support sleep state of night plants

zhangcongyu_branch
marblexu 6 years ago
parent 419d10ba8e
commit 75cfbdb436

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -12,11 +12,11 @@ CARD_LIST_NUM = 8
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_SQUASH, c.CARD_SPIKEWEED,
c.CARD_PUFFSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH, c.CARD_SPIKEWEED,
c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM, c.CARD_SUNSHROOM, c.CARD_ICESHROOM]
plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT,
c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER,
c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED,
c.PUFFSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED,
c.JALAPENO, c.SCAREDYSHROOM, c.SUNSHROOM, c.ICESHROOM]
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25, 25, 75]
plant_frozen_time_list = [7500, 7500, 7500, 30000, 50000, 7500, 7500, 7500, 7500, 30000,

@ -122,6 +122,7 @@ class Plant(pg.sprite.Sprite):
self.health = health
self.state = c.IDLE
self.bullet_group = bullet_group
self.can_sleep = False
self.animate_timer = 0
self.animate_interval = 100
self.hit_timer = 0
@ -191,7 +192,8 @@ class Plant(pg.sprite.Sprite):
self.image.set_alpha(192)
def canAttack(self, zombie):
if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right):
if (self.state != c.SLEEP and zombie.state != c.DIE and
self.rect.x <= zombie.rect.right):
return True
return False
@ -202,6 +204,10 @@ class Plant(pg.sprite.Sprite):
self.state = c.IDLE
self.is_attacked = False
def setSleep(self):
self.state = c.SLEEP
self.changeFrames(self.sleep_frames)
def setDamage(self, damage):
self.health -= damage
self.hit_timer = self.current_time
@ -439,13 +445,26 @@ class Chomper(Plant):
self.attack_zombie.kill()
self.setIdle()
class PuffMushroom(Plant):
class PuffShroom(Plant):
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.PUFFSHROOM, c.PLANT_HEALTH, bullet_group)
self.can_sleep = True
self.shoot_timer = 0
def loadImages(self, name, scale):
self.loadFrames(self.frames, name, 1)
self.idle_frames = []
self.sleep_frames = []
idle_name = name
sleep_name = name + 'Sleep'
frame_list = [self.idle_frames, self.sleep_frames]
name_list = [idle_name, sleep_name]
for i, name in enumerate(name_list):
self.loadFrames(frame_list[i], name, 1)
self.frames = self.idle_frames
def attacking(self):
if (self.current_time - self.shoot_timer) > 3000:
@ -638,18 +657,21 @@ class Jalapeno(Plant):
class ScaredyShroom(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
self.can_sleep = True
self.shoot_timer = 0
self.cry_x_range = c.GRID_X_SIZE * 2
def loadImages(self, name, scale):
self.idle_frames = []
self.cry_frames = []
self.sleep_frames = []
idle_name = name
cry_name = name + 'Cry'
sleep_name = name + 'Sleep'
frame_list = [self.idle_frames, self.cry_frames]
name_list = [idle_name, cry_name]
frame_list = [self.idle_frames, self.cry_frames, self.sleep_frames]
name_list = [idle_name, cry_name, sleep_name]
for i, name in enumerate(name_list):
self.loadFrames(frame_list[i], name, 1, c.WHITE)
@ -683,6 +705,7 @@ class ScaredyShroom(Plant):
class SunShroom(Plant):
def __init__(self, x, y, sun_group):
Plant.__init__(self, x, y, c.SUNSHROOM, c.PLANT_HEALTH, None)
self.can_sleep = True
self.animate_interval = 200
self.sun_timer = 0
self.sun_group = sun_group
@ -692,12 +715,14 @@ class SunShroom(Plant):
def loadImages(self, name, scale):
self.idle_frames = []
self.big_frames = []
self.sleep_frames = []
idle_name = name
big_name = name + 'Big'
sleep_name = name + 'Sleep'
frame_list = [self.idle_frames, self.big_frames]
name_list = [idle_name, big_name]
frame_list = [self.idle_frames, self.big_frames, self.sleep_frames]
name_list = [idle_name, big_name, sleep_name]
for i, name in enumerate(name_list):
self.loadFrames(frame_list[i], name, 1, c.WHITE)
@ -722,22 +747,24 @@ class SunShroom(Plant):
class IceShroom(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.ICESHROOM, c.PLANT_HEALTH, None)
self.can_sleep = True
self.orig_pos = (x, y)
self.state = c.ATTACK
self.start_freeze = False
def loadImages(self, name, scale):
self.idle_frames = []
self.snow_frames = []
self.sleep_frames = []
self.trap_frames = []
idle_name = name
snow_name = name + 'Snow'
sleep_name = name + 'Sleep'
trap_name = name + 'Trap'
frame_list = [self.idle_frames, self.snow_frames, self.trap_frames]
name_list = [idle_name, snow_name, trap_name]
scale_list = [1, 1.5, 1]
frame_list = [self.idle_frames, self.snow_frames, self.sleep_frames, self.trap_frames]
name_list = [idle_name, snow_name, sleep_name, trap_name]
scale_list = [1, 1.5, 1, 1]
for i, name in enumerate(name_list):
self.loadFrames(frame_list[i], name, scale_list[i], c.WHITE)
@ -763,8 +790,11 @@ class IceShroom(Plant):
if (self.current_time - self.animate_timer) > 100:
self.frame_index += 1
if self.frame_index >= self.frame_num:
self.setFreeze()
return
if self.state == c.SLEEP:
self.frame_index = 0
else:
self.setFreeze()
return
self.animate_timer = self.current_time
self.image = self.frames[self.frame_index]

@ -73,7 +73,7 @@ THREEPEASHOOTER = 'Threepeater'
REPEATERPEA = 'RepeaterPea'
CHOMPER = 'Chomper'
CHERRY_BOOM_IMAGE = 'Boom'
PUFFMUSHROOM = 'PuffMushroom'
PUFFSHROOM = 'PuffShroom'
POTATOMINE = 'PotatoMine'
SQUASH = 'Squash'
SPIKEWEED = 'Spikeweed'
@ -106,7 +106,7 @@ CARD_CHERRYBOMB = 'card_cherrybomb'
CARD_THREEPEASHOOTER = 'card_threepeashooter'
CARD_REPEATERPEA = 'card_repeaterpea'
CARD_CHOMPER = 'card_chomper'
CARD_PUFFMUSHROOM = 'card_puffmushroom'
CARD_PUFFSHROOM = 'card_puffshroom'
CARD_POTATOMINE = 'card_potatomine'
CARD_SQUASH = 'card_squash'
CARD_SPIKEWEED = 'card_spikeweed'
@ -155,6 +155,7 @@ WALK = 'walk'
DIE = 'die'
CRY = 'cry'
FREEZE = 'freeze'
SLEEP = 'sleep'
#LEVEL STATE
CHOOSE = 'choose'

@ -3,7 +3,8 @@
"PeaNormal":{"x":28, "y":0, "width":28, "height":34},
"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},
"PuffShroom":{"x":0, "y":28, "width":35, "height":38},
"PuffShroomSleep":{"x":1, "y":0, "width":39, "height":65},
"BulletMushRoom":{"x":0, "y":1, "width":55, "height":21},
"PotatoMine":{"x":0, "y":0, "width":75, "height":55},
"Squash":{"x":10, "y":140, "width":80, "height":86},

@ -183,38 +183,41 @@ class Level(tool.State):
x, y = self.hint_rect.x, self.hint_rect.bottom
map_x, map_y = self.map.getMapIndex(x, y)
if self.plant_name == c.SUNFLOWER:
self.plant_groups[map_y].add(plant.SunFlower(x, y, self.sun_group))
new_plant = plant.SunFlower(x, y, self.sun_group)
elif self.plant_name == c.PEASHOOTER:
self.plant_groups[map_y].add(plant.PeaShooter(x, y, self.bullet_groups[map_y]))
new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.SNOWPEASHOOTER:
self.plant_groups[map_y].add(plant.SnowPeaShooter(x, y, self.bullet_groups[map_y]))
new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.WALLNUT:
self.plant_groups[map_y].add(plant.WallNut(x, y))
new_plant = plant.WallNut(x, y)
elif self.plant_name == c.CHERRYBOMB:
self.plant_groups[map_y].add(plant.CherryBomb(x, y))
new_plant = plant.CherryBomb(x, y)
elif self.plant_name == c.THREEPEASHOOTER:
self.plant_groups[map_y].add(plant.ThreePeaShooter(x, y, self.bullet_groups, map_y))
new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y)
elif self.plant_name == c.REPEATERPEA:
self.plant_groups[map_y].add(plant.RepeaterPea(x, y, self.bullet_groups[map_y]))
new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.CHOMPER:
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]))
new_plant = plant.Chomper(x, y)
elif self.plant_name == c.PUFFSHROOM:
new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.POTATOMINE:
self.plant_groups[map_y].add(plant.PotatoMine(x, y))
new_plant = plant.PotatoMine(x, y)
elif self.plant_name == c.SQUASH:
self.plant_groups[map_y].add(plant.Squash(x, y))
new_plant = plant.Squash(x, y)
elif self.plant_name == c.SPIKEWEED:
self.plant_groups[map_y].add(plant.Spikeweed(x, y))
new_plant = plant.Spikeweed(x, y)
elif self.plant_name == c.JALAPENO:
self.plant_groups[map_y].add(plant.Jalapeno(x, y))
new_plant = plant.Jalapeno(x, y)
elif self.plant_name == c.SCAREDYSHROOM:
self.plant_groups[map_y].add(plant.ScaredyShroom(x, y, self.bullet_groups[map_y]))
new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.SUNSHROOM:
self.plant_groups[map_y].add(plant.SunShroom(x, y, self.sun_group))
new_plant = plant.SunShroom(x, y, self.sun_group)
elif self.plant_name == c.ICESHROOM:
self.plant_groups[map_y].add(plant.IceShroom(x, y))
new_plant = plant.IceShroom(x, y)
if new_plant.can_sleep and self.background_type == c.BACKGROUND_DAY:
new_plant.setSleep()
self.plant_groups[map_y].add(new_plant)
self.menubar.decreaseSunValue(self.plant_cost)
self.menubar.setCardFrozenTime(self.plant_name)
self.map.setMapGridType(map_x, map_y, c.MAP_EXIST)
@ -322,7 +325,7 @@ class Level(tool.State):
(plant.name == c.POTATOMINE and not plant.is_init)):
self.boomZombies(plant.rect.centerx, map_y, plant.explode_y_range,
plant.explode_x_range)
elif plant.name == c.ICESHROOM:
elif plant.name == c.ICESHROOM and plant.state != c.SLEEP:
self.freezeZombies(plant)
plant.kill()
@ -400,13 +403,13 @@ class Level(tool.State):
elif (plant.state == c.ATTACK and not can_attack):
plant.setIdle()
if plant.health <= 0:
self.killPlant(plant)
def checkPlants(self):
for i in range(self.map_y_len):
for plant in self.plant_groups[i]:
self.checkPlant(plant, i)
if plant.state != c.SLEEP:
self.checkPlant(plant, i)
if plant.health <= 0:
self.killPlant(plant)
def checkVictory(self):
if len(self.zombie_list) > 0:

Loading…
Cancel
Save