Merge pull request 'added castle;' (#10) from castle into master

Reviewed-on: s464965/WMICraft#10
This commit is contained in:
Angelika Iskra 2022-03-24 16:33:08 +01:00
commit 65afafb642
4 changed files with 36 additions and 5 deletions

View File

@ -17,6 +17,10 @@ MONSTER_SPAWN_WIDTH = 19
MONSTER_SPAWN_HEIGHT = 15
MONSTER_SPAWN_FIRST_COL = 4
MONSTER_SPAWN_FIRST_ROW = 0
CASTLE_SPAWN_WIDTH = 6
CASTLE_SPAWN_HEIGHT = 5
CASTLE_SPAWN_FIRST_ROW = 7
CASTLE_SPAWN_FIRST_COL = 9
TILES = [
'grass1.png',
'grass2.png',

View File

@ -3,10 +3,9 @@ import sys
import pygame
from common.colors import FONT_DARK, WHITE
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, MONSTER_SPAWN_WIDTH, MONSTER_SPAWN_HEIGHT, \
MONSTER_SPAWN_FIRST_COL, MONSTER_SPAWN_FIRST_ROW
from common.constants import *
from common.helpers import draw_text
from models.castle import Castle
from models.knight import Knight
from models.monster import Monster
from ui.logs import Logs
@ -90,6 +89,7 @@ class Game:
knights_sprite_group = pygame.sprite.Group()
monsters_sprite_group = pygame.sprite.Group()
castle_sprite_group = pygame.sprite.Group()
knights_left = self.generate_knights_team(knights_sprite_group)
knights_right = self.generate_knights_team(knights_sprite_group)
@ -104,12 +104,17 @@ class Game:
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)
pos_row=MONSTER_SPAWN_FIRST_ROW, pos_column=MONSTER_SPAWN_FIRST_COL)
monster_spawn.spawn_monsters()
spawned_castle = self.generate_castle(castle_sprite_group)
castle_spawn = Spawner(grid, [spawned_castle], width=CASTLE_SPAWN_WIDTH, height=CASTLE_SPAWN_HEIGHT,
pos_row=CASTLE_SPAWN_FIRST_ROW, pos_column=CASTLE_SPAWN_FIRST_COL)
castle_spawn.spawn()
while running:
self.screen.blit(self.bg, (0, 0))
@ -127,6 +132,7 @@ class Game:
knights_sprite_group.draw(self.screen)
monsters_sprite_group.draw(self.screen)
castle_sprite_group.draw(self.screen)
pygame.display.update()
self.clock.tick(FPS_COUNT)
@ -147,3 +153,9 @@ class Game:
monsters.append(monster)
monsters_sprite_group.add(monster)
return monsters
@staticmethod
def generate_castle(castle_sprite_group):
castle = Castle()
castle_sprite_group.add(castle)
return castle

15
models/castle.py Normal file
View File

@ -0,0 +1,15 @@
import pygame.image
class Castle(pygame.sprite.Sprite):
images = []
def __init__(self):
super().__init__()
self.image = pygame.image.load("./resources/textures/castle.png")
self.image = pygame.transform.scale(self.image, (78, 78))
self.images.append(self.image)
self.rect = self.image.get_rect()
castle_list = pygame.sprite.Group()
self.health = 80

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB