add plant squash

zhangcongyu_branch
marblexu 6 years ago
parent 05afc2fbae
commit b1ecaa1110

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

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,
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):

@ -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
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.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'''

@ -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

@ -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}
}
}

@ -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]:

Loading…
Cancel
Save