-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboulder.py
75 lines (69 loc) · 1.76 KB
/
boulder.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pew
VOID = 0
WALL = 1
SOIL = 2
ROCK = 3
HERO = 4
GEM1 = 5
GEM2 = 6
pew.init()
screen = pew.Pix.from_iter((
(1, 1, 1, 4, 1, 1, 1, 1),
(1, 2, 2, 2, 3, 0, 2, 1),
(1, 1, 3, 1, 2, 5, 2, 1),
(1, 2, 2, 1, 2, 1, 1, 1),
(1, 2, 0, 3, 2, 3, 2, 1),
(1, 2, 0, 5, 2, 2, 2, 1),
(1, 2, 2, 2, 2, 2, 2, 1),
(1, 1, 1, 1, 1, 1, 1, 1),
))
blink = 1
dead = False
for y in range(8):
for x in range(8):
if screen.pixel(x, y) == 4:
break;
else:
continue
break
while not dead:
screen.pixel(x, y, VOID)
pressed = pew.keys()
dx = 0
dy = 0
if pressed & pew.K_UP:
dy = -1
elif pressed & pew.K_DOWN:
dy = 1
elif pressed & pew.K_LEFT:
dx = -1
elif pressed & pew.K_RIGHT:
dx = 1
if screen.pixel(x + dx, y + dy) not in {WALL, ROCK}:
x += dx
y += dy
elif screen.pixel(x + dx, y + dy) == ROCK and dy == 0:
if screen.pixel(x + dx + dx, y + dy + dy) == VOID:
screen.pixel(x + dx + dx, y + dy + dy, ROCK)
screen.pixel(x + dx, y + dy, VOID)
x += dx
y += dy
count = 0
for a in range(8):
for b in range(7, -1, -1):
if (screen.pixel(a, b) == ROCK and
screen.pixel(a, b + 1) == VOID and
(a, b + 1) != (x, y)):
screen.pixel(a, b, VOID)
screen.pixel(a, b + 1, ROCK)
if (a, b + 2) == (x, y):
dead = True
if screen.pixel(a, b) in {GEM1, GEM2}:
screen.pixel(a, b, GEM1 if blink else GEM2)
count += 1
if count == 0:
break
screen.pixel(x, y, 3 if blink else HERO)
blink = not blink
pew.show(screen)
pew.tick(1 / 6)