diff --git a/resources/graphics/Cards/card_spikeweed.png b/resources/graphics/Cards/card_spikeweed.png new file mode 100644 index 0000000..704a871 Binary files /dev/null and b/resources/graphics/Cards/card_spikeweed.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_0.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_0.png new file mode 100644 index 0000000..5dcf98b Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_0.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_1.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_1.png new file mode 100644 index 0000000..5dcf98b Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_1.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_10.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_10.png new file mode 100644 index 0000000..6b4e404 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_10.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_11.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_11.png new file mode 100644 index 0000000..4a0d0a2 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_11.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_12.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_12.png new file mode 100644 index 0000000..68af8f1 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_12.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_13.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_13.png new file mode 100644 index 0000000..dcd5057 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_13.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_14.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_14.png new file mode 100644 index 0000000..faa36dd Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_14.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_15.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_15.png new file mode 100644 index 0000000..09baa21 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_15.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_16.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_16.png new file mode 100644 index 0000000..abb3c8c Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_16.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_17.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_17.png new file mode 100644 index 0000000..bc2817a Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_17.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_18.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_18.png new file mode 100644 index 0000000..20e391d Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_18.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_2.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_2.png new file mode 100644 index 0000000..a2fa02e Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_2.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_3.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_3.png new file mode 100644 index 0000000..a2fa02e Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_3.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_4.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_4.png new file mode 100644 index 0000000..afbbf65 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_4.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_5.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_5.png new file mode 100644 index 0000000..88e5770 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_5.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_6.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_6.png new file mode 100644 index 0000000..eed8160 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_6.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_7.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_7.png new file mode 100644 index 0000000..acd491f Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_7.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_8.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_8.png new file mode 100644 index 0000000..acd491f Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_8.png differ diff --git a/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_9.png b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_9.png new file mode 100644 index 0000000..6b4e404 Binary files /dev/null and b/resources/graphics/Plants/Spikeweed/Spikeweed/Spikeweed_9.png differ diff --git a/resources/graphics/Screen/PanelBackground.png b/resources/graphics/Screen/PanelBackground.png new file mode 100644 index 0000000..56fbb93 Binary files /dev/null and b/resources/graphics/Screen/PanelBackground.png differ diff --git a/resources/graphics/Screen/StartButton.png b/resources/graphics/Screen/StartButton.png new file mode 100644 index 0000000..29268ca Binary files /dev/null and b/resources/graphics/Screen/StartButton.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index d445817..4bd74f1 100644 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -12,13 +12,13 @@ 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_PUFFMUSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH, c.CARD_SPIKEWEED] 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] -plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50] -plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000, 8000] -all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED] +plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100] +plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000, 8000, 8000] +all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] def getSunValueImage(sun_value): font = pg.font.SysFont(None, 22) diff --git a/source/component/plant.py b/source/component/plant.py index 3f1a87a..bec8e23 100644 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -560,4 +560,38 @@ class Squash(Plant): self.animate_interval = 300 def getPosition(self): - return self.orig_pos \ No newline at end of file + return self.orig_pos + +class Spikeweed(Plant): + def __init__(self, x, y): + Plant.__init__(self, x, y, c.SPIKEWEED, c.PLANT_HEALTH, None) + self.animate_interval = 200 + self.attack_timer = 0 + + def loadImages(self, name, scale): + self.loadFrames(self.frames, name, 0.9, c.WHITE) + self.select_image = self.frames[0] + + def setIdle(self): + print('spikeweed idle') + self.animate_interval = 200 + self.state = c.IDLE + + def canAttack(self, zombie): + if (self.rect.x <= zombie.rect.right and + (self.rect.right >= zombie.rect.x)): + return True + return False + + def setAttack(self, zombie_group): + print('spikeweed attack') + self.zombie_group = zombie_group + self.animate_interval = 50 + self.state = c.ATTACK + + def attacking(self): + if (self.current_time - self.attack_timer) > 2000: + self.attack_timer = self.current_time + for zombie in self.zombie_group: + if self.canAttack(zombie): + zombie.setDamage(1, False) \ No newline at end of file diff --git a/source/component/zombie.py b/source/component/zombie.py index 3718946..eb21a00 100644 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -33,6 +33,7 @@ class Zombie(pg.sprite.Sprite): self.animate_interval = 150 self.ice_slow_ratio = 1 self.ice_slow_timer = 0 + self.hit_timer = 0 self.speed = 1 def loadFrames(self, frames, name, image_x, colorkey=c.BLACK): @@ -118,8 +119,12 @@ class Zombie(pg.sprite.Sprite): return self.frame_index = 0 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 getTimeRatio(self): return self.ice_slow_ratio @@ -136,6 +141,7 @@ class Zombie(pg.sprite.Sprite): def setDamage(self, damage, ice): self.health -= damage + self.hit_timer = self.current_time if ice: self.setIceSlow() diff --git a/source/data/entity/plant.json b/source/data/entity/plant.json index e583099..b1b79dd 100644 --- a/source/data/entity/plant.json +++ b/source/data/entity/plant.json @@ -7,6 +7,7 @@ "BulletMushRoom":{"x":0, "y":1, "width":55, "height":21}, "PotatoMine":{"x":0, "y":0, "width":75, "height":55}, "Squash":{"x":10, "y":140, "width":80, "height":86}, - "SquashAim":{"x":10, "y":140, "width":80, "height":86} + "SquashAim":{"x":10, "y":140, "width":80, "height":86}, + "Spikeweed":{"x":3, "y":0, "width":80, "height":35} } } \ No newline at end of file diff --git a/source/state/level.py b/source/state/level.py index 0e67dc7..ff810ce 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -200,6 +200,8 @@ class Level(tool.State): self.plant_groups[map_y].add(plant.PotatoMine(x, y)) elif self.plant_name == c.SQUASH: self.plant_groups[map_y].add(plant.Squash(x, y)) + elif self.plant_name == c.SPIKEWEED: + self.plant_groups[map_y].add(plant.Spikeweed(x, y)) self.menubar.decreaseSunValue(self.plant_cost) self.menubar.setCardFrozenTime(self.plant_name) @@ -236,7 +238,7 @@ class Level(tool.State): rect = frame_list[0].get_rect() width, height = rect.w, rect.h - if plant_name == c.POTATOMINE or plant_name == c.SQUASH: + if plant_name == c.POTATOMINE or plant_name == c.SQUASH or plant_name == c.SPIKEWEED: color = c.WHITE else: color = c.BLACK @@ -269,7 +271,7 @@ class Level(tool.State): for i in range(self.map_y_len): for zombie in self.zombie_groups[i]: plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func) - if plant and zombie.state == c.WALK: + if plant and plant.name != c.SPIKEWEED and zombie.state == c.WALK: zombie.setAttack(plant) plant.setAttacked() @@ -336,6 +338,16 @@ class Level(tool.State): if plant.canAttack(zombie): plant.setAttack(zombie, self.zombie_groups[i]) break + elif plant.name == c.SPIKEWEED: + can_attack = False + for zombie in self.zombie_groups[i]: + if plant.canAttack(zombie): + can_attack = True + break + if plant.state == c.IDLE and can_attack: + plant.setAttack(self.zombie_groups[i]) + elif plant.state == c.ATTACK and not can_attack: + plant.setIdle() else: if (plant.state == c.IDLE and zombie_len > 0): for zombie in self.zombie_groups[i]: