@@ -50,47 +50,45 @@ def make_display():
50
50
pass
51
51
spi .configure (baudrate = 24000000 ) # Configure SPI for 24MHz
52
52
spi .unlock ()
53
- tft_cs = board .D10
54
- tft_dc = board .D7
55
53
56
54
displayio .release_displays ()
57
- display_bus = displayio .FourWire (spi , command = tft_dc , chip_select = tft_cs , reset = board .D9 )
55
+ display_bus = displayio .FourWire (spi , command = board . D7 , chip_select = board . D10 , reset = board .D9 )
58
56
59
- return ST7789 (display_bus , width = 240 , height = 240 , rowstart = 80 )
57
+ return ST7789 (display_bus , width = 240 , height = 240 , rowstart = 80 , auto_refresh = True )
60
58
61
59
def make_tilegrid ():
62
60
"""Construct and return the tilegrid."""
63
61
group = displayio .Group (max_size = 10 )
64
62
65
- sprite_sheet , palette = adafruit_imageload .load ("/tilesheet.bmp" ,
63
+ sprite_sheet , palette = adafruit_imageload .load ("/tilesheet-2x .bmp" ,
66
64
bitmap = displayio .Bitmap ,
67
65
palette = displayio .Palette )
68
66
grid = displayio .TileGrid (sprite_sheet , pixel_shader = palette ,
69
- width = 16 , height = 10 ,
70
- tile_height = 24 , tile_width = 16 ,
67
+ width = 9 , height = 5 ,
68
+ tile_height = 48 , tile_width = 32 ,
71
69
default_tile = EMPTY )
72
70
group .append (grid )
73
71
display .show (group )
74
72
return grid
75
73
76
74
def evaluate_position (row , col ):
77
75
"""Return how long of a cloud is placable at the given location.
78
- :param row: the tile row (0-9 )
79
- :param col: the tile column (0-14 )
76
+ :param row: the tile row (0-4 )
77
+ :param col: the tile column (0-8 )
80
78
"""
81
79
if tilegrid [col , row ] != EMPTY or tilegrid [col + 1 , row ] != EMPTY :
82
80
return 0
83
81
end_col = col + 1
84
- while end_col < 16 and tilegrid [end_col , row ] == EMPTY :
82
+ while end_col < 9 and tilegrid [end_col , row ] == EMPTY :
85
83
end_col += 1
86
84
return min ([4 , end_col - col ])
87
85
88
86
def seed_clouds (number_of_clouds ):
89
87
"""Create the initial clouds so it doesn't start empty"""
90
88
for _ in range (number_of_clouds ):
91
89
while True :
92
- row = randint (0 , 9 )
93
- col = randint (0 ,14 )
90
+ row = randint (0 , 4 )
91
+ col = randint (0 , 7 )
94
92
cloud_length = evaluate_position (row , col )
95
93
if cloud_length > 0 :
96
94
break
@@ -103,36 +101,42 @@ def seed_clouds(number_of_clouds):
103
101
104
102
def slide_tiles ():
105
103
"""Move the tilegrid to the left, one pixel at a time, a full time width"""
106
- for _ in range (16 ):
104
+ for _ in range (32 ):
107
105
tilegrid .x -= 1
106
+ display .refresh (target_frames_per_second = 60 )
107
+
108
108
109
109
def shift_tiles ():
110
110
"""Move tiles one spot to the left, and reset the tilegrid's position"""
111
- for row in range (10 ):
112
- for col in range (15 ):
111
+ for row in range (5 ):
112
+ for col in range (8 ):
113
113
tilegrid [col , row ] = tilegrid [col + 1 , row ]
114
- tilegrid [15 , row ] = EMPTY
114
+ tilegrid [8 , row ] = EMPTY
115
115
tilegrid .x = 0
116
116
117
117
def extend_clouds ():
118
118
"""Extend any clouds on the right edge, either finishing them with a right
119
119
end or continuing them with a middle piece
120
120
"""
121
- for row in range (10 ):
122
- if tilegrid [14 , row ] == LEFT or tilegrid [14 , row ] == MIDDLE :
121
+ for row in range (5 ):
122
+ if tilegrid [7 , row ] == LEFT or tilegrid [7 , row ] == MIDDLE :
123
123
if randint (1 , 10 ) > CHANCE_OF_EXTENDING_A_CLOUD :
124
- tilegrid [15 , row ] = MIDDLE
124
+ tilegrid [8 , row ] = MIDDLE
125
125
else :
126
- tilegrid [15 , row ] = RIGHT
126
+ tilegrid [8 , row ] = RIGHT
127
127
128
128
def add_cloud ():
129
129
"""Maybe add a new cloud on the right at a randon open row"""
130
130
if randint (1 , 10 ) > CHANCE_OF_NEW_CLOUD :
131
+ count = 0
131
132
while True :
132
- row = randint (0 , 9 )
133
- if tilegrid [14 , row ] == EMPTY and tilegrid [15 , row ] == EMPTY :
133
+ count += 1
134
+ if count == 50 :
135
+ return
136
+ row = randint (0 , 4 )
137
+ if tilegrid [7 , row ] == EMPTY and tilegrid [8 , row ] == EMPTY :
134
138
break
135
- tilegrid [15 , row ] = LEFT
139
+ tilegrid [8 , row ] = LEFT
136
140
137
141
display = make_display ()
138
142
tilegrid = make_tilegrid ()
@@ -142,4 +146,4 @@ def add_cloud():
142
146
slide_tiles ()
143
147
shift_tiles ()
144
148
extend_clouds ()
145
- add_cloud ()
149
+ add_cloud ()
0 commit comments