Skip to content

Commit dcc85e6

Browse files
committed
Finish
1 parent 2532752 commit dcc85e6

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

examples/gauntlet_game/main.py

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,70 @@
11
import board
2+
import busio
23
import dotstar_featherwing
4+
import Adafruit_seesaw
35
import time
46
import random
57

8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
ss = Adafruit_seesaw.Seesaw(i2c)
610
wing = dotstar_featherwing.DotstarFeatherwing(board.D13, board.D11)
711

8-
wing.clear()
9-
wing.show()
10-
1112
black = (0, 0, 0)
1213
background = (32, 8, 0)
13-
edge = (32, 32, 0)
1414
blue = (0, 0, 64)
15+
player = (0, 255, 0)
16+
17+
row = (background, background, background, background, background, background, background, background, black, black, black, black, black, background, background, background, background, background, background, background, background)
18+
19+
20+
def run():
21+
player_position_col = 6
22+
score = 0
23+
steps = 0
24+
25+
for _ in range(wing.rows):
26+
wing.shift_into_top(row, 4)
27+
wing.show()
28+
29+
offset = 4
1530

16-
row = (background, background, background, background, background, background, background, edge, black, black, black, black, black, edge, background, background, background, background, background, background, background)
31+
while True:
32+
wing.set_color(3, player_position_col, black)
33+
offset = min(max(0, offset + random.randint(-1, 1)), 9)
34+
wing.shift_into_top(row, offset)
35+
if random.randint(1, 20) == 1:
36+
pos = random.randint(8, 12) - offset
37+
wing.set_color(0, pos, blue)
1738

39+
joy_x = ss.analog_read(3)
40+
if joy_x < 256 and player_position_col > 0:
41+
player_delta = -1
42+
elif joy_x > 768 and player_position_col < 11:
43+
player_delta = 1
44+
else:
45+
player_delta = 0
46+
player_position_col += player_delta
47+
48+
under_player = wing.get_color(3, player_position_col)
49+
if under_player == background:
50+
return (steps, score)
51+
elif under_player == blue:
52+
score += 1
1853

19-
for i in range(wing.rows):
20-
wing.shift_into_top(row, 4)
21-
wing.show()
54+
wing.set_color(3, player_position_col, player)
55+
wing.show()
56+
steps += 1
57+
if steps % 10 == 0:
58+
score += 1
59+
time.sleep(0.1)
2260

23-
offset = 4
2461
while True:
25-
offset = min(max(0, offset + random.randint(-1, 1)), 9)
26-
wing.shift_into_top(row, offset)
27-
if random.randint(1, 10) == 1:
28-
pos = random.randint(8, 12) - offset
29-
wing.set_color(0, pos, blue)
30-
wing.show()
31-
time.sleep(0.1)
62+
result = run()
63+
print('Score: {} Steps: {}'.format(result[1], result[0]))
64+
# got here becasue of a crash
65+
wing.clear()
66+
wing.show()
67+
wing.fill((255, 0, 0))
68+
wing.show()
69+
wing.clear()
70+
wing.show()

0 commit comments

Comments
 (0)