Projekt_Sztuczna_Inteligencja/main.py

68 lines
1.8 KiB
Python
Raw Normal View History

# libraries
2021-03-10 14:01:17 +01:00
import pygame
from pyglet.gl import * # for blocky textures
2021-03-10 14:01:17 +01:00
# other files of this project
2021-03-14 19:18:23 +01:00
import project_constants as const
2021-03-12 11:49:19 +01:00
import minefield as mf
2021-03-10 14:01:17 +01:00
2021-03-12 09:55:59 +01:00
def main():
2021-03-10 14:01:17 +01:00
pygame.init()
2021-03-14 19:18:23 +01:00
pygame.display.set_caption(const.V_NAME_OF_WINDOW)
2021-03-11 18:51:43 +01:00
# for blocky textures
glEnable(GL_TEXTURE_2D)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
2021-03-12 11:49:19 +01:00
# create an instance of Minefield, pass necessary data
2021-03-14 19:18:23 +01:00
minefield = mf.Minefield(const.MAP_RANDOM_10x10)
2021-03-10 14:01:17 +01:00
running = True
while running:
# ================ #
# === GRAPHICS === #
# ================ #
# background grid (fills frame with white, blits grid)
2021-03-14 19:18:23 +01:00
const.SCREEN.fill((255, 255, 255))
const.SCREEN.blit(
const.ASSET_BACKGROUND,
(
2021-03-14 19:18:23 +01:00
const.V_SCREEN_PADDING,
const.V_SCREEN_PADDING
)
)
# draw tiles and mines
2021-03-14 19:18:23 +01:00
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
if keys[pygame.K_RIGHT]:
minefield.go_right()
elif keys[pygame.K_LEFT]:
minefield.go_left()
elif keys[pygame.K_UP]:
minefield.go_up()
elif keys[pygame.K_DOWN]:
minefield.go_down()
2021-03-12 11:49:19 +01:00
2021-03-12 09:55:59 +01:00
if __name__ == "__main__":
main()