Projekt_Sztuczna_Inteligencja/main.py

80 lines
2.4 KiB
Python

# libraries
import pygame
from pyglet.gl import * # for blocky textures
# other files of this project
import project_constants as const
import minefield as mf
def main():
pygame.init()
pygame.display.set_caption(const.V_NAME_OF_WINDOW)
# FPS clock
clock = pygame.time.Clock()
# for blocky textures
glEnable(GL_TEXTURE_2D)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
# create an instance of Minefield, pass necessary data
minefield = mf.Minefield(const.MAP_RANDOM_10x10)
running = True
while running:
# FPS control
clock.tick(const.V_FPS)
# ================ #
# === GRAPHICS === #
# ================ #
# background grid (fills frame with white, blits grid)
const.SCREEN.fill((255, 255, 255))
const.SCREEN.blit(
const.ASSET_BACKGROUND,
(
const.V_SCREEN_PADDING,
const.V_SCREEN_PADDING
)
)
# draw tiles and mines
minefield.draw(const.SCREEN)
pygame.display.update()
# ============== #
# === EVENTS === #
# ============== #
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Assigning all input from keyboard as variables into an array
keys = pygame.key.get_pressed()
# Depending on what key we press, the agent will move in that direction
# DISCRETION : The only keys that are available are arrow keys
# DISCRETION : is_valid_move is a new brand funcation that now plays a critical role in movement of our Agent (It is NOT just the "check up" function anymore)
if keys[pygame.K_RIGHT]:
target_x, target_y = minefield.agent.go_right()
minefield.is_valid_move(target_x, target_y)
elif keys[pygame.K_LEFT]:
target_x, target_y = minefield.agent.go_left()
minefield.is_valid_move(target_x, target_y)
elif keys[pygame.K_UP]:
target_x, target_y = minefield.agent.go_up()
minefield.is_valid_move(target_x, target_y)
elif keys[pygame.K_DOWN]:
target_x, target_y = minefield.agent.go_down()
minefield.is_valid_move(target_x, target_y)
if __name__ == "__main__":
main()