add plant ScaredyShroom

zhangcongyu_branch
marblexu 6 years ago
parent cdc3fcaeed
commit 9c1dc63eb9

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -13,14 +13,15 @@ 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_JALAPENO]
c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM]
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.JALAPENO]
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125]
plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000, 8000, 8000, 8000]
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
c.JALAPENO, c.SCAREDYSHROOM]
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25]
plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000,
8000, 8000, 8000, 5000]
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
def getSunValueImage(sun_value):
font = pg.font.SysFont(None, 22)

@ -124,7 +124,7 @@ class Plant(pg.sprite.Sprite):
self.bullet_group = bullet_group
self.animate_timer = 0
self.animate_interval = 100
self.is_attacked = False
self.hit_timer = 0
def loadFrames(self, frames, name, scale, color=c.BLACK):
frame_list = tool.GFX[name]
@ -168,9 +168,6 @@ class Plant(pg.sprite.Sprite):
elif self.state == c.DIGEST:
self.digest()
if self.is_attacked:
self.attacked()
def idling(self):
pass
@ -180,9 +177,6 @@ class Plant(pg.sprite.Sprite):
def digest(self):
pass
def attacked(self):
pass
def animation(self):
if (self.current_time - self.animate_timer) > self.animate_interval:
self.frame_index += 1
@ -191,9 +185,13 @@ class Plant(pg.sprite.Sprite):
self.animate_timer = self.current_time
self.image = self.frames[self.frame_index]
if(self.current_time - self.hit_timer) >= 200:
self.image.set_alpha(255)
else:
self.image.set_alpha(192)
def canAttack(self, zombie):
if (self.rect.x <= zombie.rect.right):
if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right):
return True
return False
@ -204,11 +202,9 @@ class Plant(pg.sprite.Sprite):
self.state = c.IDLE
self.is_attacked = False
def setAttacked(self):
self.is_attacked = True
def setDamage(self, damage):
self.health -= damage
self.hit_timer = self.current_time
def getPosition(self):
return self.rect.centerx, self.rect.bottom
@ -328,16 +324,12 @@ class WallNut(Plant):
self.loadFrames(self.cracked1_frames, cracked1_frames_name, 1)
self.loadFrames(self.cracked2_frames, cracked2_frames_name, 1)
def attacked(self):
def idling(self):
if not self.cracked1 and self.health <= c.WALLNUT_CRACKED1_HEALTH:
self.frames = self.cracked1_frames
self.frame_num = len(self.frames)
self.frame_index = 0
self.changeFrames(self.cracked1_frames)
self.cracked1 = True
elif not self.cracked2 and self.health <= c.WALLNUT_CRACKED2_HEALTH:
self.frames = self.cracked2_frames
self.frame_num = len(self.frames)
self.frame_index = 0
self.changeFrames(self.cracked2_frames)
self.cracked2 = True
class CherryBomb(Plant):
@ -451,7 +443,7 @@ class PuffMushroom(Plant):
def attacking(self):
if (self.current_time - self.shoot_timer) > 3000:
self.bullet_group.add(Bullet(self.rect.right, self.rect.y, self.rect.y,
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 10, self.rect.y + 10,
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time
@ -583,7 +575,6 @@ class Spikeweed(Plant):
return False
def setAttack(self, zombie_group):
print('spikeweed attack')
self.zombie_group = zombie_group
self.animate_interval = 50
self.state = c.ATTACK
@ -631,4 +622,49 @@ class Jalapeno(Plant):
self.setExplode()
return
self.animate_timer = self.current_time
self.image = self.frames[self.frame_index]
self.image = self.frames[self.frame_index]
class ScaredyShroom(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
self.shoot_timer = 0
self.cry_x_range = c.GRID_X_SIZE * 2
def loadImages(self, name, scale):
self.idle_frames = []
self.cry_frames = []
idle_name = name
cry_name = name + 'Cry'
frame_list = [self.idle_frames, self.cry_frames]
name_list = [idle_name, cry_name]
for i, name in enumerate(name_list):
self.loadFrames(frame_list[i], name, 1, c.WHITE)
self.frames = self.idle_frames
def needCry(self, zombie):
if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right and
self.rect.x + self.cry_x_range > zombie.rect.x):
return True
return False
def setCry(self):
self.state = c.CRY
self.changeFrames(self.cry_frames)
def setAttack(self):
self.state = c.ATTACK
self.changeFrames(self.idle_frames)
def setIdle(self):
self.state = c.IDLE
self.changeFrames(self.idle_frames)
def attacking(self):
if (self.current_time - self.shoot_timer) > 2000:
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 40, self.rect.y + 40,
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time

@ -78,6 +78,7 @@ POTATOMINE = 'PotatoMine'
SQUASH = 'Squash'
SPIKEWEED = 'Spikeweed'
JALAPENO = 'Jalapeno'
SCAREDYSHROOM = 'ScaredyShroom'
PLANT_HEALTH = 5
WALLNUT_HEALTH = 30
@ -105,6 +106,7 @@ CARD_POTATOMINE = 'card_potatomine'
CARD_SQUASH = 'card_squash'
CARD_SPIKEWEED = 'card_spikeweed'
CARD_JALAPENO = 'card_jalapeno'
CARD_SCAREDYSHROOM = 'card_scaredyshroom'
#BULLET INFO
BULLET_PEA = 'PeaNormal'
@ -143,6 +145,7 @@ ATTACKED = 'attacked'
DIGEST = 'digest'
WALK = 'walk'
DIE = 'die'
CRY = 'cry'
#LEVEL STATE
CHOOSE = 'choose'

@ -204,6 +204,8 @@ class Level(tool.State):
self.plant_groups[map_y].add(plant.Spikeweed(x, y))
elif self.plant_name == c.JALAPENO:
self.plant_groups[map_y].add(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]))
self.menubar.decreaseSunValue(self.plant_cost)
self.menubar.setCardFrozenTime(self.plant_name)
@ -241,7 +243,8 @@ class Level(tool.State):
width, height = rect.w, rect.h
if (plant_name == c.POTATOMINE or plant_name == c.SQUASH or
plant_name == c.SPIKEWEED or plant_name == c.JALAPENO):
plant_name == c.SPIKEWEED or plant_name == c.JALAPENO or
plant_name == c.SCAREDYSHROOM):
color = c.WHITE
else:
color = c.BLACK
@ -276,7 +279,6 @@ class Level(tool.State):
plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func)
if plant and plant.name != c.SPIKEWEED and zombie.state == c.WALK:
zombie.setAttack(plant)
plant.setAttacked()
def checkCarCollisions(self):
collided_func = pg.sprite.collide_circle_ratio(0.8)
@ -351,13 +353,33 @@ class Level(tool.State):
plant.setAttack(self.zombie_groups[i])
elif plant.state == c.ATTACK and not can_attack:
plant.setIdle()
elif plant.name == c.SCAREDYSHROOM:
need_cry = False
can_attack = False
for zombie in self.zombie_groups[i]:
if plant.needCry(zombie):
need_cry = True
break
elif plant.canAttack(zombie):
can_attack = True
if need_cry:
if plant.state != c.CRY:
plant.setCry()
elif can_attack:
if plant.state != c.ATTACK:
plant.setAttack()
elif plant.state != c.IDLE:
plant.setIdle()
else:
can_attack = False
if (plant.state == c.IDLE and zombie_len > 0):
for zombie in self.zombie_groups[i]:
if plant.canAttack(zombie):
plant.setAttack()
can_attack = True
break
elif (plant.state == c.ATTACK and zombie_len == 0):
if plant.state == c.IDLE and can_attack:
plant.setAttack()
elif (plant.state == c.ATTACK and not can_attack):
plant.setIdle()
if plant.health <= 0:

Loading…
Cancel
Save