2024-03-10 02:46:14 +01:00
|
|
|
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()
|
2024-03-24 19:28:14 +01:00
|
|
|
if keys[pygame.K_UP] and tractor.row > 0 and not board.is_rock(tractor.row-1, tractor.col):
|
2024-03-10 02:46:14 +01:00
|
|
|
tractor.row -= 1
|
|
|
|
tractor.direction = "up"
|
2024-03-24 19:28:14 +01:00
|
|
|
if keys[pygame.K_DOWN] and tractor.row < rows-1 and not board.is_rock(tractor.row+1,tractor.col):
|
2024-03-10 02:46:14 +01:00
|
|
|
tractor.row += 1
|
|
|
|
tractor.direction = "down"
|
2024-03-24 19:28:14 +01:00
|
|
|
if keys[pygame.K_LEFT] and tractor.col > 0 and not board.is_rock(tractor.row,tractor.col-1):
|
2024-03-10 02:46:14 +01:00
|
|
|
tractor.col -= 1
|
|
|
|
tractor.direction = "left"
|
2024-03-24 19:28:14 +01:00
|
|
|
if keys[pygame.K_RIGHT] and tractor.col < cols -1 and not board.is_rock(tractor.row,tractor.col+1):
|
2024-03-10 02:46:14 +01:00
|
|
|
tractor.col += 1
|
|
|
|
tractor.direction = "right"
|
|
|
|
|
|
|
|
board.draw_cubes(WIN)
|
|
|
|
tractor.draw(WIN)
|
|
|
|
pygame.display.update()
|
|
|
|
pygame.quit()
|
|
|
|
|
|
|
|
main()
|