121 lines
4.0 KiB
Python
121 lines
4.0 KiB
Python
import pygame
|
|
from config import *
|
|
from agent import *
|
|
from map_add_ons import *
|
|
from mobs import *
|
|
#from unknown_mob import * #unknown mob
|
|
import random
|
|
from bfs import *
|
|
|
|
class Game:
|
|
|
|
def __init__(self):
|
|
pygame.init()
|
|
self.state =[-1,-1,-1,-1,-1,-1,-1,-1]
|
|
self.SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
|
|
self.running = True
|
|
self.clock = pygame.time.Clock()
|
|
|
|
self.BACKGROUND_IMG= pygame.image.load("./zdjecia/podloze.jpg")
|
|
self.BACKGROUND = pygame.transform.scale(self.BACKGROUND_IMG,(64,64))
|
|
|
|
self.LVL_ICON_PNG = pygame.image.load("./zdjecia/lvl_icon.png")
|
|
self.LVL_ICON = pygame.transform.scale(self.LVL_ICON_PNG,(24,24))
|
|
|
|
pygame.display.set_caption('Gra-SI')
|
|
|
|
self.bfs = Bfs(self)
|
|
|
|
def new(self): # tworzy się nowa sesja grania
|
|
self.all_sprites = pygame.sprite.LayeredUpdates()
|
|
|
|
self.rock_sprites = pygame.sprite.LayeredUpdates()
|
|
self.grass_sprites = pygame.sprite.LayeredUpdates()
|
|
self.archer_orks = pygame.sprite.LayeredUpdates()
|
|
self.infantry_orks = pygame.sprite.LayeredUpdates()
|
|
self.infantry_orks2 = pygame.sprite.LayeredUpdates()
|
|
self.sauronL = pygame.sprite.LayeredUpdates()
|
|
self.flowers = pygame.sprite.LayeredUpdates()
|
|
self.little_rock_sprites = pygame.sprite.LayeredUpdates()
|
|
|
|
#self.unknown_mobs = pygame.sprite.LayeredUpdates() #unknown mob
|
|
self.agent = Agent(self,1,1)
|
|
self.archer_ork = Archer_ork(self,10,10)
|
|
self.bfs.enemy_cells.append(self.bfs.get_cell_number(self.archer_ork.x,self.archer_ork.y))
|
|
self.infantry_ork = Infantry_ork(self,10,4)
|
|
self.bfs.enemy_cells.append(self.bfs.get_cell_number(self.infantry_ork.x,self.infantry_ork.y))
|
|
self.infantry_ork2 = Infantry_ork2(self,6,3)
|
|
self.bfs.enemy_cells.append(self.bfs.get_cell_number(self.infantry_ork2.x,self.infantry_ork2.y))
|
|
self.sauron = Sauron(self, 1, 10)
|
|
self.bfs.enemy_cells.append(self.bfs.get_cell_number(self.sauron.x,self.sauron.y))
|
|
self.flower = Health_flower(self, 8,2)
|
|
#self.unknown_mob = Unknown_mob(self,8,8) #unknown mob
|
|
for y in range(5):
|
|
self.rock = Rocks(self,3,y)
|
|
self.bfs.wall_cells.append(self.bfs.get_cell_number(self.rock.x,self.rock.y))
|
|
for i in range(10):
|
|
x = random.randint(0,12)
|
|
y = random.randint(0,11)
|
|
self.grass = Grass(self,x,y)
|
|
self.grass_cells.append(self.bfs.get_cell_number(self.grass.x,self.grass.y))
|
|
for y in range(5,8):
|
|
self.little_rocks = Little_Rocks(self,4,y)
|
|
|
|
|
|
|
|
def update(self):
|
|
self.all_sprites.update()
|
|
|
|
|
|
def events(self):
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
self.running = False
|
|
pygame.quit()
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
mouse_presses = pygame.mouse.get_pressed()
|
|
if mouse_presses[0]:
|
|
self.bfs.bfs()
|
|
|
|
def map(self): # tworzenie mapy
|
|
self.clock.tick(FRAMERATE)
|
|
for x in range(0, WIDTH, TILE_SIZE):
|
|
for y in range(0, 768, TILE_SIZE):
|
|
self.SCREEN.blit(self.BACKGROUND,(x,y))
|
|
self.rect = pygame.Rect(x, y, TILE_SIZE, TILE_SIZE)
|
|
pygame.draw.rect(self.SCREEN, BLACK, self.rect, 1)
|
|
self.flowers.draw(self.SCREEN)
|
|
self.all_sprites.draw(self.SCREEN)
|
|
self.rock_sprites.draw(self.SCREEN)
|
|
self.grass_sprites.draw(self.SCREEN)
|
|
self.SCREEN.blit(self.LVL_ICON, (340 ,780))
|
|
pygame.display.update()
|
|
|
|
def main(self):
|
|
self.events()
|
|
self.update()
|
|
self.map()
|
|
|
|
grass_cells = []
|
|
|
|
|
|
'''def astar(self):
|
|
|
|
|
|
def function(self):
|
|
|
|
|
|
def cost(self):
|
|
cost = 0
|
|
while()
|
|
'''
|
|
|
|
|
|
|
|
# BFS ALGORITHM
|
|
|
|
g = Game()
|
|
g.new()
|
|
while g.running:
|
|
g.main()
|