-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep4.py
53 lines (49 loc) · 1.15 KB
/
step4.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
import pew
pew.init()
world = pew.Pix.from_iter([
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 2, 1, 2, 1, 1, 1],
[1, 1, 2, 1, 3, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 2, 1],
[1, 1, 1, 1, 1, 2, 3, 2],
[1, 3, 1, 1, 1, 1, 2, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
])
x = 0
y = 0
blink = True
delay = 1/6
end = False
while not end:
world.pixel(x, y, 4)
buttons = pew.keys()
while pew.keys():
pew.tick(delay)
dx = 0
dy = 0
if buttons & pew.K_UP:
dy = -1
elif buttons & pew.K_DOWN:
dy = 1
elif buttons & pew.K_LEFT:
dx = -1
elif buttons & pew.K_RIGHT:
dx = 1
if (0 <= x + dx <= 7 and 0 <= y + dy <= 7 and
world.pixel(x + dx, y + dy) != 2):
world.pixel(x, y, 0)
x += dx
y += dy
world.pixel(x, y, 4)
elif (dy == 0 and 1 <= x + dx <= 6 and
world.pixel(x + 2 * dx, y + 2 * dy) == 0):
world.pixel(x, y, 0)
x += dx
y += dy
world.pixel(x, y, 4)
world.pixel(x + dx, y + dy, 2)
world.pixel(x, y, 3 if blink else 0)
pew.show(world)
pew.tick(delay)
blink = not blink