From c6cc763fe1e0eccdd81026e811896f8b16ab2400 Mon Sep 17 00:00:00 2001 From: AleksandraMuczynska Date: Thu, 9 Jun 2022 23:24:57 +0200 Subject: [PATCH] final attack version! \o/ --- logic/level.py | 101 ++++++++++++++++++++++++++++++++++------------ models/castle.py | 3 +- models/knight.py | 13 +++--- models/monster.py | 9 ++--- 4 files changed, 88 insertions(+), 38 deletions(-) diff --git a/logic/level.py b/logic/level.py index b14548b..9ea5ebd 100644 --- a/logic/level.py +++ b/logic/level.py @@ -92,54 +92,103 @@ class Level: self.map[row_index][col_index] = castle self.list_castles.append(castle) - def attack_knight(self, knights_list, positions, current_knight): - op_pos_1 = current_knight.position[0] - 1, current_knight.position[1] - positions.append(op_pos_1) - op_pos_2 = current_knight.position[0], current_knight.position[1] - 1 - positions.append(op_pos_2) - op_pos_3 = current_knight.position[0] + 1, current_knight.position[1] - positions.append(op_pos_3) - op_pos_4 = current_knight.position[0], current_knight.position[1] + 1 - positions.append(op_pos_4) - for some_knight in knights_list: - for some_position in positions: - if some_knight.position == some_position: - some_knight.health_bar.take_dmg(1) - if some_knight.health_bar.current_hp == 0: - some_knight.kill() - positions.clear() + #def attack_knight(self, knights_list, positions, current_knight): + # op_pos_1 = current_knight.position[0] - 1, current_knight.position[1] + # positions.append(op_pos_1) + # op_pos_2 = current_knight.position[0], current_knight.position[1] - 1 + # positions.append(op_pos_2) + # op_pos_3 = current_knight.position[0] + 1, current_knight.position[1] + # positions.append(op_pos_3) + # op_pos_4 = current_knight.position[0], current_knight.position[1] + 1 + # positions.append(op_pos_4) + # for some_knight in knights_list: + # for some_position in positions: + # if (some_knight.position == some_position and some_knight.team != current_knight.team): + # some_knight.health_bar.take_dmg(current_knight.attack) + # if some_knight.health_bar.current_hp == 0: + # some_knight.kill() + # positions.clear() def attack_knight_left(self, knights_list, current_knight): position_left = current_knight.position[0] - 1, current_knight.position[1] for some_knight in knights_list: - if some_knight.position == position_left: - some_knight.health_bar.take_dmg(1) - if some_knight.health_bar.current_hp == 0: + if (some_knight.position == position_left and some_knight.team != current_knight.team): + some_knight.health_bar.take_dmg(current_knight.attack) + if some_knight.health_bar.current_hp <= 0: some_knight.kill() + for monster in self.list_monsters: + if monster.position == position_left: + monster.health_bar.take_dmg(current_knight.attack) + if monster.health_bar.current_hp <= 0: + monster.kill() + else: + current_knight.health_bar.take_dmg(monster.attack) + if current_knight.health_bar.current_hp <= 0: + current_knight.kill() + for castle in self.list_castles: + if castle.position == position_left: + castle.health_bar.take_dmg(current_knight.attack) + def attack_knight_right(self, knights_list, current_knight): position_right = current_knight.position[0] + 1, current_knight.position[1] for some_knight in knights_list: - if some_knight.position == position_right: - some_knight.health_bar.take_dmg(1) + if (some_knight.position == position_right and some_knight.team != current_knight.team): + some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp == 0: some_knight.kill() + for monster in self.list_monsters: + if monster.position == position_right: + monster.health_bar.take_dmg(current_knight.attack) + if monster.health_bar.current_hp <= 0: + monster.kill() + else: + current_knight.health_bar.take_dmg(monster.attack) + if current_knight.health_bar.current_hp <= 0: + current_knight.kill() + for castle in self.list_castles: + if castle.position == position_right: + castle.health_bar.take_dmg(current_knight.attack) def attack_knight_up(self, knights_list, current_knight): - position_up = current_knight.position[0] , current_knight.position[1] - 1 + position_up = current_knight.position[0], current_knight.position[1] - 1 for some_knight in knights_list: - if some_knight.position == position_up: - some_knight.health_bar.take_dmg(1) + if (some_knight.position == position_up and some_knight.team != current_knight.team): + some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp == 0: some_knight.kill() + for monster in self.list_monsters: + if monster.position == position_up: + monster.health_bar.take_dmg(current_knight.attack) + if monster.health_bar.current_hp <= 0: + monster.kill() + else: + current_knight.health_bar.take_dmg(monster.attack) + if current_knight.health_bar.current_hp <= 0: + current_knight.kill() + for castle in self.list_castles: + if castle.position == position_up: + castle.health_bar.take_dmg(current_knight.attack) def attack_knight_down(self, knights_list, current_knight): position_down = current_knight.position[0], current_knight.position[1] + 1 for some_knight in knights_list: - if some_knight.position == position_down: - some_knight.health_bar.take_dmg(1) + if (some_knight.position == position_down and some_knight.team != current_knight.team): + some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp == 0: some_knight.kill() + for monster in self.list_monsters: + if monster.position == position_down: + monster.health_bar.take_dmg(current_knight.attack) + if monster.health_bar.current_hp <= 0: + monster.kill() + else: + current_knight.health_bar.take_dmg(monster.attack) + if current_knight.health_bar.current_hp <= 0: + current_knight.kill() + for castle in self.list_castles: + if castle.position == position_down: + castle.health_bar.take_dmg(current_knight.attack) def handle_turn(self): current_knight = self.knights_queue.dequeue_knight() diff --git a/models/castle.py b/models/castle.py index 6484c63..80f0703 100644 --- a/models/castle.py +++ b/models/castle.py @@ -16,8 +16,7 @@ class Castle(pygame.sprite.Sprite): position_in_px = (parse_cord(position[0]), parse_cord(position[1])) self.rect = self.image.get_rect(center=position_in_px) self.max_hp = 80 - self.current_hp = random.randint(1, self.max_hp) - self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True) + self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True) def update(self): self.health_bar.update() diff --git a/models/knight.py b/models/knight.py index 39c2679..4b3dad4 100644 --- a/models/knight.py +++ b/models/knight.py @@ -7,8 +7,11 @@ from common.helpers import parse_cord from logic.health_bar import HealthBar -def load_knight_textures(): - random_index = random.randint(1, 4) +def load_knight_textures(team): + if team == "blue": + random_index = 3 + else: + random_index = 4 states = [ pygame.image.load(f'resources/textures/knight_{random_index}_up.png').convert_alpha(), # up = 0 pygame.image.load(f'resources/textures/knight_{random_index}_right.png').convert_alpha(), # right = 1 @@ -24,7 +27,7 @@ class Knight(pygame.sprite.Sprite): super().__init__(group) self.direction = Direction.DOWN - self.states = load_knight_textures() + self.states = load_knight_textures(team) self.image = self.states[self.direction.value] self.position = position @@ -33,8 +36,8 @@ class Knight(pygame.sprite.Sprite): self.rect = self.image.get_rect(topleft=position_in_px) self.team = team - self.max_hp = random.randint(7, 12) - self.attack = random.randint(4, 7) + self.max_hp = random.randint(9, 13) + self.attack = random.randint(2, 4) self.defense = random.randint(1, 4) self.points = 1 self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True) diff --git a/models/monster.py b/models/monster.py index 9ecbe09..7631d4f 100644 --- a/models/monster.py +++ b/models/monster.py @@ -22,14 +22,13 @@ class Monster(pygame.sprite.Sprite): position_in_px = (parse_cord(position[0]), parse_cord(position[1])) self.rect = self.image.get_rect(topleft=position_in_px) self.position = position - self.max_hp = random.randrange(15, 25) - self.current_hp = random.randint(1, self.max_hp) - self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp, + self.max_hp = random.randrange(15, 20) + self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True) - self.attack = random.randrange(2, 10) + self.attack = random.randrange(4, 6) if self.image == monster_images[0]: self.max_hp = 20 - self.attack = 9 + self.attack = 6 self.points = 10 elif self.image == monster_images[1]: self.max_hp = 15