|
1 | 1 | import board |
| 2 | +import busio |
2 | 3 | import dotstar_featherwing |
| 4 | +import Adafruit_seesaw |
3 | 5 | import time |
4 | 6 | import random |
5 | 7 |
|
| 8 | +i2c = busio.I2C(board.SCL, board.SDA) |
| 9 | +ss = Adafruit_seesaw.Seesaw(i2c) |
6 | 10 | wing = dotstar_featherwing.DotstarFeatherwing(board.D13, board.D11) |
7 | 11 |
|
8 | | -wing.clear() |
9 | | -wing.show() |
10 | | - |
11 | 12 | black = (0, 0, 0) |
12 | 13 | background = (32, 8, 0) |
13 | | -edge = (32, 32, 0) |
14 | 14 | 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 |
15 | 30 |
|
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) |
17 | 38 |
|
| 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 |
18 | 53 |
|
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) |
22 | 60 |
|
23 | | -offset = 4 |
24 | 61 | 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