diff --git a/__pycache__/agent.cpython-310.pyc b/__pycache__/agent.cpython-310.pyc index 562bc61..01ab84c 100644 Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ diff --git a/__pycache__/bfs.cpython-310.pyc b/__pycache__/bfs.cpython-310.pyc index db4bae0..6fbdb95 100644 Binary files a/__pycache__/bfs.cpython-310.pyc and b/__pycache__/bfs.cpython-310.pyc differ diff --git a/__pycache__/config.cpython-310.pyc b/__pycache__/config.cpython-310.pyc index 0331f11..30e5ecf 100644 Binary files a/__pycache__/config.cpython-310.pyc and b/__pycache__/config.cpython-310.pyc differ diff --git a/__pycache__/health_flower.cpython-310.pyc b/__pycache__/health_flower.cpython-310.pyc index d596565..3ce0c13 100644 Binary files a/__pycache__/health_flower.cpython-310.pyc and b/__pycache__/health_flower.cpython-310.pyc differ diff --git a/__pycache__/map_add_ons.cpython-310.pyc b/__pycache__/map_add_ons.cpython-310.pyc index 1b7c964..e0a5378 100644 Binary files a/__pycache__/map_add_ons.cpython-310.pyc and b/__pycache__/map_add_ons.cpython-310.pyc differ diff --git a/__pycache__/mobs.cpython-310.pyc b/__pycache__/mobs.cpython-310.pyc new file mode 100644 index 0000000..7eb7e28 Binary files /dev/null and b/__pycache__/mobs.cpython-310.pyc differ diff --git a/archer_ork.py b/archer_ork.py deleted file mode 100644 index 44badb0..0000000 --- a/archer_ork.py +++ /dev/null @@ -1,29 +0,0 @@ -import pygame -from config import * - -class Archer_ork(pygame.sprite.Sprite): - - - def __init__(self, game, x, y): - self.game = game - self.groups = self.game.all_sprites, self.game.archer_orks - pygame.sprite.Sprite.__init__(self, self.groups) - - self.x = x * TILE_SIZE - self.y = y * TILE_SIZE - self.width = TILE_SIZE - self.height = TILE_SIZE - - self.ARCHER_ORK_IMG = pygame.image.load("./zdjecia/ork_lucznik.png") - self.ARCHER_ORK = pygame.transform.scale(self.ARCHER_ORK_IMG,(64,64)) - - self.image = pygame.Surface([self.width, self.height]) - self.image.blit(self.ARCHER_ORK, (0,0)) - self.image.set_colorkey((0, 0, 0)) - - self.rect = self.image.get_rect() - self.rect.x = self.x - self.rect.y = self.y - - self.level = 1 - self.damage = 50*self.level \ No newline at end of file diff --git a/bfs.py b/bfs.py new file mode 100644 index 0000000..b4ae2e3 --- /dev/null +++ b/bfs.py @@ -0,0 +1,193 @@ +import pygame +from config import * +class Bfs: + + def __init__(self,game): + + self.game = game + + self.open_queue = [] + self.close_queue = [] + self.wall_cells = [] + self.enemy_cells = [] + + def bfs(self): + print("x: ", self.game.agent.x, "y: ", self.game.agent.y) + + self.open_queue.append(self.get_cell_number(self.game.agent.x,self.game.agent.y)) + # tutaj dodaje się cel agenta + goal_cell = self.get_cell_number(self.game.flower.x,self.game.flower.y) + + path = [] + processing = True + find_path = False + while processing: # główna pętla + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exit() + + if len(self.open_queue) > 0 : + current_node_cell = self.open_queue.pop(0) + + if(current_node_cell in self.close_queue): + continue + + print("Aktualna kratka: ", current_node_cell) + print("Cel znajduje się na kratce: ", goal_cell) + + if (current_node_cell == goal_cell): + self.close_queue.append(current_node_cell) + found_goal_cell = current_node_cell + print("Znaleziono cel, szukanie drogi z odwiedzonych węzłów, kolejka odwiedzonych:", self.close_queue) + processing = False + find_path = True + self.game.clock.tick(2) + else: + child_node_cells = self.get_child_nodes(current_node_cell) + self.close_queue.append(current_node_cell) + print("Sąsiedzi: ", child_node_cells) + for child_node in child_node_cells: + if child_node not in self.open_queue and child_node not in self.close_queue: + self.open_queue.append(child_node) + print("Kolejka: ", self.open_queue, "\n") + else: + print("Brak nowych węzłów, kolejka: ",self. open_queue) + print("Odwiedzone : ", self.close_queue) + return self.close_queue + + dead_end_nodes = [] + while find_path: + path.append(self.close_queue[0]) + + for i in range(len(self.close_queue) -1): + from_cell = path[-1] + to_cell = self.close_queue[i+1] + + if to_cell in dead_end_nodes: + continue + + if self.verify_move(from_cell, to_cell): + path.append(to_cell) + + if path[-1] == found_goal_cell: + find_path = False + else: + dead_end_nodes.append(path[-1]) + path = [] + + print("Droga: ", path) + self.move_agent(path) + + + def get_cell_number(self,x, y): #zamienia koordynaty na numer kratki + cell_number = None + cell_number =(x // TILE_SIZE) + (NUM_ROWS * (( y// TILE_SIZE))) + return cell_number + + def get_child_nodes(self,cell_number): + children = [] + up = self.get_up_cell(cell_number) + if up is not None and up not in self.wall_cells and up not in self.enemy_cells: + children.append(up) + + right = self.get_right_cell(cell_number) + if right is not None and right not in self.wall_cells and up not in self.enemy_cells: + children.append(right) + + down = self.get_down_cell(cell_number) + if down is not None and down not in self.wall_cells and up not in self.enemy_cells: + children.append(down) + + left = self.get_left_cell(cell_number) + if left is not None and left not in self.wall_cells and up not in self.enemy_cells: + children.append(left) + + return children + + + def get_up_cell(self,cell_number): + cell_row_number = cell_number // NUM_ROWS + if (cell_row_number - 1 < 0): + return None + else: + return (cell_number - NUM_ROWS) + + def get_right_cell(self,cell_number): + cell_column_number = cell_number % NUM_ROWS + if (cell_column_number + 1 >= NUM_ROWS): + return None + else: + return (cell_number + 1) + + def get_down_cell(self,cell_number): + cell_row_number = cell_number // NUM_ROWS + if (cell_row_number + 1 >= NUM_ROWS): + return None + else: + return (cell_number + NUM_ROWS) + + def get_left_cell(self,cell_number): + cell_column_number = cell_number % NUM_ROWS + if (cell_column_number - 1 < 0): + return None + else: + return (cell_number - 1) + + def verify_move(self,from_cell, to_cell): #sprawdzenie czy ruch jest poprawny czyt. czy następna kratka to przeszkoda lub mob + if (to_cell in self.wall_cells or to_cell in self.enemy_cells): + return False + + if(from_cell + 1 == to_cell): + return True + + if(from_cell - 1 == to_cell): + return True + + if(from_cell - NUM_ROWS == to_cell): + return True + + if(from_cell + NUM_ROWS == to_cell): + return True + + return False + + def move_agent(self,path): + for cell_to_move in path: + x, y = self.get_coordinates(cell_to_move) + print("Ruch do kratki : ", cell_to_move, " z x: ", x, ", y: ", y, ", agent.x: ", self.game.agent.rect.x, ", agent.y: ", self.game.agent.rect.y) + if(self.get_cell_number(self.game.agent.x,self.game.agent.y)!=cell_to_move): + if x > self.game.agent.rect.x: + self.game.agent.direction = 0 + elif y > self.game.agent.rect.y: + self.game.agent.direction = 1 + elif x < self.game.agent.rect.x: + self.game.agent.direction = 2 + elif y < self.game.agent.rect.y: + self.game.agent.direction = 3 + if self.game.agent.direction==0: + print("DIRECTION: "+self.game.agent.AGENT_IMAGES[self.game.agent.direction]) + self.game.agent.x_change += TILE_SIZE + elif self.game.agent.direction==1: + print("DIRECTION: "+self.game.agent.AGENT_IMAGES[self.game.agent.direction]) + self.game.agent.y_change += TILE_SIZE + elif self.game.agent.direction==2: + print("DIRECTION: "+self.game.agent.AGENT_IMAGES[self.game.agent.direction]) + self.game.agent.x_change -= TILE_SIZE + elif self.game.agent.direction==3: + print("DIRECTION: "+self.game.agent.AGENT_IMAGES[self.game.agent.direction]) + self.game.agent.y_change -= TILE_SIZE + + self.game.agent.rotate() + self.game.update() + self.game.map() + + print("Położenie agenta: agent.x: ", self.game.agent.rect.x, ", agent.y: ", self.game.agent.rect.y) + self.game.clock.tick(2) + + def get_coordinates(self,cell_to_move): #zamienia numer kratki na koordynaty + cell_row_number = cell_to_move // NUM_ROWS + cell_column_number = cell_to_move % NUM_ROWS + + y = cell_row_number * TILE_SIZE + x = cell_column_number * TILE_SIZE + return x, y diff --git a/config.py b/config.py index 1398b28..ccfd4da 100644 --- a/config.py +++ b/config.py @@ -1,10 +1,9 @@ -import pygame - FRAMERATE = 30 WIDTH, HEIGHT = 832, 832 TILE_SIZE = 64 BLACK = ((0,0,0)) WHITE = ((255,255,255)) NUM_ROWS = WIDTH//TILE_SIZE -AGENT_LAYER =2 -FLOWER_LAYER = 1 \ No newline at end of file +AGENT_LAYER = 2 +FLOWER_LAYER = 1 +GRASS_LAYER = 3 \ No newline at end of file diff --git a/health_flower.py b/health_flower.py deleted file mode 100644 index 684bce1..0000000 --- a/health_flower.py +++ /dev/null @@ -1,28 +0,0 @@ -import pygame -from config import * - -class Health_flower(pygame.sprite.Sprite): - - - def __init__(self, game, x, y): - self.game = game - self.groups = self.game.flowers - pygame.sprite.Sprite.__init__(self, self.groups) - - self.x = x * TILE_SIZE - self.y = y * TILE_SIZE - self.width = TILE_SIZE - self.height = TILE_SIZE - - self.FLOWER_IMG = pygame.image.load("./zdjecia/flower.png") - self.FLOWER = pygame.transform.scale(self.FLOWER_IMG,(64,64)) - - self.image = pygame.Surface([self.width, self.height]) - self.image.blit(self.FLOWER, (0,0)) - self.image.set_colorkey((0, 0, 0)) - - self.rect = self.image.get_rect() - self.rect.x = self.x - self.rect.y = self.y - - self._layer = FLOWER_LAYER diff --git a/infantry_ork.py b/infantry_ork.py deleted file mode 100644 index e2db1ae..0000000 --- a/infantry_ork.py +++ /dev/null @@ -1,29 +0,0 @@ -import pygame -from config import * - -class Infantry_ork(pygame.sprite.Sprite): - - - def __init__(self, game, x, y): - self.game = game - self.groups = self.game.all_sprites, self.game.infantry_orks - pygame.sprite.Sprite.__init__(self, self.groups) - - self.x = x * TILE_SIZE - self.y = y * TILE_SIZE - self.width = TILE_SIZE - self.height = TILE_SIZE - - self.INFANTRY_ORK_IMG = pygame.image.load("./zdjecia/ork-piechota.png") - self.INFANTRY_ORK = pygame.transform.scale(self.INFANTRY_ORK_IMG,(64,64)) - - self.image = pygame.Surface([self.width, self.height]) - self.image.blit(self.INFANTRY_ORK, (0,0)) - self.image.set_colorkey((0, 0, 0)) - - self.rect = self.image.get_rect() - self.rect.x = self.x - self.rect.y = self.y - - self.level = 2 - self.damage = 50*self.level \ No newline at end of file diff --git a/infantry_ork2.py b/infantry_ork2.py deleted file mode 100644 index 6c6e9fc..0000000 --- a/infantry_ork2.py +++ /dev/null @@ -1,29 +0,0 @@ -import pygame -from config import * - -class Infantry_ork2(pygame.sprite.Sprite): - - - def __init__(self, game, x, y): - self.game = game - self.groups = self.game.all_sprites, self.game.infantry_orks2 - pygame.sprite.Sprite.__init__(self, self.groups) - - self.x = x * TILE_SIZE - self.y = y * TILE_SIZE - self.width = TILE_SIZE - self.height = TILE_SIZE - - self.INFANTRY_ORK2_IMG = pygame.image.load("./zdjecia/ork-piechota2.png") - self.INFANTRY_ORK2 = pygame.transform.scale(self.INFANTRY_ORK2_IMG,(64,64)) - - self.image = pygame.Surface([self.width, self.height]) - self.image.blit(self.INFANTRY_ORK2, (0,0)) - self.image.set_colorkey((0, 0, 0)) - - self.rect = self.image.get_rect() - self.rect.x = self.x - self.rect.y = self.y - - self.level = 3 - self.damage = 50*self.level \ No newline at end of file diff --git a/main.py b/main.py index 8b6bf71..435cf05 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,10 @@ import pygame from config import * from agent import * from map_add_ons import * -from archer_ork import * -from infantry_ork import * -from infantry_ork2 import * -from sauron import * -from health_flower import * +from mobs import * #from unknown_mob import * #unknown mob +import random +from bfs import * class Game: @@ -26,29 +24,40 @@ class Game: 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.unknown_mobs = pygame.sprite.LayeredUpdates() #unknown mob self.agent = Agent(self,1,1) self.archer_ork = Archer_ork(self,10,10) - self.enemy_cells.append(self.get_cell_number(self.archer_ork.x,self.archer_ork.y)) + 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.enemy_cells.append(self.get_cell_number(self.infantry_ork.x,self.infantry_ork.y)) + 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.enemy_cells.append(self.get_cell_number(self.infantry_ork2.x,self.infantry_ork2.y)) + 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.enemy_cells.append(self.get_cell_number(self.sauron.x,self.sauron.y)) + 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.wall_cells.append(self.get_cell_number(self.rock.x,self.rock.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)) + def update(self): @@ -63,7 +72,7 @@ class Game: if event.type == pygame.MOUSEBUTTONDOWN: mouse_presses = pygame.mouse.get_pressed() if mouse_presses[0]: - self.bfs() + self.bfs.bfs() def map(self): # tworzenie mapy self.clock.tick(FRAMERATE) @@ -75,6 +84,7 @@ class Game: 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() @@ -83,194 +93,23 @@ class Game: self.update() self.map() + grass_cells = [] + + + '''def astar(self): + + + def function(self): + + + def cost(self): + cost = 0 + while() +''' + + + # BFS ALGORITHM - - open_queue = [] - close_queue = [] - wall_cells = [] - enemy_cells = [] - - def bfs(self): - print("x: ", self.agent.x, "y: ", self.agent.y) - - self.open_queue.append(self.get_cell_number(self.agent.x,self.agent.y)) - # tutaj dodaje się cel agenta - goal_cell = self.get_cell_number(self.flower.x,self.flower.y) - - path = [] - processing = True - find_path = False - while processing: # główna pętla - for event in pygame.event.get(): - if event.type == pygame.QUIT: - exit() - - if len(self.open_queue) > 0 : - current_node_cell = self.open_queue.pop(0) - - if(current_node_cell in self.close_queue): - continue - - print("Aktualna kratka: ", current_node_cell) - print("Cel znajduje się na kratce: ", goal_cell) - - if (current_node_cell == goal_cell): - self.close_queue.append(current_node_cell) - found_goal_cell = current_node_cell - print("Znaleziono cel, szukanie drogi z odwiedzonych węzłów, kolejka odwiedzonych:", self.close_queue) - processing = False - find_path = True - self.clock.tick(2) - else: - child_node_cells = self.get_child_nodes(current_node_cell) - self.close_queue.append(current_node_cell) - print("Sąsiedzi: ", child_node_cells) - for child_node in child_node_cells: - if child_node not in self.open_queue and child_node not in self.close_queue: - self.open_queue.append(child_node) - print("Kolejka: ", self.open_queue, "\n") - else: - print("Brak nowych węzłów, kolejka: ",self. open_queue) - print("Odwiedzone : ", self.close_queue) - return self.close_queue - - dead_end_nodes = [] - while find_path: - path.append(self.close_queue[0]) - - for i in range(len(self.close_queue) -1): - from_cell = path[-1] - to_cell = self.close_queue[i+1] - - if to_cell in dead_end_nodes: - continue - - if self.verify_move(from_cell, to_cell): - path.append(to_cell) - - if path[-1] == found_goal_cell: - find_path = False - else: - dead_end_nodes.append(path[-1]) - path = [] - - print("Droga: ", path) - self.move_agent(path) - - - def get_cell_number(self,x, y): #zamienia koordynaty na numer kratki - cell_number = None - cell_number =(x // TILE_SIZE) + (NUM_ROWS * (( y// TILE_SIZE))) - return cell_number - - def get_child_nodes(self,cell_number): - children = [] - up = self.get_up_cell(cell_number) - if up is not None and up not in self.wall_cells and up not in self.enemy_cells: - children.append(up) - - right = self.get_right_cell(cell_number) - if right is not None and right not in self.wall_cells and up not in self.enemy_cells: - children.append(right) - - down = self.get_down_cell(cell_number) - if down is not None and down not in self.wall_cells and up not in self.enemy_cells: - children.append(down) - - left = self.get_left_cell(cell_number) - if left is not None and left not in self.wall_cells and up not in self.enemy_cells: - children.append(left) - - return children - - - def get_up_cell(self,cell_number): - cell_row_number = cell_number // NUM_ROWS - if (cell_row_number - 1 < 0): - return None - else: - return (cell_number - NUM_ROWS) - - def get_right_cell(self,cell_number): - cell_column_number = cell_number % NUM_ROWS - if (cell_column_number + 1 >= NUM_ROWS): - return None - else: - return (cell_number + 1) - - def get_down_cell(self,cell_number): - cell_row_number = cell_number // NUM_ROWS - if (cell_row_number + 1 >= NUM_ROWS): - return None - else: - return (cell_number + NUM_ROWS) - - def get_left_cell(self,cell_number): - cell_column_number = cell_number % NUM_ROWS - if (cell_column_number - 1 < 0): - return None - else: - return (cell_number - 1) - - def verify_move(self,from_cell, to_cell): #sprawdzenie czy ruch jest poprawny czyt. czy następna kratka to przeszkoda lub mob - if (to_cell in self.wall_cells or to_cell in self.enemy_cells): - return False - - if(from_cell + 1 == to_cell): - return True - - if(from_cell - 1 == to_cell): - return True - - if(from_cell - NUM_ROWS == to_cell): - return True - - if(from_cell + NUM_ROWS == to_cell): - return True - - return False - - def move_agent(self,path): - for cell_to_move in path: - x, y = self.get_coordinates(cell_to_move) - print("Ruch do kratki : ", cell_to_move, " z x: ", x, ", y: ", y, ", agent.x: ", self.agent.rect.x, ", agent.y: ", self.agent.rect.y) - if(self.get_cell_number(self.agent.x,self.agent.y)!=cell_to_move): - if x > self.agent.rect.x: - self.agent.direction = 0 - elif y > self.agent.rect.y: - self.agent.direction = 1 - elif x < self.agent.rect.x: - self.agent.direction = 2 - elif y < self.agent.rect.y: - self.agent.direction = 3 - if self.agent.direction==0: - print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction]) - self.agent.x_change += TILE_SIZE - elif self.agent.direction==1: - print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction]) - self.agent.y_change += TILE_SIZE - elif self.agent.direction==2: - print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction]) - self.agent.x_change -= TILE_SIZE - elif self.agent.direction==3: - print("DIRECTION: "+self.agent.AGENT_IMAGES[self.agent.direction]) - self.agent.y_change -= TILE_SIZE - - self.agent.rotate() - self.update() - self.map() - - print("Położenie agenta: agent.x: ", self.agent.rect.x, ", agent.y: ", self.agent.rect.y) - self.clock.tick(2) - - def get_coordinates(self,cell_to_move): #zamienia numer kratki na koordynaty - cell_row_number = cell_to_move // NUM_ROWS - cell_column_number = cell_to_move % NUM_ROWS - - y = cell_row_number * TILE_SIZE - x = cell_column_number * TILE_SIZE - return x, y - g = Game() g.new() diff --git a/map_add_ons.py b/map_add_ons.py index 7a2c052..a2e01a2 100644 --- a/map_add_ons.py +++ b/map_add_ons.py @@ -5,7 +5,8 @@ class Rocks(pygame.sprite.Sprite): def __init__(self,game,x,y): self.game = game - self.groups = self.game.all_sprites, self.game.rock_sprites + self.groups = self.game.rock_sprites + pygame.sprite.Sprite.__init__(self, self.groups) self.x = x * TILE_SIZE @@ -23,4 +24,60 @@ class Rocks(pygame.sprite.Sprite): self.rect = self.image.get_rect() self.rect.x = self.x self.rect.y = self.y + + + +class Grass(pygame.sprite.Sprite): + + def __init__(self,game,x,y): + self.game = game + self.groups = self.game.grass_sprites + pygame.sprite.Sprite.__init__(self, self.groups) + + self.x = x * TILE_SIZE + self.y = y * TILE_SIZE + self.width = TILE_SIZE + self.height = TILE_SIZE + + self.GRASS_PNG = pygame.image.load("./zdjecia/grass.png") + self.GRASS = pygame.transform.scale(self.GRASS_PNG,(64,64)) + + self.image = pygame.Surface([self.width, self.height]) + self.image.blit(self.GRASS,(0,0)) + self.image.set_colorkey((0, 0, 0)) + + self.rect = self.image.get_rect() + self.rect.x = self.x + self.rect.y = self.y + + self.cost = 10 + + self._layer = GRASS_LAYER + +class Health_flower(pygame.sprite.Sprite): + + + def __init__(self, game, x, y): + self.game = game + self.groups = self.game.flowers, + pygame.sprite.Sprite.__init__(self, self.groups) + + self.x = x * TILE_SIZE + self.y = y * TILE_SIZE + self.width = TILE_SIZE + self.height = TILE_SIZE + + self.FLOWER_IMG = pygame.image.load("./zdjecia/flower.png") + self.FLOWER = pygame.transform.scale(self.FLOWER_IMG,(64,64)) + + self.image = pygame.Surface([self.width, self.height]) + self.image.blit(self.FLOWER, (0,0)) + self.image.set_colorkey((0, 0, 0)) + + self.rect = self.image.get_rect() + self.rect.x = self.x + self.rect.y = self.y + + self._layer = FLOWER_LAYER + diff --git a/mobs.py b/mobs.py new file mode 100644 index 0000000..c5b53c5 --- /dev/null +++ b/mobs.py @@ -0,0 +1,113 @@ +import pygame +from config import * + +class Archer_ork(pygame.sprite.Sprite): + + + def __init__(self, game, x, y): + self.game = game + self.groups = self.game.all_sprites, self.game.archer_orks + pygame.sprite.Sprite.__init__(self, self.groups) + + self.x = x * TILE_SIZE + self.y = y * TILE_SIZE + self.width = TILE_SIZE + self.height = TILE_SIZE + + self.ARCHER_ORK_IMG = pygame.image.load("./zdjecia/ork_lucznik.png") + self.ARCHER_ORK = pygame.transform.scale(self.ARCHER_ORK_IMG,(64,64)) + + self.image = pygame.Surface([self.width, self.height]) + self.image.blit(self.ARCHER_ORK, (0,0)) + self.image.set_colorkey((0, 0, 0)) + + self.rect = self.image.get_rect() + self.rect.x = self.x + self.rect.y = self.y + + self.level = 1 + self.damage = 50*self.level + +class Infantry_ork(pygame.sprite.Sprite): + + + def __init__(self, game, x, y): + self.game = game + self.groups = self.game.all_sprites, self.game.infantry_orks + pygame.sprite.Sprite.__init__(self, self.groups) + + self.x = x * TILE_SIZE + self.y = y * TILE_SIZE + self.width = TILE_SIZE + self.height = TILE_SIZE + + self.INFANTRY_ORK_IMG = pygame.image.load("./zdjecia/ork-piechota.png") + self.INFANTRY_ORK = pygame.transform.scale(self.INFANTRY_ORK_IMG,(64,64)) + + self.image = pygame.Surface([self.width, self.height]) + self.image.blit(self.INFANTRY_ORK, (0,0)) + self.image.set_colorkey((0, 0, 0)) + + self.rect = self.image.get_rect() + self.rect.x = self.x + self.rect.y = self.y + + self.level = 2 + self.damage = 50*self.level + + +class Infantry_ork2(pygame.sprite.Sprite): + + + def __init__(self, game, x, y): + self.game = game + self.groups = self.game.all_sprites, self.game.infantry_orks2 + pygame.sprite.Sprite.__init__(self, self.groups) + + self.x = x * TILE_SIZE + self.y = y * TILE_SIZE + self.width = TILE_SIZE + self.height = TILE_SIZE + + self.INFANTRY_ORK2_IMG = pygame.image.load("./zdjecia/ork-piechota2.png") + self.INFANTRY_ORK2 = pygame.transform.scale(self.INFANTRY_ORK2_IMG,(64,64)) + + self.image = pygame.Surface([self.width, self.height]) + self.image.blit(self.INFANTRY_ORK2, (0,0)) + self.image.set_colorkey((0, 0, 0)) + + self.rect = self.image.get_rect() + self.rect.x = self.x + self.rect.y = self.y + + self.level = 3 + self.damage = 50*self.level + + +class Sauron(pygame.sprite.Sprite): + + + def __init__(self, game, x, y): + self.game = game + self.groups = self.game.all_sprites, self.game.sauronL + pygame.sprite.Sprite.__init__(self, self.groups) + + self.x = x * TILE_SIZE + self.y = y * TILE_SIZE + self.width = TILE_SIZE + self.height = TILE_SIZE + + self.SAURON_IMG = pygame.image.load("./zdjecia/sauron.png") + self.SAURON = pygame.transform.scale(self.SAURON_IMG,(64,64)) + + self.image = pygame.Surface([self.width, self.height]) + self.image.blit(self.SAURON, (0,0)) + self.image.set_colorkey((0, 0, 0)) + + self.rect = self.image.get_rect() + self.rect.x = self.x + self.rect.y = self.y + + self.level = 4 + self.damage = 50*self.level + \ No newline at end of file diff --git a/sauron.py b/sauron.py deleted file mode 100644 index e5d9c07..0000000 --- a/sauron.py +++ /dev/null @@ -1,29 +0,0 @@ -import pygame -from config import * - -class Sauron(pygame.sprite.Sprite): - - - def __init__(self, game, x, y): - self.game = game - self.groups = self.game.all_sprites, self.game.sauronL - pygame.sprite.Sprite.__init__(self, self.groups) - - self.x = x * TILE_SIZE - self.y = y * TILE_SIZE - self.width = TILE_SIZE - self.height = TILE_SIZE - - self.SAURON_IMG = pygame.image.load("./zdjecia/sauron.png") - self.SAURON = pygame.transform.scale(self.SAURON_IMG,(64,64)) - - self.image = pygame.Surface([self.width, self.height]) - self.image.blit(self.SAURON, (0,0)) - self.image.set_colorkey((0, 0, 0)) - - self.rect = self.image.get_rect() - self.rect.x = self.x - self.rect.y = self.y - - self.level = 4 - self.damage = 50*self.level \ No newline at end of file diff --git a/zdjecia/grass.png b/zdjecia/grass.png new file mode 100644 index 0000000..ea27812 Binary files /dev/null and b/zdjecia/grass.png differ