niekompletny update potworów
This commit is contained in:
parent
58518c3120
commit
bc6aa0a558
@ -13,6 +13,10 @@ KNIGHTS_SPAWN_WIDTH = 4
|
|||||||
KNIGHTS_SPAWN_HEIGHT = 5
|
KNIGHTS_SPAWN_HEIGHT = 5
|
||||||
KNIGHTS_SPAWN_FIRST_ROW = 8
|
KNIGHTS_SPAWN_FIRST_ROW = 8
|
||||||
KNIGHTS_SPAWN_FIRST_COL = 0
|
KNIGHTS_SPAWN_FIRST_COL = 0
|
||||||
|
MONSTER_SPAWN_WIDTH = 19
|
||||||
|
MONSTER_SPAWN_HEIGHT = 15
|
||||||
|
MONSTER_SPAWN_FIRST_COL = 4
|
||||||
|
MONSTER_SPAWN_FIRST_ROW = 0
|
||||||
TILES = [
|
TILES = [
|
||||||
'grass1.png',
|
'grass1.png',
|
||||||
'grass2.png',
|
'grass2.png',
|
||||||
|
@ -4,7 +4,8 @@ import pygame
|
|||||||
|
|
||||||
from common.colors import FONT_DARK, WHITE
|
from common.colors import FONT_DARK, WHITE
|
||||||
from common.constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT, TILES, COLUMNS, KNIGHTS_SPAWN_WIDTH, \
|
from common.constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT, TILES, COLUMNS, KNIGHTS_SPAWN_WIDTH, \
|
||||||
KNIGHTS_SPAWN_FIRST_ROW, KNIGHTS_SPAWN_HEIGHT, KNIGHTS_SPAWN_FIRST_COL
|
KNIGHTS_SPAWN_FIRST_ROW, KNIGHTS_SPAWN_HEIGHT, KNIGHTS_SPAWN_FIRST_COL, MONSTER_SPAWN_WIDTH, MONSTER_SPAWN_HEIGHT, \
|
||||||
|
MONSTER_SPAWN_FIRST_COL, MONSTER_SPAWN_FIRST_ROW
|
||||||
from common.helpers import draw_text
|
from common.helpers import draw_text
|
||||||
from models.knight import Knight
|
from models.knight import Knight
|
||||||
from models.monster import Monster
|
from models.monster import Monster
|
||||||
@ -88,6 +89,7 @@ class Game:
|
|||||||
logs = Logs()
|
logs = Logs()
|
||||||
|
|
||||||
knights_sprite_group = pygame.sprite.Group()
|
knights_sprite_group = pygame.sprite.Group()
|
||||||
|
monsters_sprite_group = pygame.sprite.Group()
|
||||||
|
|
||||||
knights_left = self.generate_knights_team(knights_sprite_group)
|
knights_left = self.generate_knights_team(knights_sprite_group)
|
||||||
knights_right = self.generate_knights_team(knights_sprite_group)
|
knights_right = self.generate_knights_team(knights_sprite_group)
|
||||||
@ -101,6 +103,13 @@ class Game:
|
|||||||
spawn_left_team.spawn()
|
spawn_left_team.spawn()
|
||||||
spawn_right_team.spawn()
|
spawn_right_team.spawn()
|
||||||
|
|
||||||
|
spawned_monsters = self.generate_monster((monsters_sprite_group))
|
||||||
|
|
||||||
|
monster_spawn = Spawner(grid, spawned_monsters, width=MONSTER_SPAWN_WIDTH, height=MONSTER_SPAWN_HEIGHT,
|
||||||
|
pos_row = MONSTER_SPAWN_FIRST_ROW, pos_column=MONSTER_SPAWN_FIRST_COL)
|
||||||
|
|
||||||
|
monster_spawn.spawn_monster()
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
self.screen.blit(self.bg, (0, 0))
|
self.screen.blit(self.bg, (0, 0))
|
||||||
|
|
||||||
@ -117,9 +126,10 @@ class Game:
|
|||||||
logs.draw(self.screen)
|
logs.draw(self.screen)
|
||||||
|
|
||||||
knights_sprite_group.draw(self.screen)
|
knights_sprite_group.draw(self.screen)
|
||||||
monster1 = Monster(self.screen, "./resources/textures/dragon.png")
|
monsters_sprite_group.draw(self.screen)
|
||||||
monster_list = pygame.sprite.Group()
|
# monster1 = Monster(self.screen)
|
||||||
monster_list.add(monster1)
|
# monster_list = pygame.sprite.Group()
|
||||||
|
# monster_list.add(monster1)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(FPS_COUNT)
|
self.clock.tick(FPS_COUNT)
|
||||||
|
|
||||||
@ -131,3 +141,11 @@ class Game:
|
|||||||
knights.append(knight)
|
knights.append(knight)
|
||||||
knights_sprite_group.add(knight)
|
knights_sprite_group.add(knight)
|
||||||
return knights
|
return knights
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_monster(monsters_sprite_group):
|
||||||
|
monsters = []
|
||||||
|
monster1 = Monster()
|
||||||
|
monsters.append(monster1)
|
||||||
|
monsters_sprite_group.add(monster1)
|
||||||
|
return monsters
|
||||||
|
@ -26,3 +26,18 @@ class Spawner:
|
|||||||
obj.rect.y = coords[random_tile][1]
|
obj.rect.y = coords[random_tile][1]
|
||||||
coords.pop(random_tile)
|
coords.pop(random_tile)
|
||||||
obj.update()
|
obj.update()
|
||||||
|
|
||||||
|
def spawn_monster(self):
|
||||||
|
coords = []
|
||||||
|
for row in range(self.pos_row, (self.pos_row + self.width)):
|
||||||
|
for column in range(self.pos_column, (self.pos_column + self.height)):
|
||||||
|
if self.grid.grid[row][column].texture_path != "water.png" and self.grid.grid[row][column].texture_path != "grass_with_tree.jpg" and not ((10 <=column <=14) and (8 <= row <= 12)):
|
||||||
|
coords.append([(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING + 7,
|
||||||
|
(GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING + 7])
|
||||||
|
|
||||||
|
for obj in self.objs_to_spawn_list:
|
||||||
|
random_tile = random.randint(0, len(coords) - 1)
|
||||||
|
obj.rect.x = coords[random_tile][0]
|
||||||
|
obj.rect.y = coords[random_tile][1]
|
||||||
|
coords.pop(random_tile)
|
||||||
|
obj.update()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import pygame.image
|
import pygame.image
|
||||||
|
import random
|
||||||
|
|
||||||
class Knight(pygame.sprite.Sprite):
|
class Knight(pygame.sprite.Sprite):
|
||||||
def __init__(self, img):
|
def __init__(self, img):
|
||||||
@ -9,5 +9,7 @@ class Knight(pygame.sprite.Sprite):
|
|||||||
self.image = pygame.transform.scale(self.image, (40, 40))
|
self.image = pygame.transform.scale(self.image, (40, 40))
|
||||||
self.images.append(self.image)
|
self.images.append(self.image)
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
|
self.health = random.randrange(7, 12)
|
||||||
|
self.attack = random.randrange(3, 7)
|
||||||
|
|
||||||
knights_list = pygame.sprite.Group()
|
knights_list = pygame.sprite.Group()
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
import pygame.image
|
import pygame.image
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
class Monster(pygame.sprite.Sprite):
|
class Monster(pygame.sprite.Sprite):
|
||||||
|
images = []
|
||||||
|
|
||||||
def __init__(self, screen, img):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.images = []
|
|
||||||
self.image = pygame.image.load("./resources/textures/dragon.png")
|
self.image = pygame.image.load("./resources/textures/dragon.png")
|
||||||
self.image = pygame.transform.scale(self.image, (40, 40))
|
self.image = pygame.transform.scale(self.image, (40, 40))
|
||||||
self.images.append(self.image)
|
self.images.append(self.image)
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
monster_list = pygame.sprite.Group()
|
monster_list = pygame.sprite.Group()
|
||||||
x = 337 + 41 * 5
|
#x = 337 + 41 * 5
|
||||||
y = 214 + 41 * 7
|
#y = 214 + 41 * 7
|
||||||
pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(x, y, 40, 40), 0, 0)
|
#pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(x, y, 40, 40), 0, 0)
|
||||||
screen.blit(self.image, (x, y))
|
#screen.blit(self.image, (x, y))
|
||||||
|
self.health = random.randrange(15, 25)
|
||||||
|
self.attack = random.randrange(2, 10)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 165 KiB |
Loading…
Reference in New Issue
Block a user