add potatomine
BIN
resources/graphics/Cards/card_potatomine.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_0.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_1.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_2.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_3.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_4.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_5.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_6.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
resources/graphics/Plants/PotatoMine/PotatoMine/PotatoMine_7.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
@ -6,13 +6,13 @@ from .. import constants as c
|
|||||||
|
|
||||||
card_name_list = [c.CARD_SUNFLOWER, c.CARD_PEASHOOTER, c.CARD_SNOWPEASHOOTER, c.CARD_WALLNUT,
|
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_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,
|
plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT,
|
||||||
c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER,
|
c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER,
|
||||||
c.PUFFMUSHROOM]
|
c.PUFFMUSHROOM, c.POTATOMINE]
|
||||||
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0]
|
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25]
|
||||||
plant_frozen_time_list = [0, 0, 0, 0, 0, 0, 0, 0, 8000]
|
plant_frozen_time_list = [5000, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000]
|
||||||
card_list = [0, 1, 2, 3, 4, 8, 7]
|
card_list = [0, 1, 2, 3, 4, 8, 9]
|
||||||
|
|
||||||
class Card():
|
class Card():
|
||||||
def __init__(self, x, y, name_index):
|
def __init__(self, x, y, name_index):
|
||||||
|
|||||||
@ -126,7 +126,7 @@ class Plant(pg.sprite.Sprite):
|
|||||||
self.animate_interval = 100
|
self.animate_interval = 100
|
||||||
self.is_attacked = False
|
self.is_attacked = False
|
||||||
|
|
||||||
def loadFrames(self, frames, name, scale):
|
def loadFrames(self, frames, name, scale, color=c.BLACK):
|
||||||
frame_list = tool.GFX[name]
|
frame_list = tool.GFX[name]
|
||||||
if name in tool.PLANT_RECT:
|
if name in tool.PLANT_RECT:
|
||||||
data = tool.PLANT_RECT[name]
|
data = tool.PLANT_RECT[name]
|
||||||
@ -137,11 +137,24 @@ class Plant(pg.sprite.Sprite):
|
|||||||
width, height = rect.w, rect.h
|
width, height = rect.w, rect.h
|
||||||
|
|
||||||
for frame in frame_list:
|
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):
|
def loadImages(self, name, scale):
|
||||||
self.loadFrames(self.frames, 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):
|
def update(self, game_info):
|
||||||
self.current_time = game_info[c.CURRENT_TIME]
|
self.current_time = game_info[c.CURRENT_TIME]
|
||||||
self.handleState()
|
self.handleState()
|
||||||
@ -185,8 +198,8 @@ class Plant(pg.sprite.Sprite):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def setAttack(self):
|
def setAttack(self):
|
||||||
pass
|
self.state = c.ATTACK
|
||||||
|
|
||||||
def setIdle(self):
|
def setIdle(self):
|
||||||
self.state = c.IDLE
|
self.state = c.IDLE
|
||||||
self.is_attacked = False
|
self.is_attacked = False
|
||||||
@ -252,9 +265,6 @@ class PeaShooter(Plant):
|
|||||||
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
def setAttack(self):
|
|
||||||
self.state = c.ATTACK
|
|
||||||
|
|
||||||
class RepeaterPea(Plant):
|
class RepeaterPea(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.REPEATERPEA, c.PLANT_HEALTH, 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))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
def setAttack(self):
|
|
||||||
self.state = c.ATTACK
|
|
||||||
|
|
||||||
class ThreePeaShooter(Plant):
|
class ThreePeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_groups, map_y):
|
def __init__(self, x, y, bullet_groups, map_y):
|
||||||
Plant.__init__(self, x, y, c.THREEPEASHOOTER, c.PLANT_HEALTH, None)
|
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,
|
self.bullet_groups[tmp_y].add(Bullet(self.rect.right, self.rect.y, dest_y,
|
||||||
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
def setAttack(self):
|
|
||||||
self.state = c.ATTACK
|
|
||||||
|
|
||||||
class SnowPeaShooter(Plant):
|
class SnowPeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
@ -304,9 +308,6 @@ class SnowPeaShooter(Plant):
|
|||||||
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True))
|
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
def setAttack(self):
|
|
||||||
self.state = c.ATTACK
|
|
||||||
|
|
||||||
class WallNut(Plant):
|
class WallNut(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.WALLNUT, c.WALLNUT_HEALTH, None)
|
Plant.__init__(self, x, y, c.WALLNUT, c.WALLNUT_HEALTH, None)
|
||||||
@ -342,6 +343,8 @@ class CherryBomb(Plant):
|
|||||||
self.state = c.ATTACK
|
self.state = c.ATTACK
|
||||||
self.start_boom = False
|
self.start_boom = False
|
||||||
self.bomb_timer = 0
|
self.bomb_timer = 0
|
||||||
|
self.explode_y_range = 1
|
||||||
|
self.explode_x_range = c.GRID_X_SIZE
|
||||||
|
|
||||||
def setBoom(self):
|
def setBoom(self):
|
||||||
frame = tool.GFX[c.CHERRY_BOOM_IMAGE]
|
frame = tool.GFX[c.CHERRY_BOOM_IMAGE]
|
||||||
@ -435,19 +438,6 @@ class Chomper(Plant):
|
|||||||
self.attack_zombie.kill()
|
self.attack_zombie.kill()
|
||||||
self.setIdle()
|
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):
|
class PuffMushroom(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.PUFFMUSHROOM, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.PUFFMUSHROOM, c.PLANT_HEALTH, bullet_group)
|
||||||
@ -468,5 +458,49 @@ class PuffMushroom(Plant):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def setAttack(self):
|
class PotatoMine(Plant):
|
||||||
self.state = c.ATTACK
|
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
|
||||||
@ -348,6 +348,10 @@ class NewspaperZombie(Zombie):
|
|||||||
losthead_attack_name, die_name, boomdie_name]
|
losthead_attack_name, die_name, boomdie_name]
|
||||||
|
|
||||||
for i, name in enumerate(name_list):
|
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
|
self.frames = self.helmet_walk_frames
|
||||||
@ -72,6 +72,7 @@ REPEATERPEA = 'RepeaterPea'
|
|||||||
CHOMPER = 'Chomper'
|
CHOMPER = 'Chomper'
|
||||||
CHERRY_BOOM_IMAGE = 'Boom'
|
CHERRY_BOOM_IMAGE = 'Boom'
|
||||||
PUFFMUSHROOM = 'PuffMushroom'
|
PUFFMUSHROOM = 'PuffMushroom'
|
||||||
|
POTATOMINE = 'PotatoMine'
|
||||||
SPIKEWEED = 'Spikeweed'
|
SPIKEWEED = 'Spikeweed'
|
||||||
|
|
||||||
PLANT_HEALTH = 5
|
PLANT_HEALTH = 5
|
||||||
@ -96,6 +97,7 @@ CARD_THREEPEASHOOTER = 'card_threepeashooter'
|
|||||||
CARD_REPEATERPEA = 'card_repeaterpea'
|
CARD_REPEATERPEA = 'card_repeaterpea'
|
||||||
CARD_CHOMPER = 'card_chomper'
|
CARD_CHOMPER = 'card_chomper'
|
||||||
CARD_PUFFMUSHROOM = 'card_puffmushroom'
|
CARD_PUFFMUSHROOM = 'card_puffmushroom'
|
||||||
|
CARD_POTATOMINE = 'card_potatomine'
|
||||||
CARD_SPIKEWEED = 'card_spikeweed'
|
CARD_SPIKEWEED = 'card_spikeweed'
|
||||||
|
|
||||||
#BULLET INFO
|
#BULLET INFO
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
"PeaIce":{"x":26, "y":0, "width":30, "height":34},
|
"PeaIce":{"x":26, "y":0, "width":30, "height":34},
|
||||||
"Chomper":{"x":0, "y":0, "width":100, "height":114},
|
"Chomper":{"x":0, "y":0, "width":100, "height":114},
|
||||||
"PuffMushroom":{"x":0, "y":28, "width":35, "height":38},
|
"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}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,6 +178,8 @@ class Level(tool.State):
|
|||||||
self.plant_groups[map_y].add(plant.Chomper(x, y))
|
self.plant_groups[map_y].add(plant.Chomper(x, y))
|
||||||
elif self.plant_name == c.PUFFMUSHROOM:
|
elif self.plant_name == c.PUFFMUSHROOM:
|
||||||
self.plant_groups[map_y].add(plant.PuffMushroom(x, y, self.bullet_groups[map_y]))
|
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.decreaseSunValue(self.plant_cost)
|
||||||
self.menubar.setCardFrozenTime(self.plant_name)
|
self.menubar.setCardFrozenTime(self.plant_name)
|
||||||
@ -214,7 +216,11 @@ class Level(tool.State):
|
|||||||
rect = frame_list[0].get_rect()
|
rect = frame_list[0].get_rect()
|
||||||
width, height = rect.w, rect.h
|
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()
|
self.mouse_rect = self.mouse_image.get_rect()
|
||||||
pg.mouse.set_visible(False)
|
pg.mouse.set_visible(False)
|
||||||
self.drag_plant = True
|
self.drag_plant = True
|
||||||
@ -258,19 +264,21 @@ class Level(tool.State):
|
|||||||
if car.dead:
|
if car.dead:
|
||||||
self.cars.remove(car)
|
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):
|
for i in range(self.map_y_len):
|
||||||
if abs(i - map_y) > 1:
|
if abs(i - map_y) > y_range:
|
||||||
continue
|
continue
|
||||||
for zombie in self.zombie_groups[i]:
|
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()
|
zombie.setBoomDie()
|
||||||
|
|
||||||
def killPlant(self, plant):
|
def killPlant(self, plant):
|
||||||
map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom)
|
map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom)
|
||||||
self.map.setMapGridType(map_x, map_y, c.MAP_EMPTY)
|
self.map.setMapGridType(map_x, map_y, c.MAP_EMPTY)
|
||||||
if plant.name == c.CHERRYBOMB:
|
if (plant.name == c.CHERRYBOMB or
|
||||||
self.boomZombies(plant.rect.centerx, map_y)
|
(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()
|
plant.kill()
|
||||||
|
|
||||||
def checkPlant(self, plant, i):
|
def checkPlant(self, plant, i):
|
||||||
@ -297,6 +305,11 @@ class Level(tool.State):
|
|||||||
if plant.canAttack(zombie):
|
if plant.canAttack(zombie):
|
||||||
plant.setAttack(zombie, self.zombie_groups[i])
|
plant.setAttack(zombie, self.zombie_groups[i])
|
||||||
break
|
break
|
||||||
|
elif plant.name == c.POTATOMINE:
|
||||||
|
for zombie in self.zombie_groups[i]:
|
||||||
|
if plant.canAttack(zombie):
|
||||||
|
plant.setAttack()
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
if (plant.state == c.IDLE and zombie_len > 0):
|
if (plant.state == c.IDLE and zombie_len > 0):
|
||||||
for zombie in self.zombie_groups[i]:
|
for zombie in self.zombie_groups[i]:
|
||||||
|
|||||||