add plant hypnoshroom
BIN
resources/graphics/Cards/card_hypnoshroom.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
@ -13,15 +13,17 @@ 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_PUFFSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH, c.CARD_SPIKEWEED,
|
||||
c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM, c.CARD_SUNSHROOM, c.CARD_ICESHROOM]
|
||||
c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM, c.CARD_SUNSHROOM, c.CARD_ICESHROOM,
|
||||
c.CARD_HYPNOSHROOM]
|
||||
plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT,
|
||||
c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER,
|
||||
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]
|
||||
c.JALAPENO, c.SCAREDYSHROOM, c.SUNSHROOM, c.ICESHROOM,
|
||||
c.HYPNOSHROOM]
|
||||
plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25, 25, 75, 75]
|
||||
plant_frozen_time_list = [7500, 7500, 7500, 30000, 50000, 7500, 7500, 7500, 7500, 30000,
|
||||
30000, 7500, 50000, 7500, 7500, 50000]
|
||||
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
|
||||
30000, 7500, 50000, 7500, 7500, 50000, 3000]
|
||||
all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
|
||||
|
||||
def getSunValueImage(sun_value):
|
||||
font = pg.font.SysFont(None, 22)
|
||||
|
||||
@ -208,9 +208,11 @@ class Plant(pg.sprite.Sprite):
|
||||
self.state = c.SLEEP
|
||||
self.changeFrames(self.sleep_frames)
|
||||
|
||||
def setDamage(self, damage):
|
||||
def setDamage(self, damage, zombie):
|
||||
self.health -= damage
|
||||
self.hit_timer = self.current_time
|
||||
if self.health == 0:
|
||||
self.kill_zombie = zombie
|
||||
|
||||
def getPosition(self):
|
||||
return self.rect.centerx, self.rect.bottom
|
||||
@ -799,4 +801,25 @@ class IceShroom(Plant):
|
||||
self.image = self.frames[self.frame_index]
|
||||
|
||||
def getPosition(self):
|
||||
return self.orig_pos
|
||||
return self.orig_pos
|
||||
|
||||
class HypnoShroom(Plant):
|
||||
def __init__(self, x, y):
|
||||
Plant.__init__(self, x, y, c.HYPNOSHROOM, 1, None)
|
||||
self.can_sleep = True
|
||||
self.animate_interval = 200
|
||||
|
||||
def loadImages(self, name, scale):
|
||||
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, c.WHITE)
|
||||
|
||||
self.frames = self.idle_frames
|
||||
@ -36,6 +36,7 @@ class Zombie(pg.sprite.Sprite):
|
||||
self.hit_timer = 0
|
||||
self.speed = 1
|
||||
self.freeze_timer = 0
|
||||
self.is_hypno = False # the zombie is hypo and attack other zombies when it ate a HypnoShroom
|
||||
|
||||
def loadFrames(self, frames, name, image_x, colorkey=c.BLACK):
|
||||
frame_list = tool.GFX[name]
|
||||
@ -76,7 +77,10 @@ class Zombie(pg.sprite.Sprite):
|
||||
|
||||
if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()):
|
||||
self.walk_timer = self.current_time
|
||||
self.rect.x -= self.speed
|
||||
if self.is_hypno:
|
||||
self.rect.x += self.speed
|
||||
else:
|
||||
self.rect.x -= self.speed
|
||||
|
||||
def attacking(self):
|
||||
if self.health <= 0:
|
||||
@ -84,13 +88,20 @@ class Zombie(pg.sprite.Sprite):
|
||||
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
||||
self.changeFrames(self.losthead_attack_frames)
|
||||
self.setLostHead()
|
||||
elif self.health <= c.NORMAL_HEALTH and self.helmet:
|
||||
self.changeFrames(self.attack_frames)
|
||||
self.helmet = False
|
||||
if (self.current_time - self.attack_timer) > (c.ATTACK_INTERVAL * self.getTimeRatio()):
|
||||
self.plant.setDamage(self.damage)
|
||||
if self.prey.health > 0:
|
||||
if self.prey_is_plant:
|
||||
self.prey.setDamage(self.damage, self)
|
||||
else:
|
||||
self.prey.setDamage(self.damage)
|
||||
self.attack_timer = self.current_time
|
||||
|
||||
if self.plant.health <= 0:
|
||||
self.plant = None
|
||||
self.setWalk()
|
||||
if self.prey.health <= 0:
|
||||
self.prey = None
|
||||
self.setWalk()
|
||||
|
||||
def dying(self):
|
||||
pass
|
||||
@ -140,6 +151,8 @@ class Zombie(pg.sprite.Sprite):
|
||||
self.animate_timer = self.current_time
|
||||
|
||||
self.image = self.frames[self.frame_index]
|
||||
if self.is_hypno:
|
||||
self.image = pg.transform.flip(self.image, True, False)
|
||||
if(self.current_time - self.hit_timer) >= 200:
|
||||
self.image.set_alpha(255)
|
||||
else:
|
||||
@ -158,7 +171,7 @@ class Zombie(pg.sprite.Sprite):
|
||||
if (self.current_time - self.ice_slow_timer) > c.ICE_SLOW_TIME:
|
||||
self.ice_slow_ratio = 1
|
||||
|
||||
def setDamage(self, damage, ice):
|
||||
def setDamage(self, damage, ice=False):
|
||||
self.health -= damage
|
||||
self.hit_timer = self.current_time
|
||||
if ice:
|
||||
@ -175,9 +188,11 @@ class Zombie(pg.sprite.Sprite):
|
||||
else:
|
||||
self.changeFrames(self.walk_frames)
|
||||
|
||||
def setAttack(self, plant):
|
||||
self.plant = plant
|
||||
def setAttack(self, prey, is_plant=True):
|
||||
self.prey = prey # prey can be plant or other zombies
|
||||
self.prey_is_plant = is_plant
|
||||
self.state = c.ATTACK
|
||||
self.attack_timer = self.current_time
|
||||
self.animate_interval = 100
|
||||
|
||||
if self.helmet:
|
||||
@ -210,6 +225,10 @@ class Zombie(pg.sprite.Sprite):
|
||||
if self.state == c.FREEZE:
|
||||
surface.blit(self.ice_trap_image, self.ice_trap_rect)
|
||||
|
||||
def setHypno(self):
|
||||
self.is_hypno = True
|
||||
self.setWalk()
|
||||
|
||||
class ZombieHead(Zombie):
|
||||
def __init__(self, x, y):
|
||||
Zombie.__init__(self, x, y, c.ZOMBIE_HEAD, 0)
|
||||
|
||||
@ -81,6 +81,7 @@ JALAPENO = 'Jalapeno'
|
||||
SCAREDYSHROOM = 'ScaredyShroom'
|
||||
SUNSHROOM = 'SunShroom'
|
||||
ICESHROOM = 'IceShroom'
|
||||
HYPNOSHROOM = 'HypnoShroom'
|
||||
|
||||
PLANT_HEALTH = 5
|
||||
WALLNUT_HEALTH = 30
|
||||
@ -114,7 +115,7 @@ CARD_JALAPENO = 'card_jalapeno'
|
||||
CARD_SCAREDYSHROOM = 'card_scaredyshroom'
|
||||
CARD_SUNSHROOM = 'card_sunshroom'
|
||||
CARD_ICESHROOM = 'card_iceshroom'
|
||||
|
||||
CARD_HYPNOSHROOM = 'card_hypnoshroom'
|
||||
|
||||
#BULLET INFO
|
||||
BULLET_PEA = 'PeaNormal'
|
||||
|
||||
@ -46,10 +46,12 @@ class Level(tool.State):
|
||||
|
||||
self.plant_groups = []
|
||||
self.zombie_groups = []
|
||||
self.hypno_zombie_groups = [] #zombies who are hypno after eating hypnoshroom
|
||||
self.bullet_groups = []
|
||||
for i in range(self.map_y_len):
|
||||
self.plant_groups.append(pg.sprite.Group())
|
||||
self.zombie_groups.append(pg.sprite.Group())
|
||||
self.hypno_zombie_groups.append(pg.sprite.Group())
|
||||
self.bullet_groups.append(pg.sprite.Group())
|
||||
|
||||
def setupZombies(self):
|
||||
@ -116,6 +118,11 @@ class Level(tool.State):
|
||||
self.bullet_groups[i].update(self.game_info)
|
||||
self.plant_groups[i].update(self.game_info)
|
||||
self.zombie_groups[i].update(self.game_info)
|
||||
self.hypno_zombie_groups[i].update(self.game_info)
|
||||
for zombie in self.hypno_zombie_groups[i]:
|
||||
if zombie.rect.x > c.SCREEN_WIDTH:
|
||||
zombie.kill()
|
||||
|
||||
self.head_group.update(self.game_info)
|
||||
self.sun_group.update(self.game_info)
|
||||
|
||||
@ -214,6 +221,8 @@ class Level(tool.State):
|
||||
new_plant = plant.SunShroom(x, y, self.sun_group)
|
||||
elif self.plant_name == c.ICESHROOM:
|
||||
new_plant = plant.IceShroom(x, y)
|
||||
elif self.plant_name == c.HYPNOSHROOM:
|
||||
new_plant = plant.HypnoShroom(x, y)
|
||||
|
||||
if new_plant.can_sleep and self.background_type == c.BACKGROUND_DAY:
|
||||
new_plant.setSleep()
|
||||
@ -256,7 +265,7 @@ class Level(tool.State):
|
||||
if (plant_name == c.POTATOMINE or plant_name == c.SQUASH or
|
||||
plant_name == c.SPIKEWEED or plant_name == c.JALAPENO or
|
||||
plant_name == c.SCAREDYSHROOM or plant_name == c.SUNSHROOM or
|
||||
plant_name == c.ICESHROOM):
|
||||
plant_name == c.ICESHROOM or plant_name == c.HYPNOSHROOM):
|
||||
color = c.WHITE
|
||||
else:
|
||||
color = c.BLACK
|
||||
@ -287,11 +296,27 @@ class Level(tool.State):
|
||||
def checkZombieCollisions(self):
|
||||
collided_func = pg.sprite.collide_circle_ratio(0.7)
|
||||
for i in range(self.map_y_len):
|
||||
hypo_zombies = []
|
||||
for zombie in self.zombie_groups[i]:
|
||||
if zombie.state != c.WALK:
|
||||
continue
|
||||
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:
|
||||
zombie.setAttack(plant)
|
||||
|
||||
for hypno_zombie in self.hypno_zombie_groups[i]:
|
||||
if hypno_zombie.health <= 0:
|
||||
continue
|
||||
zombie_list = pg.sprite.spritecollide(hypno_zombie,
|
||||
self.zombie_groups[i], False,collided_func)
|
||||
for zombie in zombie_list:
|
||||
if zombie.state == c.DIE:
|
||||
continue
|
||||
if zombie.state == c.WALK:
|
||||
zombie.setAttack(hypno_zombie, False)
|
||||
if hypno_zombie.state == c.WALK:
|
||||
hypno_zombie.setAttack(zombie, False)
|
||||
|
||||
def checkCarCollisions(self):
|
||||
collided_func = pg.sprite.collide_circle_ratio(0.8)
|
||||
for car in self.cars:
|
||||
@ -327,7 +352,12 @@ class Level(tool.State):
|
||||
plant.explode_x_range)
|
||||
elif plant.name == c.ICESHROOM and plant.state != c.SLEEP:
|
||||
self.freezeZombies(plant)
|
||||
|
||||
elif plant.name == c.HYPNOSHROOM and plant.state != c.SLEEP:
|
||||
zombie = plant.kill_zombie
|
||||
zombie.setHypno()
|
||||
_, map_y = self.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)
|
||||
self.zombie_groups[map_y].remove(zombie)
|
||||
self.hypno_zombie_groups[map_y].add(zombie)
|
||||
plant.kill()
|
||||
|
||||
def checkPlant(self, plant, i):
|
||||
@ -457,6 +487,7 @@ class Level(tool.State):
|
||||
for i in range(self.map_y_len):
|
||||
self.plant_groups[i].draw(surface)
|
||||
self.zombie_groups[i].draw(surface)
|
||||
self.hypno_zombie_groups[i].draw(surface)
|
||||
self.bullet_groups[i].draw(surface)
|
||||
self.drawZombieFreezeTrap(i, surface)
|
||||
for car in self.cars:
|
||||
|
||||