add plant squash
BIN
resources/graphics/Cards/card_squash.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_0.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_1.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_10.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_11.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_12.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_13.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_14.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_15.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_16.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_2.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_3.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_4.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_5.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_6.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_7.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_8.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
resources/graphics/Plants/Squash/Squash/Squash_9.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
resources/graphics/Plants/Squash/SquashAim/SquashAim_0.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
resources/graphics/Plants/Squash/SquashAttack/SquashAttack_0.png
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
resources/graphics/Plants/Squash/SquashAttack/SquashAttack_1.png
Normal file
|
After Width: | Height: | Size: 6.2 KiB |
BIN
resources/graphics/Plants/Squash/SquashAttack/SquashAttack_2.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
resources/graphics/Plants/Squash/SquashAttack/SquashAttack_3.png
Normal file
|
After Width: | Height: | Size: 4.5 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_POTATOMINE]
|
c.CARD_PUFFMUSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH]
|
||||||
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.POTATOMINE]
|
c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH]
|
||||||
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25]
|
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50]
|
||||||
plant_frozen_time_list = [5000, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000]
|
plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000, 8000]
|
||||||
card_list = [0, 1, 2, 3, 4, 8, 9]
|
card_list = [0, 1, 8, 3, 4, 10, 9]
|
||||||
|
|
||||||
class Card():
|
class Card():
|
||||||
def __init__(self, x, y, name_index):
|
def __init__(self, x, y, name_index):
|
||||||
|
|||||||
@ -210,6 +210,9 @@ class Plant(pg.sprite.Sprite):
|
|||||||
def setDamage(self, damage):
|
def setDamage(self, damage):
|
||||||
self.health -= damage
|
self.health -= damage
|
||||||
|
|
||||||
|
def getPosition(self):
|
||||||
|
return self.rect.centerx, self.rect.bottom
|
||||||
|
|
||||||
class Sun(Plant):
|
class Sun(Plant):
|
||||||
def __init__(self, x, y, dest_x, dest_y):
|
def __init__(self, x, y, dest_x, dest_y):
|
||||||
Plant.__init__(self, x, y, c.SUN, 0, None, 0.9)
|
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.bomb_timer = self.current_time
|
||||||
self.changeFrames(self.explode_frames)
|
self.changeFrames(self.explode_frames)
|
||||||
elif (self.current_time - self.bomb_timer) > 500:
|
elif (self.current_time - self.bomb_timer) > 500:
|
||||||
self.health = 0
|
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
|
||||||
@ -33,7 +33,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.animate_interval = 150
|
self.animate_interval = 150
|
||||||
self.ice_slow_ratio = 1
|
self.ice_slow_ratio = 1
|
||||||
self.ice_slow_timer = 0
|
self.ice_slow_timer = 0
|
||||||
self.speed_ratio = 1
|
self.speed = 1
|
||||||
|
|
||||||
def loadFrames(self, frames, name, image_x, colorkey=c.BLACK):
|
def loadFrames(self, frames, name, image_x, colorkey=c.BLACK):
|
||||||
frame_list = tool.GFX[name]
|
frame_list = tool.GFX[name]
|
||||||
@ -68,11 +68,11 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.changeFrames(self.walk_frames)
|
self.changeFrames(self.walk_frames)
|
||||||
self.helmet = False
|
self.helmet = False
|
||||||
if self.name == c.NEWSPAPER_ZOMBIE:
|
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()):
|
if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()):
|
||||||
self.walk_timer = self.current_time
|
self.walk_timer = self.current_time
|
||||||
self.rect.x -= 1
|
self.rect.x -= self.speed
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if self.health <= 0:
|
if self.health <= 0:
|
||||||
@ -122,7 +122,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.image = self.frames[self.frame_index]
|
self.image = self.frames[self.frame_index]
|
||||||
|
|
||||||
def getTimeRatio(self):
|
def getTimeRatio(self):
|
||||||
return self.ice_slow_ratio * self.speed_ratio
|
return self.ice_slow_ratio
|
||||||
|
|
||||||
def setIceSlow(self):
|
def setIceSlow(self):
|
||||||
'''when get a ice bullet damage, slow the attack or walk speed of the zombie'''
|
'''when get a ice bullet damage, slow the attack or walk speed of the zombie'''
|
||||||
|
|||||||
@ -73,6 +73,7 @@ CHOMPER = 'Chomper'
|
|||||||
CHERRY_BOOM_IMAGE = 'Boom'
|
CHERRY_BOOM_IMAGE = 'Boom'
|
||||||
PUFFMUSHROOM = 'PuffMushroom'
|
PUFFMUSHROOM = 'PuffMushroom'
|
||||||
POTATOMINE = 'PotatoMine'
|
POTATOMINE = 'PotatoMine'
|
||||||
|
SQUASH = 'Squash'
|
||||||
SPIKEWEED = 'Spikeweed'
|
SPIKEWEED = 'Spikeweed'
|
||||||
|
|
||||||
PLANT_HEALTH = 5
|
PLANT_HEALTH = 5
|
||||||
@ -98,6 +99,7 @@ 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_POTATOMINE = 'card_potatomine'
|
||||||
|
CARD_SQUASH = 'card_squash'
|
||||||
CARD_SPIKEWEED = 'card_spikeweed'
|
CARD_SPIKEWEED = 'card_spikeweed'
|
||||||
|
|
||||||
#BULLET INFO
|
#BULLET INFO
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
"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}
|
"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}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,6 +180,8 @@ class Level(tool.State):
|
|||||||
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:
|
elif self.plant_name == c.POTATOMINE:
|
||||||
self.plant_groups[map_y].add(plant.PotatoMine(x, y))
|
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.decreaseSunValue(self.plant_cost)
|
||||||
self.menubar.setCardFrozenTime(self.plant_name)
|
self.menubar.setCardFrozenTime(self.plant_name)
|
||||||
@ -216,7 +218,7 @@ 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
|
||||||
|
|
||||||
if plant_name == c.POTATOMINE:
|
if plant_name == c.POTATOMINE or plant_name == c.SQUASH:
|
||||||
color = c.WHITE
|
color = c.WHITE
|
||||||
else:
|
else:
|
||||||
color = c.BLACK
|
color = c.BLACK
|
||||||
@ -273,7 +275,8 @@ class Level(tool.State):
|
|||||||
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)
|
x, y = plant.getPosition()
|
||||||
|
map_x, map_y = self.map.getMapIndex(x, y)
|
||||||
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 or
|
if (plant.name == c.CHERRYBOMB or
|
||||||
(plant.name == c.POTATOMINE and not plant.is_init)):
|
(plant.name == c.POTATOMINE and not plant.is_init)):
|
||||||
@ -310,6 +313,11 @@ class Level(tool.State):
|
|||||||
if plant.canAttack(zombie):
|
if plant.canAttack(zombie):
|
||||||
plant.setAttack()
|
plant.setAttack()
|
||||||
break
|
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:
|
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]:
|
||||||
|
|||||||