diff --git a/resources/graphics/Cards/card_hypnoshroom.png b/resources/graphics/Cards/card_hypnoshroom.png new file mode 100644 index 0000000..e605f48 Binary files /dev/null and b/resources/graphics/Cards/card_hypnoshroom.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_0.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_0.png new file mode 100644 index 0000000..0a79f9b Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_0.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_1.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_1.png new file mode 100644 index 0000000..e5a9a14 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_1.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_10.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_10.png new file mode 100644 index 0000000..a42062e Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_10.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_11.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_11.png new file mode 100644 index 0000000..ac92a54 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_11.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_12.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_12.png new file mode 100644 index 0000000..776cc9e Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_12.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_13.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_13.png new file mode 100644 index 0000000..a4b0064 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_13.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_14.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_14.png new file mode 100644 index 0000000..c86f012 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_14.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_2.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_2.png new file mode 100644 index 0000000..15db637 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_2.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_3.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_3.png new file mode 100644 index 0000000..4d1a2f7 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_3.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_4.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_4.png new file mode 100644 index 0000000..f42a16b Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_4.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_5.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_5.png new file mode 100644 index 0000000..c267773 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_5.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_6.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_6.png new file mode 100644 index 0000000..2e66838 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_6.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_7.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_7.png new file mode 100644 index 0000000..50de883 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_7.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_8.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_8.png new file mode 100644 index 0000000..9d0dae8 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_8.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_9.png b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_9.png new file mode 100644 index 0000000..a42062e Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroom/HypnoShroom_9.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_0.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_0.png new file mode 100644 index 0000000..1093170 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_0.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_1.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_1.png new file mode 100644 index 0000000..af4dbdc Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_1.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_10.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_10.png new file mode 100644 index 0000000..d54e2bd Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_10.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_11.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_11.png new file mode 100644 index 0000000..9d2809f Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_11.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_12.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_12.png new file mode 100644 index 0000000..cf87ac3 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_12.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_2.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_2.png new file mode 100644 index 0000000..8ed7d4f Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_2.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_3.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_3.png new file mode 100644 index 0000000..3c8b3c7 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_3.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_4.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_4.png new file mode 100644 index 0000000..d7a883a Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_4.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_5.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_5.png new file mode 100644 index 0000000..465ae9b Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_5.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_6.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_6.png new file mode 100644 index 0000000..dc46cbb Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_6.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_7.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_7.png new file mode 100644 index 0000000..e490c34 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_7.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_8.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_8.png new file mode 100644 index 0000000..ed304df Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_8.png differ diff --git a/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_9.png b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_9.png new file mode 100644 index 0000000..5ef4994 Binary files /dev/null and b/resources/graphics/Plants/HypnoShroom/HypnoShroomSleep/HypnoShroomSleep_9.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index 67dba64..27aceaf 100644 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -13,15 +13,17 @@ CARD_LIST_NUM = 8 card_name_list = [c.CARD_SUNFLOWER, c.CARD_PEASHOOTER, c.CARD_SNOWPEASHOOTER, c.CARD_WALLNUT, c.CARD_CHERRYBOMB, c.CARD_THREEPEASHOOTER, c.CARD_REPEATERPEA, c.CARD_CHOMPER, c.CARD_PUFFSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH, c.CARD_SPIKEWEED, - c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM, c.CARD_SUNSHROOM, c.CARD_ICESHROOM] + c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM, c.CARD_SUNSHROOM, c.CARD_ICESHROOM, + c.CARD_HYPNOSHROOM] plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT, c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER, c.PUFFSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED, - c.JALAPENO, c.SCAREDYSHROOM, c.SUNSHROOM, c.ICESHROOM] -plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25, 25, 75] + c.JALAPENO, c.SCAREDYSHROOM, c.SUNSHROOM, c.ICESHROOM, + c.HYPNOSHROOM] +plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25, 25, 75, 75] plant_frozen_time_list = [7500, 7500, 7500, 30000, 50000, 7500, 7500, 7500, 7500, 30000, - 30000, 7500, 50000, 7500, 7500, 50000] -all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + 30000, 7500, 50000, 7500, 7500, 50000, 3000] +all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] def getSunValueImage(sun_value): font = pg.font.SysFont(None, 22) diff --git a/source/component/plant.py b/source/component/plant.py index dfc7a73..2fd8878 100644 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -208,9 +208,11 @@ class Plant(pg.sprite.Sprite): self.state = c.SLEEP self.changeFrames(self.sleep_frames) - def setDamage(self, damage): + def setDamage(self, damage, zombie): self.health -= damage self.hit_timer = self.current_time + if self.health == 0: + self.kill_zombie = zombie def getPosition(self): return self.rect.centerx, self.rect.bottom @@ -799,4 +801,25 @@ class IceShroom(Plant): self.image = self.frames[self.frame_index] def getPosition(self): - return self.orig_pos \ No newline at end of file + return self.orig_pos + +class HypnoShroom(Plant): + def __init__(self, x, y): + Plant.__init__(self, x, y, c.HYPNOSHROOM, 1, None) + self.can_sleep = True + self.animate_interval = 200 + + def loadImages(self, name, scale): + self.idle_frames = [] + self.sleep_frames = [] + + idle_name = name + sleep_name = name + 'Sleep' + + frame_list = [self.idle_frames, self.sleep_frames] + name_list = [idle_name, sleep_name] + + for i, name in enumerate(name_list): + self.loadFrames(frame_list[i], name, 1, c.WHITE) + + self.frames = self.idle_frames \ No newline at end of file diff --git a/source/component/zombie.py b/source/component/zombie.py index bb2b720..73780f1 100644 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -36,6 +36,7 @@ class Zombie(pg.sprite.Sprite): self.hit_timer = 0 self.speed = 1 self.freeze_timer = 0 + self.is_hypno = False # the zombie is hypo and attack other zombies when it ate a HypnoShroom def loadFrames(self, frames, name, image_x, colorkey=c.BLACK): frame_list = tool.GFX[name] @@ -76,7 +77,10 @@ class Zombie(pg.sprite.Sprite): if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): self.walk_timer = self.current_time - self.rect.x -= self.speed + if self.is_hypno: + self.rect.x += self.speed + else: + self.rect.x -= self.speed def attacking(self): if self.health <= 0: @@ -84,13 +88,20 @@ class Zombie(pg.sprite.Sprite): elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead: self.changeFrames(self.losthead_attack_frames) self.setLostHead() + elif self.health <= c.NORMAL_HEALTH and self.helmet: + self.changeFrames(self.attack_frames) + self.helmet = False if (self.current_time - self.attack_timer) > (c.ATTACK_INTERVAL * self.getTimeRatio()): - self.plant.setDamage(self.damage) + if self.prey.health > 0: + if self.prey_is_plant: + self.prey.setDamage(self.damage, self) + else: + self.prey.setDamage(self.damage) self.attack_timer = self.current_time - if self.plant.health <= 0: - self.plant = None - self.setWalk() + if self.prey.health <= 0: + self.prey = None + self.setWalk() def dying(self): pass @@ -140,6 +151,8 @@ class Zombie(pg.sprite.Sprite): self.animate_timer = self.current_time self.image = self.frames[self.frame_index] + if self.is_hypno: + self.image = pg.transform.flip(self.image, True, False) if(self.current_time - self.hit_timer) >= 200: self.image.set_alpha(255) else: @@ -158,7 +171,7 @@ class Zombie(pg.sprite.Sprite): if (self.current_time - self.ice_slow_timer) > c.ICE_SLOW_TIME: self.ice_slow_ratio = 1 - def setDamage(self, damage, ice): + def setDamage(self, damage, ice=False): self.health -= damage self.hit_timer = self.current_time if ice: @@ -175,9 +188,11 @@ class Zombie(pg.sprite.Sprite): else: self.changeFrames(self.walk_frames) - def setAttack(self, plant): - self.plant = plant + def setAttack(self, prey, is_plant=True): + self.prey = prey # prey can be plant or other zombies + self.prey_is_plant = is_plant self.state = c.ATTACK + self.attack_timer = self.current_time self.animate_interval = 100 if self.helmet: @@ -210,6 +225,10 @@ class Zombie(pg.sprite.Sprite): if self.state == c.FREEZE: surface.blit(self.ice_trap_image, self.ice_trap_rect) + def setHypno(self): + self.is_hypno = True + self.setWalk() + class ZombieHead(Zombie): def __init__(self, x, y): Zombie.__init__(self, x, y, c.ZOMBIE_HEAD, 0) diff --git a/source/constants.py b/source/constants.py index 85b7dec..3c37bb6 100644 --- a/source/constants.py +++ b/source/constants.py @@ -81,6 +81,7 @@ JALAPENO = 'Jalapeno' SCAREDYSHROOM = 'ScaredyShroom' SUNSHROOM = 'SunShroom' ICESHROOM = 'IceShroom' +HYPNOSHROOM = 'HypnoShroom' PLANT_HEALTH = 5 WALLNUT_HEALTH = 30 @@ -114,7 +115,7 @@ CARD_JALAPENO = 'card_jalapeno' CARD_SCAREDYSHROOM = 'card_scaredyshroom' CARD_SUNSHROOM = 'card_sunshroom' CARD_ICESHROOM = 'card_iceshroom' - +CARD_HYPNOSHROOM = 'card_hypnoshroom' #BULLET INFO BULLET_PEA = 'PeaNormal' diff --git a/source/state/level.py b/source/state/level.py index f4c0b6b..c30e9de 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -46,10 +46,12 @@ class Level(tool.State): self.plant_groups = [] self.zombie_groups = [] + self.hypno_zombie_groups = [] #zombies who are hypno after eating hypnoshroom self.bullet_groups = [] for i in range(self.map_y_len): self.plant_groups.append(pg.sprite.Group()) self.zombie_groups.append(pg.sprite.Group()) + self.hypno_zombie_groups.append(pg.sprite.Group()) self.bullet_groups.append(pg.sprite.Group()) def setupZombies(self): @@ -116,6 +118,11 @@ class Level(tool.State): self.bullet_groups[i].update(self.game_info) self.plant_groups[i].update(self.game_info) self.zombie_groups[i].update(self.game_info) + self.hypno_zombie_groups[i].update(self.game_info) + for zombie in self.hypno_zombie_groups[i]: + if zombie.rect.x > c.SCREEN_WIDTH: + zombie.kill() + self.head_group.update(self.game_info) self.sun_group.update(self.game_info) @@ -214,6 +221,8 @@ class Level(tool.State): new_plant = plant.SunShroom(x, y, self.sun_group) elif self.plant_name == c.ICESHROOM: new_plant = plant.IceShroom(x, y) + elif self.plant_name == c.HYPNOSHROOM: + new_plant = plant.HypnoShroom(x, y) if new_plant.can_sleep and self.background_type == c.BACKGROUND_DAY: new_plant.setSleep() @@ -256,7 +265,7 @@ class Level(tool.State): if (plant_name == c.POTATOMINE or plant_name == c.SQUASH or plant_name == c.SPIKEWEED or plant_name == c.JALAPENO or plant_name == c.SCAREDYSHROOM or plant_name == c.SUNSHROOM or - plant_name == c.ICESHROOM): + plant_name == c.ICESHROOM or plant_name == c.HYPNOSHROOM): color = c.WHITE else: color = c.BLACK @@ -287,11 +296,27 @@ class Level(tool.State): def checkZombieCollisions(self): collided_func = pg.sprite.collide_circle_ratio(0.7) for i in range(self.map_y_len): + hypo_zombies = [] for zombie in self.zombie_groups[i]: + if zombie.state != c.WALK: + continue plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func) - if plant and plant.name != c.SPIKEWEED and zombie.state == c.WALK: + if plant and plant.name != c.SPIKEWEED: zombie.setAttack(plant) + for hypno_zombie in self.hypno_zombie_groups[i]: + if hypno_zombie.health <= 0: + continue + zombie_list = pg.sprite.spritecollide(hypno_zombie, + self.zombie_groups[i], False,collided_func) + for zombie in zombie_list: + if zombie.state == c.DIE: + continue + if zombie.state == c.WALK: + zombie.setAttack(hypno_zombie, False) + if hypno_zombie.state == c.WALK: + hypno_zombie.setAttack(zombie, False) + def checkCarCollisions(self): collided_func = pg.sprite.collide_circle_ratio(0.8) for car in self.cars: @@ -327,7 +352,12 @@ class Level(tool.State): plant.explode_x_range) elif plant.name == c.ICESHROOM and plant.state != c.SLEEP: self.freezeZombies(plant) - + elif plant.name == c.HYPNOSHROOM and plant.state != c.SLEEP: + zombie = plant.kill_zombie + zombie.setHypno() + _, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom) + self.zombie_groups[map_y].remove(zombie) + self.hypno_zombie_groups[map_y].add(zombie) plant.kill() def checkPlant(self, plant, i): @@ -457,6 +487,7 @@ class Level(tool.State): for i in range(self.map_y_len): self.plant_groups[i].draw(surface) self.zombie_groups[i].draw(surface) + self.hypno_zombie_groups[i].draw(surface) self.bullet_groups[i].draw(surface) self.drawZombieFreezeTrap(i, surface) for car in self.cars: