Draw grid with a cursor
This commit is contained in:
commit
6d128b840f
79
pydoku.py
Normal file
79
pydoku.py
Normal file
@ -0,0 +1,79 @@
|
||||
import pygame as pg
|
||||
from pygame import Rect, Vector2 as v2
|
||||
|
||||
pg.init()
|
||||
|
||||
screen = pg.display.set_mode((900, 900))
|
||||
pg.display.set_caption("Pydoku")
|
||||
clock = pg.time.Clock()
|
||||
running = True
|
||||
|
||||
CELL_SIZE = 60
|
||||
CURSOR_SIZE = CELL_SIZE + 6
|
||||
GRID_X = screen.get_width() / 2 - 9 * CELL_SIZE // 2
|
||||
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)
|
||||
|
||||
def draw_grid():
|
||||
for row in range(9):
|
||||
for col in range(9):
|
||||
rect = Rect(CELL_SIZE * col + padding * col + GRID_X,
|
||||
CELL_SIZE * row + padding * row + GRID_Y,
|
||||
CELL_SIZE, CELL_SIZE)
|
||||
rect = Rect(CELL_SIZE * col + padding * col + GRID_X,
|
||||
CELL_SIZE * row + padding * row + GRID_Y,
|
||||
CELL_SIZE, CELL_SIZE)
|
||||
|
||||
|
||||
pg.draw.rect(screen, "white", rect)
|
||||
pg.draw.rect(screen, "gray", rect, width=1)
|
||||
for l in range(4):
|
||||
pg.draw.line(screen, "black",
|
||||
start_pos=(GRID_X, GRID_Y + CELL_SIZE * 3 * l),
|
||||
end_pos =(GRID_X + CELL_SIZE * 9, GRID_Y + CELL_SIZE * 3 * l),
|
||||
width=2)
|
||||
for l in range(4):
|
||||
pg.draw.line(screen, "black",
|
||||
start_pos=(GRID_X + CELL_SIZE * 3 * l, GRID_Y),
|
||||
end_pos =(GRID_X + CELL_SIZE * 3 * l, GRID_Y + CELL_SIZE * 9),
|
||||
width=2)
|
||||
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,
|
||||
CURSOR_SIZE, CURSOR_SIZE)
|
||||
screen.blit(cursorSurface, rect)
|
||||
|
||||
while running:
|
||||
for event in pg.event.get():
|
||||
if event.type == pg.QUIT:
|
||||
running = False
|
||||
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
|
||||
|
||||
# playerPos += dir * (speed * dt)
|
||||
|
||||
screen.fill('cornflower blue')
|
||||
|
||||
draw_grid()
|
||||
draw_cursor()
|
||||
|
||||
|
||||
pg.display.flip()
|
||||
|
||||
dt = clock.tick(60) / 1000
|
||||
|
||||
pg.quit()
|
Loading…
x
Reference in New Issue
Block a user