Keyboard movement
This commit is contained in:
parent
6d128b840f
commit
2dc9f89431
26
pydoku.py
26
pydoku.py
@ -5,6 +5,7 @@ pg.init()
|
||||
|
||||
screen = pg.display.set_mode((900, 900))
|
||||
pg.display.set_caption("Pydoku")
|
||||
pg.key.set_repeat(200, 35)
|
||||
clock = pg.time.Clock()
|
||||
running = True
|
||||
|
||||
@ -16,7 +17,7 @@ GRID_Y = screen.get_height() / 2 - 9 * CELL_SIZE // 2
|
||||
cursorSurface = pg.Surface((CURSOR_SIZE, CURSOR_SIZE), pg.SRCALPHA)
|
||||
# Not used for now
|
||||
padding = 0
|
||||
cursor = v2(5, 5)
|
||||
cursor_pos = v2(5, 5)
|
||||
|
||||
def draw_grid():
|
||||
for row in range(9):
|
||||
@ -44,8 +45,8 @@ def draw_grid():
|
||||
def draw_cursor():
|
||||
pad_diff = (CURSOR_SIZE - CELL_SIZE) // 2
|
||||
pg.draw.rect(cursorSurface, (100, 0, 155, 100), [0, 0, CURSOR_SIZE, CURSOR_SIZE])
|
||||
rect = Rect(CELL_SIZE * (cursor.x - 1) + GRID_X - pad_diff,
|
||||
CELL_SIZE * (cursor.y - 1) + GRID_Y - pad_diff,
|
||||
rect = Rect(CELL_SIZE * (cursor_pos.x - 1) + GRID_X - pad_diff,
|
||||
CELL_SIZE * (cursor_pos.y - 1) + GRID_Y - pad_diff,
|
||||
CURSOR_SIZE, CURSOR_SIZE)
|
||||
screen.blit(cursorSurface, rect)
|
||||
|
||||
@ -53,16 +54,17 @@ while running:
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
running = False
|
||||
keys = pg.key.get_pressed()
|
||||
if event.type == pg.KEYDOWN:
|
||||
keys = pg.key.get_pressed()
|
||||
|
||||
if keys[pg.K_w]:
|
||||
cursor = -1
|
||||
if keys[pg.K_s]:
|
||||
dir.y = 1
|
||||
if keys[pg.K_a]:
|
||||
dir.x = -1
|
||||
if keys[pg.K_d]:
|
||||
dir.x = 1
|
||||
if keys[pg.K_w] and cursor_pos.y > 1:
|
||||
cursor_pos.y -= 1
|
||||
if keys[pg.K_s] and cursor_pos.y < 9:
|
||||
cursor_pos.y += 1
|
||||
if keys[pg.K_a] and cursor_pos.x > 1:
|
||||
cursor_pos.x -= 1
|
||||
if keys[pg.K_d] and cursor_pos.x < 9:
|
||||
cursor_pos.x += 1
|
||||
|
||||
# playerPos += dir * (speed * dt)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user