add plant ScaredyShroom
BIN
resources/graphics/Cards/card_scaredyshroom.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
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,
|
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_SQUASH, c.CARD_SPIKEWEED,
|
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,
|
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.SQUASH, c.SPIKEWEED,
|
c.PUFFMUSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED,
|
||||||
c.JALAPENO]
|
c.JALAPENO, c.SCAREDYSHROOM]
|
||||||
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125]
|
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]
|
plant_frozen_time_list = [0, 5000, 5000, 10000, 5000, 5000, 5000, 5000, 8000, 8000,
|
||||||
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
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):
|
def getSunValueImage(sun_value):
|
||||||
font = pg.font.SysFont(None, 22)
|
font = pg.font.SysFont(None, 22)
|
||||||
|
|||||||
@ -124,7 +124,7 @@ class Plant(pg.sprite.Sprite):
|
|||||||
self.bullet_group = bullet_group
|
self.bullet_group = bullet_group
|
||||||
self.animate_timer = 0
|
self.animate_timer = 0
|
||||||
self.animate_interval = 100
|
self.animate_interval = 100
|
||||||
self.is_attacked = False
|
self.hit_timer = 0
|
||||||
|
|
||||||
def loadFrames(self, frames, name, scale, color=c.BLACK):
|
def loadFrames(self, frames, name, scale, color=c.BLACK):
|
||||||
frame_list = tool.GFX[name]
|
frame_list = tool.GFX[name]
|
||||||
@ -168,9 +168,6 @@ class Plant(pg.sprite.Sprite):
|
|||||||
elif self.state == c.DIGEST:
|
elif self.state == c.DIGEST:
|
||||||
self.digest()
|
self.digest()
|
||||||
|
|
||||||
if self.is_attacked:
|
|
||||||
self.attacked()
|
|
||||||
|
|
||||||
def idling(self):
|
def idling(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -180,9 +177,6 @@ class Plant(pg.sprite.Sprite):
|
|||||||
def digest(self):
|
def digest(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def attacked(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def animation(self):
|
def animation(self):
|
||||||
if (self.current_time - self.animate_timer) > self.animate_interval:
|
if (self.current_time - self.animate_timer) > self.animate_interval:
|
||||||
self.frame_index += 1
|
self.frame_index += 1
|
||||||
@ -191,9 +185,13 @@ class Plant(pg.sprite.Sprite):
|
|||||||
self.animate_timer = self.current_time
|
self.animate_timer = self.current_time
|
||||||
|
|
||||||
self.image = self.frames[self.frame_index]
|
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):
|
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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -204,11 +202,9 @@ class Plant(pg.sprite.Sprite):
|
|||||||
self.state = c.IDLE
|
self.state = c.IDLE
|
||||||
self.is_attacked = False
|
self.is_attacked = False
|
||||||
|
|
||||||
def setAttacked(self):
|
|
||||||
self.is_attacked = True
|
|
||||||
|
|
||||||
def setDamage(self, damage):
|
def setDamage(self, damage):
|
||||||
self.health -= damage
|
self.health -= damage
|
||||||
|
self.hit_timer = self.current_time
|
||||||
|
|
||||||
def getPosition(self):
|
def getPosition(self):
|
||||||
return self.rect.centerx, self.rect.bottom
|
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.cracked1_frames, cracked1_frames_name, 1)
|
||||||
self.loadFrames(self.cracked2_frames, cracked2_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:
|
if not self.cracked1 and self.health <= c.WALLNUT_CRACKED1_HEALTH:
|
||||||
self.frames = self.cracked1_frames
|
self.changeFrames(self.cracked1_frames)
|
||||||
self.frame_num = len(self.frames)
|
|
||||||
self.frame_index = 0
|
|
||||||
self.cracked1 = True
|
self.cracked1 = True
|
||||||
elif not self.cracked2 and self.health <= c.WALLNUT_CRACKED2_HEALTH:
|
elif not self.cracked2 and self.health <= c.WALLNUT_CRACKED2_HEALTH:
|
||||||
self.frames = self.cracked2_frames
|
self.changeFrames(self.cracked2_frames)
|
||||||
self.frame_num = len(self.frames)
|
|
||||||
self.frame_index = 0
|
|
||||||
self.cracked2 = True
|
self.cracked2 = True
|
||||||
|
|
||||||
class CherryBomb(Plant):
|
class CherryBomb(Plant):
|
||||||
@ -451,7 +443,7 @@ class PuffMushroom(Plant):
|
|||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 3000:
|
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))
|
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
@ -583,7 +575,6 @@ class Spikeweed(Plant):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def setAttack(self, zombie_group):
|
def setAttack(self, zombie_group):
|
||||||
print('spikeweed attack')
|
|
||||||
self.zombie_group = zombie_group
|
self.zombie_group = zombie_group
|
||||||
self.animate_interval = 50
|
self.animate_interval = 50
|
||||||
self.state = c.ATTACK
|
self.state = c.ATTACK
|
||||||
@ -632,3 +623,48 @@ class Jalapeno(Plant):
|
|||||||
return
|
return
|
||||||
self.animate_timer = self.current_time
|
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'
|
SQUASH = 'Squash'
|
||||||
SPIKEWEED = 'Spikeweed'
|
SPIKEWEED = 'Spikeweed'
|
||||||
JALAPENO = 'Jalapeno'
|
JALAPENO = 'Jalapeno'
|
||||||
|
SCAREDYSHROOM = 'ScaredyShroom'
|
||||||
|
|
||||||
PLANT_HEALTH = 5
|
PLANT_HEALTH = 5
|
||||||
WALLNUT_HEALTH = 30
|
WALLNUT_HEALTH = 30
|
||||||
@ -105,6 +106,7 @@ CARD_POTATOMINE = 'card_potatomine'
|
|||||||
CARD_SQUASH = 'card_squash'
|
CARD_SQUASH = 'card_squash'
|
||||||
CARD_SPIKEWEED = 'card_spikeweed'
|
CARD_SPIKEWEED = 'card_spikeweed'
|
||||||
CARD_JALAPENO = 'card_jalapeno'
|
CARD_JALAPENO = 'card_jalapeno'
|
||||||
|
CARD_SCAREDYSHROOM = 'card_scaredyshroom'
|
||||||
|
|
||||||
#BULLET INFO
|
#BULLET INFO
|
||||||
BULLET_PEA = 'PeaNormal'
|
BULLET_PEA = 'PeaNormal'
|
||||||
@ -143,6 +145,7 @@ ATTACKED = 'attacked'
|
|||||||
DIGEST = 'digest'
|
DIGEST = 'digest'
|
||||||
WALK = 'walk'
|
WALK = 'walk'
|
||||||
DIE = 'die'
|
DIE = 'die'
|
||||||
|
CRY = 'cry'
|
||||||
|
|
||||||
#LEVEL STATE
|
#LEVEL STATE
|
||||||
CHOOSE = 'choose'
|
CHOOSE = 'choose'
|
||||||
|
|||||||
@ -204,6 +204,8 @@ class Level(tool.State):
|
|||||||
self.plant_groups[map_y].add(plant.Spikeweed(x, y))
|
self.plant_groups[map_y].add(plant.Spikeweed(x, y))
|
||||||
elif self.plant_name == c.JALAPENO:
|
elif self.plant_name == c.JALAPENO:
|
||||||
self.plant_groups[map_y].add(plant.Jalapeno(x, y))
|
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.decreaseSunValue(self.plant_cost)
|
||||||
self.menubar.setCardFrozenTime(self.plant_name)
|
self.menubar.setCardFrozenTime(self.plant_name)
|
||||||
@ -241,7 +243,8 @@ class Level(tool.State):
|
|||||||
width, height = rect.w, rect.h
|
width, height = rect.w, rect.h
|
||||||
|
|
||||||
if (plant_name == c.POTATOMINE or plant_name == c.SQUASH or
|
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
|
color = c.WHITE
|
||||||
else:
|
else:
|
||||||
color = c.BLACK
|
color = c.BLACK
|
||||||
@ -276,7 +279,6 @@ class Level(tool.State):
|
|||||||
plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func)
|
plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func)
|
||||||
if plant and plant.name != c.SPIKEWEED and zombie.state == c.WALK:
|
if plant and plant.name != c.SPIKEWEED and zombie.state == c.WALK:
|
||||||
zombie.setAttack(plant)
|
zombie.setAttack(plant)
|
||||||
plant.setAttacked()
|
|
||||||
|
|
||||||
def checkCarCollisions(self):
|
def checkCarCollisions(self):
|
||||||
collided_func = pg.sprite.collide_circle_ratio(0.8)
|
collided_func = pg.sprite.collide_circle_ratio(0.8)
|
||||||
@ -351,13 +353,33 @@ class Level(tool.State):
|
|||||||
plant.setAttack(self.zombie_groups[i])
|
plant.setAttack(self.zombie_groups[i])
|
||||||
elif plant.state == c.ATTACK and not can_attack:
|
elif plant.state == c.ATTACK and not can_attack:
|
||||||
plant.setIdle()
|
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:
|
else:
|
||||||
|
can_attack = False
|
||||||
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]:
|
||||||
if plant.canAttack(zombie):
|
if plant.canAttack(zombie):
|
||||||
plant.setAttack()
|
can_attack = True
|
||||||
break
|
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()
|
plant.setIdle()
|
||||||
|
|
||||||
if plant.health <= 0:
|
if plant.health <= 0:
|
||||||
|
|||||||