|
|
@ -158,7 +158,7 @@ class Enemy(pygame.sprite.Sprite): |
|
|
|
|
|
|
|
if life_ratio >= 0.75: |
|
|
|
self.health_bar_color = GREEN |
|
|
|
elif life_ratio < 0.75 and life_ratio > 0.25: |
|
|
|
elif life_ratio < 0.75 and life_ratio >= 0.25: |
|
|
|
self.health_bar_color = YELLOW |
|
|
|
else: |
|
|
|
self.health_bar_color = RED |
|
|
@ -229,13 +229,52 @@ class Snowball(pygame.sprite.Sprite): |
|
|
|
self.rect = self.image.get_rect() |
|
|
|
self.rect.center=(x, y) |
|
|
|
|
|
|
|
def move(self, player): |
|
|
|
self.rect.move_ip(4,0) |
|
|
|
def move(self, snowball_list, enemy_list): |
|
|
|
|
|
|
|
target_enemy = None |
|
|
|
for enemy in enemy_list: |
|
|
|
if enemy.alive == 1: |
|
|
|
target_enemy = enemy |
|
|
|
break |
|
|
|
|
|
|
|
if enemy == None: |
|
|
|
return |
|
|
|
|
|
|
|
enemy_x = enemy.rect.x |
|
|
|
enemy_y = enemy.rect.y |
|
|
|
|
|
|
|
snowball_x = self.rect.x |
|
|
|
snowball_y = self.rect.y |
|
|
|
|
|
|
|
if abs(enemy_x - snowball_x) < 8 and abs(enemy_y - snowball_y) < 8: |
|
|
|
snowball_list.remove(self) |
|
|
|
enemy.damage(50) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delta_move_x = 0 |
|
|
|
delta_move_y = 0 |
|
|
|
|
|
|
|
|
|
|
|
if enemy_x < snowball_x: |
|
|
|
delta_move_x = -4 |
|
|
|
elif enemy_x > snowball_x: |
|
|
|
delta_move_x = 4 |
|
|
|
|
|
|
|
|
|
|
|
if enemy_y < snowball_y: |
|
|
|
delta_move_y = -4 |
|
|
|
elif enemy_y > snowball_y: |
|
|
|
delta_move_y = 4 |
|
|
|
|
|
|
|
|
|
|
|
self.rect.move_ip(delta_move_x, delta_move_y) |
|
|
|
|
|
|
|
#if (self.rect.right > 600): |
|
|
|
# self.rect.top = 0 |
|
|
|
# self.rect.center = (0, 400) |
|
|
|
|
|
|
|
# if self.rect.colliderect(player.rect): |
|
|
|
#if self.rect.colliderect(player.rect): |
|
|
|
# print("HIT") |
|
|
|
|
|
|
|
def draw(self, surface): |
|
|
@ -417,14 +456,10 @@ def start_new_level(count, health): |
|
|
|
def valid_space(new_tower): |
|
|
|
global snowman_list |
|
|
|
global cakeman_list |
|
|
|
global reindeer_list |
|
|
|
|
|
|
|
combined_tower_list = snowman_list + cakeman_list |
|
|
|
combined_tower_list = snowman_list + cakeman_list + reindeer_list |
|
|
|
for old_tower in combined_tower_list: |
|
|
|
print("new: ") |
|
|
|
print(new_tower.rect) |
|
|
|
print("old: ") |
|
|
|
print(old_tower.rect) |
|
|
|
|
|
|
|
if new_tower.rect.colliderect(old_tower.rect): |
|
|
|
return False |
|
|
|
|
|
|
@ -619,7 +654,7 @@ while True: |
|
|
|
kagemand_animation_step = (kagemand_animation_step + 1) % 8 |
|
|
|
|
|
|
|
for snowball in snowball_list: |
|
|
|
snowball.move(menu_snowman) |
|
|
|
snowball.move(snowball_list, enemy_list) |
|
|
|
snowball.draw(DISPLAYSURF) |
|
|
|
|
|
|
|
for laser_beam in laser_beam_list: |
|
|
|