Merge pull request 'final attack version! \o/' (#40) from attack_v3 into master

Reviewed-on: s464965/WMICraft#40
This commit is contained in:
Aleksandra Muczyńska 2022-06-09 23:26:20 +02:00
commit 050a0359b0
4 changed files with 88 additions and 38 deletions

View File

@ -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
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()

View File

@ -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()

View File

@ -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)

View File

@ -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