Use mouse clicks to place cursor

This commit is contained in:
Joseph Ferano 2023-10-29 12:17:14 +07:00
parent 6b4be6913a
commit db516cd52a

View File

@ -90,6 +90,18 @@ while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1:
grid_max_x = GRID_X + CELL_SIZE * 9
grid_max_y = GRID_Y + CELL_SIZE * 9
mx = event.pos[0]
my = event.pos[1]
if (mx >= GRID_X
and mx <= grid_max_x
and my >= GRID_Y
and my <= grid_max_y):
cursor.row = (my - GRID_Y) // CELL_SIZE + 1
cursor.col = (mx - GRID_X) // CELL_SIZE + 1
if event.type == pg.KEYDOWN:
# keys = pg.key.get_pressed()
if event.key == pg.K_h and cursor.col > 1:
@ -111,8 +123,6 @@ while running:
print(board)
# playerPos += dir * (speed * dt)
screen.fill('cornflower blue')
draw_grid()