diff --git a/resources/graphics/Cards/card_squash.png b/resources/graphics/Cards/card_squash.png new file mode 100644 index 0000000..7474a8b Binary files /dev/null and b/resources/graphics/Cards/card_squash.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_0.png b/resources/graphics/Plants/Squash/Squash/Squash_0.png new file mode 100644 index 0000000..b6284ae Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_0.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_1.png b/resources/graphics/Plants/Squash/Squash/Squash_1.png new file mode 100644 index 0000000..c5346a1 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_1.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_10.png b/resources/graphics/Plants/Squash/Squash/Squash_10.png new file mode 100644 index 0000000..d3881dc Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_10.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_11.png b/resources/graphics/Plants/Squash/Squash/Squash_11.png new file mode 100644 index 0000000..e6d9103 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_11.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_12.png b/resources/graphics/Plants/Squash/Squash/Squash_12.png new file mode 100644 index 0000000..854f27f Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_12.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_13.png b/resources/graphics/Plants/Squash/Squash/Squash_13.png new file mode 100644 index 0000000..3abfc6c Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_13.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_14.png b/resources/graphics/Plants/Squash/Squash/Squash_14.png new file mode 100644 index 0000000..ad3e95e Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_14.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_15.png b/resources/graphics/Plants/Squash/Squash/Squash_15.png new file mode 100644 index 0000000..81327a6 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_15.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_16.png b/resources/graphics/Plants/Squash/Squash/Squash_16.png new file mode 100644 index 0000000..85c87e0 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_16.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_2.png b/resources/graphics/Plants/Squash/Squash/Squash_2.png new file mode 100644 index 0000000..99328cd Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_2.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_3.png b/resources/graphics/Plants/Squash/Squash/Squash_3.png new file mode 100644 index 0000000..f797bc9 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_3.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_4.png b/resources/graphics/Plants/Squash/Squash/Squash_4.png new file mode 100644 index 0000000..d2975c2 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_4.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_5.png b/resources/graphics/Plants/Squash/Squash/Squash_5.png new file mode 100644 index 0000000..6ffc0c3 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_5.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_6.png b/resources/graphics/Plants/Squash/Squash/Squash_6.png new file mode 100644 index 0000000..818cc5f Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_6.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_7.png b/resources/graphics/Plants/Squash/Squash/Squash_7.png new file mode 100644 index 0000000..3a19803 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_7.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_8.png b/resources/graphics/Plants/Squash/Squash/Squash_8.png new file mode 100644 index 0000000..8a0291f Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_8.png differ diff --git a/resources/graphics/Plants/Squash/Squash/Squash_9.png b/resources/graphics/Plants/Squash/Squash/Squash_9.png new file mode 100644 index 0000000..395cb96 Binary files /dev/null and b/resources/graphics/Plants/Squash/Squash/Squash_9.png differ diff --git a/resources/graphics/Plants/Squash/SquashAim/SquashAim_0.png b/resources/graphics/Plants/Squash/SquashAim/SquashAim_0.png new file mode 100644 index 0000000..bf05208 Binary files /dev/null and b/resources/graphics/Plants/Squash/SquashAim/SquashAim_0.png differ diff --git a/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_0.png b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_0.png new file mode 100644 index 0000000..6997d2a Binary files /dev/null and b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_0.png differ diff --git a/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_1.png b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_1.png new file mode 100644 index 0000000..31fe4c7 Binary files /dev/null and b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_1.png differ diff --git a/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_2.png b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_2.png new file mode 100644 index 0000000..02bef9d Binary files /dev/null and b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_2.png differ diff --git a/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_3.png b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_3.png new file mode 100644 index 0000000..41a93d8 Binary files /dev/null and b/resources/graphics/Plants/Squash/SquashAttack/SquashAttack_3.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index 0e41981..b4f963a 100644 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -6,13 +6,13 @@ from .. import constants as c 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_PUFFMUSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH] plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT, c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER, - c.PUFFMUSHROOM, c.POTATOMINE] -plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25] -plant_frozen_time_list = [5000, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000] -card_list = [0, 1, 2, 3, 4, 8, 9] + 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] +card_list = [0, 1, 8, 3, 4, 10, 9] class Card(): def __init__(self, x, y, name_index): diff --git a/source/component/plant.py b/source/component/plant.py index bd5a27b..3f1a87a 100644 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -210,6 +210,9 @@ class Plant(pg.sprite.Sprite): def setDamage(self, damage): self.health -= damage + def getPosition(self): + return self.rect.centerx, self.rect.bottom + class Sun(Plant): def __init__(self, x, y, dest_x, dest_y): Plant.__init__(self, x, y, c.SUN, 0, None, 0.9) @@ -503,4 +506,58 @@ class PotatoMine(Plant): self.bomb_timer = self.current_time self.changeFrames(self.explode_frames) elif (self.current_time - self.bomb_timer) > 500: - self.health = 0 \ No newline at end of file + self.health = 0 + +class Squash(Plant): + def __init__(self, x, y): + Plant.__init__(self, x, y, c.SQUASH, c.PLANT_HEALTH, None) + self.orig_pos = (x, y) + self.aim_timer = 0 + self.squashing = False + + def loadImages(self, name, scale): + self.idle_frames = [] + self.aim_frames = [] + self.attack_frames = [] + + idle_name = name + aim_name = name + 'Aim' + attack_name = name + 'Attack' + + frame_list = [self.idle_frames, self.aim_frames, self.attack_frames] + name_list = [idle_name, aim_name, attack_name] + + for i, name in enumerate(name_list): + self.loadFrames(frame_list[i], name, 1, c.WHITE) + + self.frames = self.idle_frames + + def canAttack(self, zombie): + if (self.state == c.IDLE and self.rect.x <= zombie.rect.right and + (self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)): + return True + return False + + def setAttack(self, zombie, zombie_group): + self.attack_zombie = zombie + self.zombie_group = zombie_group + self.state = c.ATTACK + + def attacking(self): + if self.squashing: + if self.frame_index == 2: + self.zombie_group.remove(self.attack_zombie) + if (self.frame_index + 1) == self.frame_num: + self.attack_zombie.kill() + self.health = 0 + elif self.aim_timer == 0: + self.aim_timer = self.current_time + self.changeFrames(self.aim_frames) + elif (self.current_time - self.aim_timer) > 1000: + self.changeFrames(self.attack_frames) + self.rect.centerx = self.attack_zombie.rect.centerx + self.squashing = True + self.animate_interval = 300 + + def getPosition(self): + return self.orig_pos \ No newline at end of file diff --git a/source/component/zombie.py b/source/component/zombie.py index 75a2842..3718946 100644 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -33,7 +33,7 @@ class Zombie(pg.sprite.Sprite): self.animate_interval = 150 self.ice_slow_ratio = 1 self.ice_slow_timer = 0 - self.speed_ratio = 1 + self.speed = 1 def loadFrames(self, frames, name, image_x, colorkey=c.BLACK): frame_list = tool.GFX[name] @@ -68,11 +68,11 @@ class Zombie(pg.sprite.Sprite): self.changeFrames(self.walk_frames) self.helmet = False if self.name == c.NEWSPAPER_ZOMBIE: - self.speed_ratio = 0.5 + self.speed = 2 if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): self.walk_timer = self.current_time - self.rect.x -= 1 + self.rect.x -= self.speed def attacking(self): if self.health <= 0: @@ -122,7 +122,7 @@ class Zombie(pg.sprite.Sprite): self.image = self.frames[self.frame_index] def getTimeRatio(self): - return self.ice_slow_ratio * self.speed_ratio + return self.ice_slow_ratio def setIceSlow(self): '''when get a ice bullet damage, slow the attack or walk speed of the zombie''' diff --git a/source/constants.py b/source/constants.py index 44f0cfa..850dab7 100644 --- a/source/constants.py +++ b/source/constants.py @@ -73,6 +73,7 @@ CHOMPER = 'Chomper' CHERRY_BOOM_IMAGE = 'Boom' PUFFMUSHROOM = 'PuffMushroom' POTATOMINE = 'PotatoMine' +SQUASH = 'Squash' SPIKEWEED = 'Spikeweed' PLANT_HEALTH = 5 @@ -98,6 +99,7 @@ CARD_REPEATERPEA = 'card_repeaterpea' CARD_CHOMPER = 'card_chomper' CARD_PUFFMUSHROOM = 'card_puffmushroom' CARD_POTATOMINE = 'card_potatomine' +CARD_SQUASH = 'card_squash' CARD_SPIKEWEED = 'card_spikeweed' #BULLET INFO diff --git a/source/data/entity/plant.json b/source/data/entity/plant.json index 5d5c4c3..e583099 100644 --- a/source/data/entity/plant.json +++ b/source/data/entity/plant.json @@ -5,6 +5,8 @@ "Chomper":{"x":0, "y":0, "width":100, "height":114}, "PuffMushroom":{"x":0, "y":28, "width":35, "height":38}, "BulletMushRoom":{"x":0, "y":1, "width":55, "height":21}, - "PotatoMine":{"x":0, "y":0, "width":75, "height":55} + "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} } } \ No newline at end of file diff --git a/source/state/level.py b/source/state/level.py index 79aa928..855484c 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -180,6 +180,8 @@ class Level(tool.State): self.plant_groups[map_y].add(plant.PuffMushroom(x, y, self.bullet_groups[map_y])) elif self.plant_name == c.POTATOMINE: 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)) self.menubar.decreaseSunValue(self.plant_cost) self.menubar.setCardFrozenTime(self.plant_name) @@ -216,7 +218,7 @@ class Level(tool.State): rect = frame_list[0].get_rect() width, height = rect.w, rect.h - if plant_name == c.POTATOMINE: + if plant_name == c.POTATOMINE or plant_name == c.SQUASH: color = c.WHITE else: color = c.BLACK @@ -273,7 +275,8 @@ class Level(tool.State): zombie.setBoomDie() def killPlant(self, plant): - map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) + x, y = plant.getPosition() + map_x, map_y = self.map.getMapIndex(x, y) self.map.setMapGridType(map_x, map_y, c.MAP_EMPTY) if (plant.name == c.CHERRYBOMB or (plant.name == c.POTATOMINE and not plant.is_init)): @@ -310,6 +313,11 @@ class Level(tool.State): if plant.canAttack(zombie): plant.setAttack() break + elif plant.name == c.SQUASH: + for zombie in self.zombie_groups[i]: + if plant.canAttack(zombie): + plant.setAttack(zombie, self.zombie_groups[i]) + break else: if (plant.state == c.IDLE and zombie_len > 0): for zombie in self.zombie_groups[i]: