-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfire_animation.py
60 lines (47 loc) · 1.46 KB
/
fire_animation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import asyncio
import curses
from obstacles import has_collision
async def fire(
canvas,
start_row,
start_column,
obstacles,
obstacles_in_last_collisions,
rows_speed=-0.3,
columns_speed=0,
):
"""Display animation of gun shot, direction and speed can be specified."""
row, column = start_row, start_column
canvas.addstr(round(row), round(column), "*")
await asyncio.sleep(0)
canvas.addstr(round(row), round(column), "O")
await asyncio.sleep(0)
canvas.addstr(round(row), round(column), " ")
row += rows_speed
column += columns_speed
symbol = "-" if columns_speed else "|"
rows, columns = canvas.getmaxyx()
max_row, max_column = rows - 1, columns - 1
curses.beep()
while 0 < row < max_row and 0 < column < max_column:
row = round(row)
column = round(column)
canvas.addstr(round(row), round(column), symbol)
await asyncio.sleep(0)
canvas.addstr(round(row), round(column), " ")
for obstacle in obstacles:
if has_collision(
(
obstacle.row,
obstacle.column,
),
(
obstacle.rows_size,
obstacle.columns_size,
),
(row, column),
):
obstacles_in_last_collisions.append(obstacle)
return
row += rows_speed
column += columns_speed