47
47
color_depth = 16 ,
48
48
)
49
49
display = framebufferio .FramebufferDisplay (fb )
50
+ supervisor .runtime .display = display
50
51
51
52
game_logic = GameLogic (display ) # pylint: disable=no-value-for-parameter
52
53
74
75
ui_group = Group ()
75
76
main_group .append (ui_group )
76
77
77
- # Create the mouse graphics and add to the main group
78
- mouse_bmp = OnDiskBitmap ("bitmaps/mouse_cursor.bmp" )
79
- mouse_bmp .pixel_shader .make_transparent (0 )
80
- mouse_tg = TileGrid (mouse_bmp , pixel_shader = mouse_bmp .pixel_shader )
81
- mouse_tg .x = display .width // 2
82
- mouse_tg .y = display .height // 2
83
- main_group .append (mouse_tg )
84
-
85
78
MENU_ITEM_HEIGHT = INFO_BAR_HEIGHT
86
79
87
80
def create_game_board ():
@@ -114,11 +107,23 @@ def update_ui():
114
107
mines_left_label .text = f"Mines: { game_logic .mines_left } "
115
108
elapsed_time_label .text = f"Time: { game_logic .elapsed_time } "
116
109
110
+
111
+ # Mouse resolution/sensitivity
112
+ sensitivity = 4
113
+
117
114
# variable for the mouse USB device instance
118
- mouse = find_and_init_boot_mouse ()
115
+ mouse = find_and_init_boot_mouse (cursor_image = "bitmaps/mouse_cursor.bmp" )
119
116
if mouse is None :
120
117
raise RuntimeError ("No mouse found. Please connect a USB mouse." )
121
118
119
+ mouse .sensitivity = sensitivity
120
+ mouse_tg = mouse .tilegrid
121
+ mouse_tg .x = display .width // 2
122
+ mouse_tg .y = display .height // 2
123
+
124
+ # add mouse graphic to main_group
125
+ main_group .append (mouse_tg )
126
+
122
127
buf = array .array ("b" , [0 ] * 4 )
123
128
waiting_for_release = False
124
129
left_button = right_button = False
@@ -235,26 +240,17 @@ def hide_group(group):
235
240
left_button_pressed = False
236
241
right_button_pressed = False
237
242
238
- # Mouse resolution/sensitivity
239
- sensitivity = 4
240
- mouse .x = mouse_coords [0 ] * sensitivity
241
- mouse .y = mouse_coords [1 ] * sensitivity
242
-
243
- # Change the mouse resolution so it's not too sensitive
244
- mouse .display_size = (display .width * sensitivity , display .height * sensitivity )
245
-
246
243
# main loop
247
244
while True :
248
245
update_ui ()
249
- # attempt mouse read
246
+ # update cursor position, and check for clicks
250
247
buttons = mouse .update ()
251
248
252
249
# Extract button states
253
250
if buttons is None :
254
251
left_button = 0
255
252
right_button = 0
256
253
else :
257
- print (buttons )
258
254
left_button = 1 if 'left' in buttons else 0
259
255
right_button = 1 if 'right' in buttons else 0
260
256
@@ -273,11 +269,6 @@ def hide_group(group):
273
269
last_left_button_state = left_button
274
270
last_right_button_state = right_button
275
271
276
- # Update position
277
- # Ensure position stays within bounds
278
- mouse_tg .x = max (0 , min (display .width - 1 , mouse .x // sensitivity ))
279
- mouse_tg .y = max (0 , min (display .height - 1 , mouse .y // sensitivity ))
280
-
281
272
mouse_coords = (mouse_tg .x , mouse_tg .y )
282
273
283
274
if waiting_for_release and not left_button and not right_button :
0 commit comments