Projekt_Si/app.py
2024-03-13 23:30:39 +01:00

71 lines
1.7 KiB
Python

import pygame
import prefs
import random
from pygame.locals import K_w, K_s, K_a, K_d
from classes.cell import Cell
from classes.agent import Agent
pygame.init()
window = pygame.display.set_mode((prefs.WIDTH, prefs.HEIGHT))
pygame.display.set_caption("Game Window")
def initBoard():
global cells
cells = []
for i in range(prefs.GRID_SIZE):
row = []
for j in range(prefs.GRID_SIZE):
cell = Cell(i, j)
row.append(cell)
cells.append(row)
global agent
agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells)
# Na potrzeby prezentacji tworzę sobie prostokatne sciany na które nie da się wejść
x1 = 3
y1 = 2
for i in range(x1, x1+4):
for j in range(y1, y1+2):
cells[i][j].prepareTexture("wall.png")
cells[i][j].blocking_movement = True
def draw_grid(window, cells):
for i in range(prefs.GRID_SIZE):
for j in range(prefs.GRID_SIZE):
cells[i][j].draw(window)
initBoard()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# takie głupie kontrolki do usunięcia potem, tylko do preznetacji
keys = pygame.key.get_pressed()
if keys[K_w] and not agent.moved:
agent.move_up()
if keys[K_s] and not agent.moved:
agent.move_down()
if keys[K_a] and not agent.moved:
agent.move_left()
if keys[K_d] and not agent.moved:
agent.move_right()
if not any([keys[K_w], keys[K_s], keys[K_a], keys[K_d]]):
agent.moved = False
window.fill((255, 0, 0))
draw_grid(window, cells)
agent.draw(window)
pygame.display.update()
pygame.quit()