final attack version! \o/ #40
101
logic/level.py
101
logic/level.py
@ -92,54 +92,103 @@ class Level:
|
|||||||
self.map[row_index][col_index] = castle
|
self.map[row_index][col_index] = castle
|
||||||
self.list_castles.append(castle)
|
self.list_castles.append(castle)
|
||||||
|
|
||||||
def attack_knight(self, knights_list, positions, current_knight):
|
#def attack_knight(self, knights_list, positions, current_knight):
|
||||||
op_pos_1 = current_knight.position[0] - 1, current_knight.position[1]
|
# op_pos_1 = current_knight.position[0] - 1, current_knight.position[1]
|
||||||
positions.append(op_pos_1)
|
# positions.append(op_pos_1)
|
||||||
op_pos_2 = current_knight.position[0], current_knight.position[1] - 1
|
# op_pos_2 = current_knight.position[0], current_knight.position[1] - 1
|
||||||
positions.append(op_pos_2)
|
# positions.append(op_pos_2)
|
||||||
op_pos_3 = current_knight.position[0] + 1, current_knight.position[1]
|
# op_pos_3 = current_knight.position[0] + 1, current_knight.position[1]
|
||||||
positions.append(op_pos_3)
|
# positions.append(op_pos_3)
|
||||||
op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
|
# op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
|
||||||
positions.append(op_pos_4)
|
# positions.append(op_pos_4)
|
||||||
for some_knight in knights_list:
|
# for some_knight in knights_list:
|
||||||
for some_position in positions:
|
# for some_position in positions:
|
||||||
if some_knight.position == some_position:
|
# if (some_knight.position == some_position and some_knight.team != current_knight.team):
|
||||||
some_knight.health_bar.take_dmg(1)
|
# some_knight.health_bar.take_dmg(current_knight.attack)
|
||||||
if some_knight.health_bar.current_hp == 0:
|
# if some_knight.health_bar.current_hp == 0:
|
||||||
some_knight.kill()
|
# some_knight.kill()
|
||||||
positions.clear()
|
# positions.clear()
|
||||||
|
|
||||||
def attack_knight_left(self, knights_list, current_knight):
|
def attack_knight_left(self, knights_list, current_knight):
|
||||||
position_left = current_knight.position[0] - 1, current_knight.position[1]
|
position_left = current_knight.position[0] - 1, current_knight.position[1]
|
||||||
for some_knight in knights_list:
|
for some_knight in knights_list:
|
||||||
if some_knight.position == position_left:
|
if (some_knight.position == position_left and some_knight.team != current_knight.team):
|
||||||
some_knight.health_bar.take_dmg(1)
|
some_knight.health_bar.take_dmg(current_knight.attack)
|
||||||
if some_knight.health_bar.current_hp == 0:
|
if some_knight.health_bar.current_hp <= 0:
|
||||||
some_knight.kill()
|
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):
|
def attack_knight_right(self, knights_list, current_knight):
|
||||||
position_right = current_knight.position[0] + 1, current_knight.position[1]
|
position_right = current_knight.position[0] + 1, current_knight.position[1]
|
||||||
for some_knight in knights_list:
|
for some_knight in knights_list:
|
||||||
if some_knight.position == position_right:
|
if (some_knight.position == position_right and some_knight.team != current_knight.team):
|
||||||
some_knight.health_bar.take_dmg(1)
|
some_knight.health_bar.take_dmg(current_knight.attack)
|
||||||
if some_knight.health_bar.current_hp == 0:
|
if some_knight.health_bar.current_hp == 0:
|
||||||
some_knight.kill()
|
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):
|
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:
|
for some_knight in knights_list:
|
||||||
if some_knight.position == position_up:
|
if (some_knight.position == position_up and some_knight.team != current_knight.team):
|
||||||
some_knight.health_bar.take_dmg(1)
|
some_knight.health_bar.take_dmg(current_knight.attack)
|
||||||
if some_knight.health_bar.current_hp == 0:
|
if some_knight.health_bar.current_hp == 0:
|
||||||
some_knight.kill()
|
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):
|
def attack_knight_down(self, knights_list, current_knight):
|
||||||
position_down = current_knight.position[0], current_knight.position[1] + 1
|
position_down = current_knight.position[0], current_knight.position[1] + 1
|
||||||
for some_knight in knights_list:
|
for some_knight in knights_list:
|
||||||
if some_knight.position == position_down:
|
if (some_knight.position == position_down and some_knight.team != current_knight.team):
|
||||||
some_knight.health_bar.take_dmg(1)
|
some_knight.health_bar.take_dmg(current_knight.attack)
|
||||||
if some_knight.health_bar.current_hp == 0:
|
if some_knight.health_bar.current_hp == 0:
|
||||||
some_knight.kill()
|
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):
|
def handle_turn(self):
|
||||||
current_knight = self.knights_queue.dequeue_knight()
|
current_knight = self.knights_queue.dequeue_knight()
|
||||||
|
@ -16,8 +16,7 @@ class Castle(pygame.sprite.Sprite):
|
|||||||
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
||||||
self.rect = self.image.get_rect(center=position_in_px)
|
self.rect = self.image.get_rect(center=position_in_px)
|
||||||
self.max_hp = 80
|
self.max_hp = 80
|
||||||
self.current_hp = random.randint(1, self.max_hp)
|
self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)
|
||||||
self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.health_bar.update()
|
self.health_bar.update()
|
||||||
|
@ -7,8 +7,11 @@ from common.helpers import parse_cord
|
|||||||
from logic.health_bar import HealthBar
|
from logic.health_bar import HealthBar
|
||||||
|
|
||||||
|
|
||||||
def load_knight_textures():
|
def load_knight_textures(team):
|
||||||
random_index = random.randint(1, 4)
|
if team == "blue":
|
||||||
|
random_index = 3
|
||||||
|
else:
|
||||||
|
random_index = 4
|
||||||
states = [
|
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}_up.png').convert_alpha(), # up = 0
|
||||||
pygame.image.load(f'resources/textures/knight_{random_index}_right.png').convert_alpha(), # right = 1
|
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)
|
super().__init__(group)
|
||||||
|
|
||||||
self.direction = Direction.DOWN
|
self.direction = Direction.DOWN
|
||||||
self.states = load_knight_textures()
|
self.states = load_knight_textures(team)
|
||||||
|
|
||||||
self.image = self.states[self.direction.value]
|
self.image = self.states[self.direction.value]
|
||||||
self.position = position
|
self.position = position
|
||||||
@ -33,8 +36,8 @@ class Knight(pygame.sprite.Sprite):
|
|||||||
self.rect = self.image.get_rect(topleft=position_in_px)
|
self.rect = self.image.get_rect(topleft=position_in_px)
|
||||||
|
|
||||||
self.team = team
|
self.team = team
|
||||||
self.max_hp = random.randint(7, 12)
|
self.max_hp = random.randint(9, 13)
|
||||||
self.attack = random.randint(4, 7)
|
self.attack = random.randint(2, 4)
|
||||||
self.defense = random.randint(1, 4)
|
self.defense = random.randint(1, 4)
|
||||||
self.points = 1
|
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)
|
self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)
|
||||||
|
@ -22,14 +22,13 @@ class Monster(pygame.sprite.Sprite):
|
|||||||
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
|
||||||
self.rect = self.image.get_rect(topleft=position_in_px)
|
self.rect = self.image.get_rect(topleft=position_in_px)
|
||||||
self.position = position
|
self.position = position
|
||||||
self.max_hp = random.randrange(15, 25)
|
self.max_hp = random.randrange(15, 20)
|
||||||
self.current_hp = random.randint(1, self.max_hp)
|
self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=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)
|
calculate_xy=True, calculate_size=True)
|
||||||
self.attack = random.randrange(2, 10)
|
self.attack = random.randrange(4, 6)
|
||||||
if self.image == monster_images[0]:
|
if self.image == monster_images[0]:
|
||||||
self.max_hp = 20
|
self.max_hp = 20
|
||||||
self.attack = 9
|
self.attack = 6
|
||||||
self.points = 10
|
self.points = 10
|
||||||
elif self.image == monster_images[1]:
|
elif self.image == monster_images[1]:
|
||||||
self.max_hp = 15
|
self.max_hp = 15
|
||||||
|
Loading…
Reference in New Issue
Block a user