proba/main.py

46 lines
1.1 KiB
Python

import pygame
from board import Board
from constant import width, height, rows, cols
from tractor import Tractor
fps = 5
WIN = pygame.display.set_mode((width, height))
pygame.display.set_caption('Inteligenty Traktor')
def main():
run = True
clock = pygame.time.Clock()
board = Board()
board.load_images()
tractor = Tractor(4, 4)
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_UP] and tractor.row > 0:
tractor.row -= 1
tractor.direction = "up"
if keys[pygame.K_DOWN] and tractor.row < rows-1:
tractor.row += 1
tractor.direction = "down"
if keys[pygame.K_LEFT] and tractor.col > 0:
tractor.col -= 1
tractor.direction = "left"
if keys[pygame.K_RIGHT] and tractor.col < cols -1:
tractor.col += 1
tractor.direction = "right"
board.draw_cubes(WIN)
tractor.draw(WIN)
pygame.display.update()
pygame.quit()
main()