diff --git a/resources/graphics/Cards/card_potatomine.png b/resources/graphics/Cards/card_potatomine.png new file mode 100644 index 0000000..192fe4b Binary files /dev/null and b/resources/graphics/Cards/card_potatomine.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_0.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_0.png new file mode 100644 index 0000000..96efb6e Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_0.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_1.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_1.png new file mode 100644 index 0000000..b8c37ee Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_1.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_2.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_2.png new file mode 100644 index 0000000..9e741e3 Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_2.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_3.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_3.png new file mode 100644 index 0000000..be35b0b Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_3.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_4.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_4.png new file mode 100644 index 0000000..23e4eff Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_4.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_5.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_5.png new file mode 100644 index 0000000..b8c37ee Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_5.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_6.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_6.png new file mode 100644 index 0000000..9e741e3 Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_6.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_7.png b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_7.png new file mode 100644 index 0000000..be35b0b Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_7.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMineExplode/PotatoMineExplode_0.png b/resources/graphics/Plants/PotatoMine/PotatoMineExplode/PotatoMineExplode_0.png new file mode 100644 index 0000000..f12ca5f Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMineExplode/PotatoMineExplode_0.png differ diff --git a/resources/graphics/Plants/PotatoMine/PotatoMineInit/PotatoMineInit_0.png b/resources/graphics/Plants/PotatoMine/PotatoMineInit/PotatoMineInit_0.png new file mode 100644 index 0000000..72c1fca Binary files /dev/null and b/resources/graphics/Plants/PotatoMine/PotatoMineInit/PotatoMineInit_0.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index 21222ce..0e41981 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_PUFFMUSHROOM, c.CARD_POTATOMINE] plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT, c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER, - c.PUFFMUSHROOM] -plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0] -plant_frozen_time_list = [0, 0, 0, 0, 0, 0, 0, 0, 8000] -card_list = [0, 1, 2, 3, 4, 8, 7] + 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] class Card(): def __init__(self, x, y, name_index): diff --git a/source/component/plant.py b/source/component/plant.py index 6498538..bd5a27b 100644 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -126,7 +126,7 @@ class Plant(pg.sprite.Sprite): self.animate_interval = 100 self.is_attacked = False - def loadFrames(self, frames, name, scale): + def loadFrames(self, frames, name, scale, color=c.BLACK): frame_list = tool.GFX[name] if name in tool.PLANT_RECT: data = tool.PLANT_RECT[name] @@ -137,11 +137,24 @@ class Plant(pg.sprite.Sprite): width, height = rect.w, rect.h for frame in frame_list: - frames.append(tool.get_image(frame, x, y, width, height, c.BLACK, scale)) + frames.append(tool.get_image(frame, x, y, width, height, color, scale)) def loadImages(self, name, scale): self.loadFrames(self.frames, name, scale) + def changeFrames(self, frames): + '''change image frames and modify rect position''' + self.frames = frames + self.frame_num = len(self.frames) + self.frame_index = 0 + + bottom = self.rect.bottom + x = self.rect.x + self.image = self.frames[self.frame_index] + self.rect = self.image.get_rect() + self.rect.bottom = bottom + self.rect.x = x + def update(self, game_info): self.current_time = game_info[c.CURRENT_TIME] self.handleState() @@ -185,8 +198,8 @@ class Plant(pg.sprite.Sprite): return False def setAttack(self): - pass - + self.state = c.ATTACK + def setIdle(self): self.state = c.IDLE self.is_attacked = False @@ -252,9 +265,6 @@ class PeaShooter(Plant): c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) self.shoot_timer = self.current_time - def setAttack(self): - self.state = c.ATTACK - class RepeaterPea(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.REPEATERPEA, c.PLANT_HEALTH, bullet_group) @@ -268,9 +278,6 @@ class RepeaterPea(Plant): c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) self.shoot_timer = self.current_time - def setAttack(self): - self.state = c.ATTACK - class ThreePeaShooter(Plant): def __init__(self, x, y, bullet_groups, map_y): Plant.__init__(self, x, y, c.THREEPEASHOOTER, c.PLANT_HEALTH, None) @@ -289,9 +296,6 @@ class ThreePeaShooter(Plant): self.bullet_groups[tmp_y].add(Bullet(self.rect.right, self.rect.y, dest_y, c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) self.shoot_timer = self.current_time - - def setAttack(self): - self.state = c.ATTACK class SnowPeaShooter(Plant): def __init__(self, x, y, bullet_group): @@ -304,9 +308,6 @@ class SnowPeaShooter(Plant): c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True)) self.shoot_timer = self.current_time - def setAttack(self): - self.state = c.ATTACK - class WallNut(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.WALLNUT, c.WALLNUT_HEALTH, None) @@ -342,6 +343,8 @@ class CherryBomb(Plant): self.state = c.ATTACK self.start_boom = False self.bomb_timer = 0 + self.explode_y_range = 1 + self.explode_x_range = c.GRID_X_SIZE def setBoom(self): frame = tool.GFX[c.CHERRY_BOOM_IMAGE] @@ -435,19 +438,6 @@ class Chomper(Plant): self.attack_zombie.kill() self.setIdle() - def changeFrames(self, frames): - '''change image frames and modify rect position''' - self.frames = frames - self.frame_num = len(self.frames) - self.frame_index = 0 - - bottom = self.rect.bottom - x = self.rect.x - self.image = self.frames[self.frame_index] - self.rect = self.image.get_rect() - self.rect.bottom = bottom - self.rect.x = x - class PuffMushroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.PUFFMUSHROOM, c.PLANT_HEALTH, bullet_group) @@ -468,5 +458,49 @@ class PuffMushroom(Plant): return True return False - def setAttack(self): - self.state = c.ATTACK \ No newline at end of file +class PotatoMine(Plant): + def __init__(self, x, y): + Plant.__init__(self, x, y, c.POTATOMINE, c.PLANT_HEALTH, None) + self.animate_interval = 300 + self.is_init = True + self.init_timer = 0 + self.bomb_timer = 0 + self.explode_y_range = 0 + self.explode_x_range = c.GRID_X_SIZE//2 + + def loadImages(self, name, scale): + self.init_frames = [] + self.idle_frames = [] + self.explode_frames = [] + + init_name = name + 'Init' + idle_name = name + explode_name = name + 'Explode' + + frame_list = [self.init_frames, self.idle_frames, self.explode_frames] + name_list = [init_name, idle_name, explode_name] + + for i, name in enumerate(name_list): + self.loadFrames(frame_list[i], name, 1, c.WHITE) + + self.frames = self.init_frames + + def idling(self): + if self.is_init: + if self.init_timer == 0: + self.init_timer = self.current_time + elif (self.current_time - self.init_timer) > 15000: + self.changeFrames(self.idle_frames) + self.is_init = False + + def canAttack(self, zombie): + if not self.is_init and abs(zombie.rect.x - self.rect.x) <= self.explode_x_range: + return True + return False + + def attacking(self): + if self.bomb_timer == 0: + 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 diff --git a/source/component/zombie.py b/source/component/zombie.py index c89f6cc..75a2842 100644 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -348,6 +348,10 @@ class NewspaperZombie(Zombie): losthead_attack_name, die_name, boomdie_name] for i, name in enumerate(name_list): - self.loadFrames(frame_list[i], name, tool.ZOMBIE_RECT[name]['x'], c.WHITE) + if name == c.BOOMDIE: + color = c.BLACK + else: + color = c.WHITE + self.loadFrames(frame_list[i], name, tool.ZOMBIE_RECT[name]['x'], color) self.frames = self.helmet_walk_frames \ No newline at end of file diff --git a/source/constants.py b/source/constants.py index b43e5fe..44f0cfa 100644 --- a/source/constants.py +++ b/source/constants.py @@ -72,6 +72,7 @@ REPEATERPEA = 'RepeaterPea' CHOMPER = 'Chomper' CHERRY_BOOM_IMAGE = 'Boom' PUFFMUSHROOM = 'PuffMushroom' +POTATOMINE = 'PotatoMine' SPIKEWEED = 'Spikeweed' PLANT_HEALTH = 5 @@ -96,6 +97,7 @@ CARD_THREEPEASHOOTER = 'card_threepeashooter' CARD_REPEATERPEA = 'card_repeaterpea' CARD_CHOMPER = 'card_chomper' CARD_PUFFMUSHROOM = 'card_puffmushroom' +CARD_POTATOMINE = 'card_potatomine' CARD_SPIKEWEED = 'card_spikeweed' #BULLET INFO diff --git a/source/data/entity/plant.json b/source/data/entity/plant.json index 94222aa..5d5c4c3 100644 --- a/source/data/entity/plant.json +++ b/source/data/entity/plant.json @@ -4,6 +4,7 @@ "PeaIce":{"x":26, "y":0, "width":30, "height":34}, "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} + "BulletMushRoom":{"x":0, "y":1, "width":55, "height":21}, + "PotatoMine":{"x":0, "y":0, "width":75, "height":55} } } \ No newline at end of file diff --git a/source/state/level.py b/source/state/level.py index 65c216a..79aa928 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -178,6 +178,8 @@ class Level(tool.State): self.plant_groups[map_y].add(plant.Chomper(x, y)) elif self.plant_name == c.PUFFMUSHROOM: 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)) self.menubar.decreaseSunValue(self.plant_cost) self.menubar.setCardFrozenTime(self.plant_name) @@ -214,7 +216,11 @@ class Level(tool.State): rect = frame_list[0].get_rect() width, height = rect.w, rect.h - self.mouse_image = tool.get_image(frame_list[0], x, y, width, height, c.BLACK, 1) + if plant_name == c.POTATOMINE: + color = c.WHITE + else: + color = c.BLACK + self.mouse_image = tool.get_image(frame_list[0], x, y, width, height, color, 1) self.mouse_rect = self.mouse_image.get_rect() pg.mouse.set_visible(False) self.drag_plant = True @@ -258,19 +264,21 @@ class Level(tool.State): if car.dead: self.cars.remove(car) - def boomZombies(self, x, map_y): + def boomZombies(self, x, map_y, y_range, x_range): for i in range(self.map_y_len): - if abs(i - map_y) > 1: + if abs(i - map_y) > y_range: continue for zombie in self.zombie_groups[i]: - if abs(zombie.rect.x - x) <= c.GRID_X_SIZE: + if abs(zombie.rect.x - x) <= x_range: zombie.setBoomDie() def killPlant(self, plant): map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) self.map.setMapGridType(map_x, map_y, c.MAP_EMPTY) - if plant.name == c.CHERRYBOMB: - self.boomZombies(plant.rect.centerx, map_y) + if (plant.name == c.CHERRYBOMB or + (plant.name == c.POTATOMINE and not plant.is_init)): + self.boomZombies(plant.rect.centerx, map_y, plant.explode_y_range, + plant.explode_x_range) plant.kill() def checkPlant(self, plant, i): @@ -297,6 +305,11 @@ class Level(tool.State): if plant.canAttack(zombie): plant.setAttack(zombie, self.zombie_groups[i]) break + elif plant.name == c.POTATOMINE: + for zombie in self.zombie_groups[i]: + if plant.canAttack(zombie): + plant.setAttack() + break else: if (plant.state == c.IDLE and zombie_len > 0): for zombie in self.zombie_groups[i]: