Merge pull request 'feat: spawning teams' (#7) from Knights_team_spawn into master

Reviewed-on: #7
This commit is contained in:
Dawid Korzępa 2022-03-21 21:13:30 +01:00
commit 58518c3120
2 changed files with 31 additions and 14 deletions

View File

@ -9,6 +9,10 @@ COLUMNS = 24
BORDER_WIDTH = 10 BORDER_WIDTH = 10
BORDER_RADIUS = 5 BORDER_RADIUS = 5
FPS_COUNT = 60 FPS_COUNT = 60
KNIGHTS_SPAWN_WIDTH = 4
KNIGHTS_SPAWN_HEIGHT = 5
KNIGHTS_SPAWN_FIRST_ROW = 8
KNIGHTS_SPAWN_FIRST_COL = 0
TILES = [ TILES = [
'grass1.png', 'grass1.png',
'grass2.png', 'grass2.png',

View File

@ -3,12 +3,13 @@ import sys
import pygame 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 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
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
from ui.screens.credits import Credits
from ui.logs import Logs from ui.logs import Logs
from ui.screens.credits import Credits
from ui.screens.options import Options from ui.screens.options import Options
from ui.stats import Stats from ui.stats import Stats
from .grid import Grid from .grid import Grid
@ -85,17 +86,20 @@ class Game:
grid = Grid(self.tiles) grid = Grid(self.tiles)
stats = Stats() stats = Stats()
logs = Logs() logs = Logs()
knight1 = Knight("./resources/textures/knight.png")
knight2 = Knight("./resources/textures/knight.png") knights_sprite_group = pygame.sprite.Group()
knight3 = Knight("./resources/textures/knight.png")
knight4 = Knight("./resources/textures/knight.png") knights_left = self.generate_knights_team(knights_sprite_group)
spawn = Spawner(grid, [knight1, knight2, knight3, knight4], 4, 5, 8, 0) knights_right = self.generate_knights_team(knights_sprite_group)
spawn.spawn()
knights_list = pygame.sprite.Group() spawn_left_team = Spawner(grid, knights_left, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT,
knights_list.add(knight1) pos_row=KNIGHTS_SPAWN_FIRST_ROW, pos_column=KNIGHTS_SPAWN_FIRST_COL)
knights_list.add(knight2) spawn_right_team = Spawner(grid, knights_right, width=KNIGHTS_SPAWN_WIDTH, height=KNIGHTS_SPAWN_HEIGHT,
knights_list.add(knight3) pos_row=KNIGHTS_SPAWN_FIRST_ROW,
knights_list.add(knight4) pos_column=COLUMNS - KNIGHTS_SPAWN_WIDTH - 1) # - 1 to avoid list index out of range
spawn_left_team.spawn()
spawn_right_team.spawn()
while running: while running:
self.screen.blit(self.bg, (0, 0)) self.screen.blit(self.bg, (0, 0))
@ -112,9 +116,18 @@ class Game:
stats.draw(self.screen) stats.draw(self.screen)
logs.draw(self.screen) logs.draw(self.screen)
knights_list.draw(self.screen) knights_sprite_group.draw(self.screen)
monster1 = Monster(self.screen, "./resources/textures/dragon.png") monster1 = Monster(self.screen, "./resources/textures/dragon.png")
monster_list = pygame.sprite.Group() monster_list = pygame.sprite.Group()
monster_list.add(monster1) monster_list.add(monster1)
pygame.display.update() pygame.display.update()
self.clock.tick(FPS_COUNT) self.clock.tick(FPS_COUNT)
@staticmethod
def generate_knights_team(knights_sprite_group):
knights = []
for i in range(4):
knight = Knight("./resources/textures/knight.png")
knights.append(knight)
knights_sprite_group.add(knight)
return knights