diff --git a/field.py b/field.py index b72710f..226abec 100644 --- a/field.py +++ b/field.py @@ -1,38 +1,51 @@ import pygame pygame.init() - +BLACK = (0, 0, 0) +WHITE = (200, 200, 200) BLUE = (46, 34, 240) -WHITE = (255, 255, 255) -W = 600 -H = 400 -sc = pygame.display.set_mode((W, H)) -pygame.display.set_caption("Pole i ciągnik") -pygame.display.set_icon(pygame.image.load("icon.png")) +WINDOW_HEIGHT = 600 +WINDOW_WIDTH = 600 +BLOCK_SIZE = 40 -clock = pygame.time.Clock() -FPS = 60 -x = W // 2 -y = H // 2 -speed = 20 -flRunning = True -while flRunning: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - flRunning = False - elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT: - x -= speed - elif event.key == pygame.K_RIGHT: - x += speed - elif event.key == pygame.K_DOWN: - y += speed - elif event.key == pygame.K_UP: - y -= speed - sc.fill(WHITE) - pygame.draw.rect(sc, BLUE, (x, y, 20, 20)) - pygame.display.update() +def drawGrid(): + #Set the size of the grid block + for x in range(0, WINDOW_WIDTH, BLOCK_SIZE): + for y in range(0, WINDOW_HEIGHT, BLOCK_SIZE): + rect = pygame.Rect(x, y, BLOCK_SIZE, BLOCK_SIZE) + pygame.draw.rect(sc, WHITE, rect, 1) +def draw_interface(): + global sc + sc = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) + pygame.display.set_caption("Pole i ciągnik") + pygame.display.set_icon(pygame.image.load("icon.png")) - clock.tick(FPS) \ No newline at end of file + clock = pygame.time.Clock() + sc.fill(BLACK) + FPS = 60 + + x = BLOCK_SIZE / 4 + y = BLOCK_SIZE / 4 + + flRunning = True + while flRunning: + sc.fill(BLACK) + drawGrid() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + flRunning = False + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + x -= BLOCK_SIZE + elif event.key == pygame.K_RIGHT: + x += BLOCK_SIZE + elif event.key == pygame.K_DOWN: + y += BLOCK_SIZE + elif event.key == pygame.K_UP: + y -= BLOCK_SIZE + pygame.draw.rect(sc, BLUE, (x, y, BLOCK_SIZE / 2, BLOCK_SIZE / 2)) + pygame.display.update() + + clock.tick(FPS) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..a1bffd0 --- /dev/null +++ b/main.py @@ -0,0 +1,2 @@ +from field import * +draw_interface() \ No newline at end of file