diff --git a/resources/graphics/Cards/card_scaredyshroom.png b/resources/graphics/Cards/card_scaredyshroom.png new file mode 100644 index 0000000..b8ebf82 Binary files /dev/null and b/resources/graphics/Cards/card_scaredyshroom.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_0.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_0.png new file mode 100644 index 0000000..ba733a3 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_0.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_1.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_1.png new file mode 100644 index 0000000..9e5d067 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_1.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_10.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_10.png new file mode 100644 index 0000000..291b293 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_10.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_11.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_11.png new file mode 100644 index 0000000..877af5a Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_11.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_12.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_12.png new file mode 100644 index 0000000..26ca157 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_12.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_13.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_13.png new file mode 100644 index 0000000..d575b3f Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_13.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_14.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_14.png new file mode 100644 index 0000000..fff8380 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_14.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_15.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_15.png new file mode 100644 index 0000000..fff8380 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_15.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_16.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_16.png new file mode 100644 index 0000000..dcc4818 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_16.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_2.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_2.png new file mode 100644 index 0000000..f6c0379 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_2.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_3.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_3.png new file mode 100644 index 0000000..49c0462 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_3.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_4.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_4.png new file mode 100644 index 0000000..260ea2d Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_4.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_5.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_5.png new file mode 100644 index 0000000..cb95661 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_5.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_6.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_6.png new file mode 100644 index 0000000..4364821 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_6.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_7.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_7.png new file mode 100644 index 0000000..6844992 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_7.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_8.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_8.png new file mode 100644 index 0000000..026a120 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_8.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_9.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_9.png new file mode 100644 index 0000000..1247365 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroom/ScaredyShroom_9.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_0.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_0.png new file mode 100644 index 0000000..01291fb Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_0.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_1.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_1.png new file mode 100644 index 0000000..74905bd Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_1.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_10.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_10.png new file mode 100644 index 0000000..010a1ec Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_10.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_2.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_2.png new file mode 100644 index 0000000..6c95fa7 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_2.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_3.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_3.png new file mode 100644 index 0000000..5056db3 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_3.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_4.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_4.png new file mode 100644 index 0000000..fe0a875 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_4.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_5.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_5.png new file mode 100644 index 0000000..7038061 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_5.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_6.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_6.png new file mode 100644 index 0000000..9e82862 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_6.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_7.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_7.png new file mode 100644 index 0000000..7d48bac Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_7.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_8.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_8.png new file mode 100644 index 0000000..9092794 Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_8.png differ diff --git a/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_9.png b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_9.png new file mode 100644 index 0000000..559ed0b Binary files /dev/null and b/resources/graphics/Plants/ScaredyShroom/ScaredyShroomCry/ScaredyShroomCry_9.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index 0b36777..cb9419e 100644 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -13,14 +13,15 @@ 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_PUFFMUSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH, c.CARD_SPIKEWEED, - c.CARD_JALAPENO] + c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM] plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT, c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER, c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED, - c.JALAPENO] -plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125] -plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000, 8000, 8000, 8000] -all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] + c.JALAPENO, c.SCAREDYSHROOM] +plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25] +plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000, + 8000, 8000, 8000, 5000] +all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] def getSunValueImage(sun_value): font = pg.font.SysFont(None, 22) diff --git a/source/component/plant.py b/source/component/plant.py index cc6ffda..ec4dca4 100644 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -124,7 +124,7 @@ class Plant(pg.sprite.Sprite): self.bullet_group = bullet_group self.animate_timer = 0 self.animate_interval = 100 - self.is_attacked = False + self.hit_timer = 0 def loadFrames(self, frames, name, scale, color=c.BLACK): frame_list = tool.GFX[name] @@ -168,9 +168,6 @@ class Plant(pg.sprite.Sprite): elif self.state == c.DIGEST: self.digest() - if self.is_attacked: - self.attacked() - def idling(self): pass @@ -180,9 +177,6 @@ class Plant(pg.sprite.Sprite): def digest(self): pass - def attacked(self): - pass - def animation(self): if (self.current_time - self.animate_timer) > self.animate_interval: self.frame_index += 1 @@ -191,9 +185,13 @@ class Plant(pg.sprite.Sprite): self.animate_timer = self.current_time self.image = self.frames[self.frame_index] + if(self.current_time - self.hit_timer) >= 200: + self.image.set_alpha(255) + else: + self.image.set_alpha(192) def canAttack(self, zombie): - if (self.rect.x <= zombie.rect.right): + if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right): return True return False @@ -204,11 +202,9 @@ class Plant(pg.sprite.Sprite): self.state = c.IDLE self.is_attacked = False - def setAttacked(self): - self.is_attacked = True - def setDamage(self, damage): self.health -= damage + self.hit_timer = self.current_time def getPosition(self): return self.rect.centerx, self.rect.bottom @@ -328,16 +324,12 @@ class WallNut(Plant): self.loadFrames(self.cracked1_frames, cracked1_frames_name, 1) self.loadFrames(self.cracked2_frames, cracked2_frames_name, 1) - def attacked(self): + def idling(self): if not self.cracked1 and self.health <= c.WALLNUT_CRACKED1_HEALTH: - self.frames = self.cracked1_frames - self.frame_num = len(self.frames) - self.frame_index = 0 + self.changeFrames(self.cracked1_frames) self.cracked1 = True elif not self.cracked2 and self.health <= c.WALLNUT_CRACKED2_HEALTH: - self.frames = self.cracked2_frames - self.frame_num = len(self.frames) - self.frame_index = 0 + self.changeFrames(self.cracked2_frames) self.cracked2 = True class CherryBomb(Plant): @@ -451,7 +443,7 @@ class PuffMushroom(Plant): def attacking(self): if (self.current_time - self.shoot_timer) > 3000: - self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y, + self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 10, self.rect.y + 10, c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True)) self.shoot_timer = self.current_time @@ -583,7 +575,6 @@ class Spikeweed(Plant): return False def setAttack(self, zombie_group): - print('spikeweed attack') self.zombie_group = zombie_group self.animate_interval = 50 self.state = c.ATTACK @@ -631,4 +622,49 @@ class Jalapeno(Plant): self.setExplode() return self.animate_timer = self.current_time - self.image = self.frames[self.frame_index] \ No newline at end of file + self.image = self.frames[self.frame_index] + +class ScaredyShroom(Plant): + def __init__(self, x, y, bullet_group): + Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group) + self.shoot_timer = 0 + self.cry_x_range = c.GRID_X_SIZE * 2 + + def loadImages(self, name, scale): + self.idle_frames = [] + self.cry_frames = [] + + idle_name = name + cry_name = name + 'Cry' + + frame_list = [self.idle_frames, self.cry_frames] + name_list = [idle_name, cry_name] + + for i, name in enumerate(name_list): + self.loadFrames(frame_list[i], name, 1, c.WHITE) + + self.frames = self.idle_frames + + def needCry(self, zombie): + if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right and + self.rect.x + self.cry_x_range > zombie.rect.x): + return True + return False + + def setCry(self): + self.state = c.CRY + self.changeFrames(self.cry_frames) + + def setAttack(self): + self.state = c.ATTACK + self.changeFrames(self.idle_frames) + + def setIdle(self): + self.state = c.IDLE + self.changeFrames(self.idle_frames) + + def attacking(self): + if (self.current_time - self.shoot_timer) > 2000: + self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 40, self.rect.y + 40, + c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True)) + self.shoot_timer = self.current_time \ No newline at end of file diff --git a/source/constants.py b/source/constants.py index 2954a60..d268222 100644 --- a/source/constants.py +++ b/source/constants.py @@ -78,6 +78,7 @@ POTATOMINE = 'PotatoMine' SQUASH = 'Squash' SPIKEWEED = 'Spikeweed' JALAPENO = 'Jalapeno' +SCAREDYSHROOM = 'ScaredyShroom' PLANT_HEALTH = 5 WALLNUT_HEALTH = 30 @@ -105,6 +106,7 @@ CARD_POTATOMINE = 'card_potatomine' CARD_SQUASH = 'card_squash' CARD_SPIKEWEED = 'card_spikeweed' CARD_JALAPENO = 'card_jalapeno' +CARD_SCAREDYSHROOM = 'card_scaredyshroom' #BULLET INFO BULLET_PEA = 'PeaNormal' @@ -143,6 +145,7 @@ ATTACKED = 'attacked' DIGEST = 'digest' WALK = 'walk' DIE = 'die' +CRY = 'cry' #LEVEL STATE CHOOSE = 'choose' diff --git a/source/state/level.py b/source/state/level.py index 6478056..19695d9 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -204,6 +204,8 @@ class Level(tool.State): self.plant_groups[map_y].add(plant.Spikeweed(x, y)) elif self.plant_name == c.JALAPENO: self.plant_groups[map_y].add(plant.Jalapeno(x, y)) + elif self.plant_name == c.SCAREDYSHROOM: + self.plant_groups[map_y].add(plant.ScaredyShroom(x, y, self.bullet_groups[map_y])) self.menubar.decreaseSunValue(self.plant_cost) self.menubar.setCardFrozenTime(self.plant_name) @@ -241,7 +243,8 @@ class Level(tool.State): width, height = rect.w, rect.h if (plant_name == c.POTATOMINE or plant_name == c.SQUASH or - plant_name == c.SPIKEWEED or plant_name == c.JALAPENO): + plant_name == c.SPIKEWEED or plant_name == c.JALAPENO or + plant_name == c.SCAREDYSHROOM): color = c.WHITE else: color = c.BLACK @@ -276,7 +279,6 @@ class Level(tool.State): plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func) if plant and plant.name != c.SPIKEWEED and zombie.state == c.WALK: zombie.setAttack(plant) - plant.setAttacked() def checkCarCollisions(self): collided_func = pg.sprite.collide_circle_ratio(0.8) @@ -351,13 +353,33 @@ class Level(tool.State): plant.setAttack(self.zombie_groups[i]) elif plant.state == c.ATTACK and not can_attack: plant.setIdle() + elif plant.name == c.SCAREDYSHROOM: + need_cry = False + can_attack = False + for zombie in self.zombie_groups[i]: + if plant.needCry(zombie): + need_cry = True + break + elif plant.canAttack(zombie): + can_attack = True + if need_cry: + if plant.state != c.CRY: + plant.setCry() + elif can_attack: + if plant.state != c.ATTACK: + plant.setAttack() + elif plant.state != c.IDLE: + plant.setIdle() else: + can_attack = False if (plant.state == c.IDLE and zombie_len > 0): for zombie in self.zombie_groups[i]: if plant.canAttack(zombie): - plant.setAttack() + can_attack = True break - elif (plant.state == c.ATTACK and zombie_len == 0): + if plant.state == c.IDLE and can_attack: + plant.setAttack() + elif (plant.state == c.ATTACK and not can_attack): plant.setIdle() if plant.health <= 0: