Updated by update.sh
This commit is contained in:
parent
09836b8ee8
commit
d86ff87ffd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Cache after running the app
|
||||||
|
__pycache__/
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -9,7 +9,8 @@ PANEL_Y_START = 87
|
|||||||
PANEL_X_START = 22
|
PANEL_X_START = 22
|
||||||
PANEL_Y_INTERNAL = 74
|
PANEL_Y_INTERNAL = 74
|
||||||
PANEL_X_INTERNAL = 53
|
PANEL_X_INTERNAL = 53
|
||||||
CARD_LIST_NUM = 8
|
CARD_LIST_NUM = 0
|
||||||
|
CARD_MAX_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,
|
||||||
@ -275,7 +276,7 @@ class Panel():
|
|||||||
self.selected_cards.remove(delete_card)
|
self.selected_cards.remove(delete_card)
|
||||||
self.selected_num -= 1
|
self.selected_num -= 1
|
||||||
|
|
||||||
if self.selected_num == CARD_LIST_NUM:
|
if self.selected_num >= CARD_MAX_NUM:
|
||||||
return
|
return
|
||||||
|
|
||||||
for card in self.card_list:
|
for card in self.card_list:
|
||||||
@ -319,7 +320,7 @@ class Panel():
|
|||||||
for card in self.selected_cards:
|
for card in self.selected_cards:
|
||||||
card.draw(surface)
|
card.draw(surface)
|
||||||
|
|
||||||
if self.selected_num == CARD_LIST_NUM:
|
if self.selected_num >= CARD_LIST_NUM:
|
||||||
surface.blit(self.button_image, self.button_rect)
|
surface.blit(self.button_image, self.button_rect)
|
||||||
|
|
||||||
class MoveCard():
|
class MoveCard():
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import pygame as pg
|
|||||||
from .. import tool
|
from .. import tool
|
||||||
from .. import constants as c
|
from .. import constants as c
|
||||||
|
|
||||||
|
|
||||||
class Car(pg.sprite.Sprite):
|
class Car(pg.sprite.Sprite):
|
||||||
def __init__(self, x, y, map_y):
|
def __init__(self, x, y, map_y):
|
||||||
pg.sprite.Sprite.__init__(self)
|
pg.sprite.Sprite.__init__(self)
|
||||||
@ -35,6 +36,7 @@ class Car(pg.sprite.Sprite):
|
|||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
|
|
||||||
|
|
||||||
class Bullet(pg.sprite.Sprite):
|
class Bullet(pg.sprite.Sprite):
|
||||||
def __init__(self, x, start_y, dest_y, name, damage, ice):
|
def __init__(self, x, start_y, dest_y, name, damage, ice):
|
||||||
pg.sprite.Sprite.__init__(self)
|
pg.sprite.Sprite.__init__(self)
|
||||||
@ -94,7 +96,7 @@ class Bullet(pg.sprite.Sprite):
|
|||||||
if self.rect.x > c.SCREEN_WIDTH:
|
if self.rect.x > c.SCREEN_WIDTH:
|
||||||
self.kill()
|
self.kill()
|
||||||
elif self.state == c.EXPLODE:
|
elif self.state == c.EXPLODE:
|
||||||
if(self.current_time - self.explode_timer) > 500:
|
if (self.current_time - self.explode_timer) > 500:
|
||||||
self.kill()
|
self.kill()
|
||||||
|
|
||||||
def setExplode(self):
|
def setExplode(self):
|
||||||
@ -106,6 +108,7 @@ class Bullet(pg.sprite.Sprite):
|
|||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
|
|
||||||
|
|
||||||
class Plant(pg.sprite.Sprite):
|
class Plant(pg.sprite.Sprite):
|
||||||
def __init__(self, x, y, name, health, bullet_group, scale=1):
|
def __init__(self, x, y, name, health, bullet_group, scale=1):
|
||||||
pg.sprite.Sprite.__init__(self)
|
pg.sprite.Sprite.__init__(self)
|
||||||
@ -187,14 +190,14 @@ 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:
|
if (self.current_time - self.hit_timer) >= 200:
|
||||||
self.image.set_alpha(255)
|
self.image.set_alpha(255)
|
||||||
else:
|
else:
|
||||||
self.image.set_alpha(192)
|
self.image.set_alpha(192)
|
||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if (self.state != c.SLEEP and zombie.state != c.DIE and
|
if (self.state != c.SLEEP and zombie.state != c.DIE and
|
||||||
self.rect.x <= zombie.rect.right):
|
self.rect.x <= zombie.rect.right):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -210,7 +213,8 @@ class Plant(pg.sprite.Sprite):
|
|||||||
self.changeFrames(self.sleep_frames)
|
self.changeFrames(self.sleep_frames)
|
||||||
|
|
||||||
def setDamage(self, damage, zombie):
|
def setDamage(self, damage, zombie):
|
||||||
self.health -= damage
|
if not zombie.losHead:
|
||||||
|
self.health -= damage
|
||||||
self.hit_timer = self.current_time
|
self.hit_timer = self.current_time
|
||||||
if self.health == 0:
|
if self.health == 0:
|
||||||
self.kill_zombie = zombie
|
self.kill_zombie = zombie
|
||||||
@ -218,6 +222,7 @@ class Plant(pg.sprite.Sprite):
|
|||||||
def getPosition(self):
|
def getPosition(self):
|
||||||
return self.rect.centerx, self.rect.bottom
|
return self.rect.centerx, self.rect.bottom
|
||||||
|
|
||||||
|
|
||||||
class Sun(Plant):
|
class Sun(Plant):
|
||||||
def __init__(self, x, y, dest_x, dest_y, is_big=True):
|
def __init__(self, x, y, dest_x, dest_y, is_big=True):
|
||||||
if is_big:
|
if is_big:
|
||||||
@ -241,20 +246,21 @@ class Sun(Plant):
|
|||||||
if self.rect.centerx == self.dest_x and self.rect.bottom == self.dest_y:
|
if self.rect.centerx == self.dest_x and self.rect.bottom == self.dest_y:
|
||||||
if self.die_timer == 0:
|
if self.die_timer == 0:
|
||||||
self.die_timer = self.current_time
|
self.die_timer = self.current_time
|
||||||
elif(self.current_time - self.die_timer) > c.SUN_LIVE_TIME:
|
elif (self.current_time - self.die_timer) > c.SUN_LIVE_TIME:
|
||||||
self.state = c.DIE
|
self.state = c.DIE
|
||||||
self.kill()
|
self.kill()
|
||||||
|
|
||||||
def checkCollision(self, x, y):
|
def checkCollision(self, x, y):
|
||||||
if self.state == c.DIE:
|
if self.state == c.DIE:
|
||||||
return False
|
return False
|
||||||
if(x >= self.rect.x and x <= self.rect.right and
|
if (x >= self.rect.x and x <= self.rect.right and
|
||||||
y >= self.rect.y and y <= self.rect.bottom):
|
y >= self.rect.y and y <= self.rect.bottom):
|
||||||
self.state = c.DIE
|
self.state = c.DIE
|
||||||
self.kill()
|
self.kill()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class SunFlower(Plant):
|
class SunFlower(Plant):
|
||||||
def __init__(self, x, y, sun_group):
|
def __init__(self, x, y, sun_group):
|
||||||
Plant.__init__(self, x, y, c.SUNFLOWER, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.SUNFLOWER, c.PLANT_HEALTH, None)
|
||||||
@ -265,9 +271,11 @@ class SunFlower(Plant):
|
|||||||
if self.sun_timer == 0:
|
if self.sun_timer == 0:
|
||||||
self.sun_timer = self.current_time - (c.FLOWER_SUN_INTERVAL - 6000)
|
self.sun_timer = self.current_time - (c.FLOWER_SUN_INTERVAL - 6000)
|
||||||
elif (self.current_time - self.sun_timer) > c.FLOWER_SUN_INTERVAL:
|
elif (self.current_time - self.sun_timer) > c.FLOWER_SUN_INTERVAL:
|
||||||
self.sun_group.add(Sun(self.rect.centerx, self.rect.bottom, self.rect.right, self.rect.bottom + self.rect.h // 2))
|
self.sun_group.add(
|
||||||
|
Sun(self.rect.centerx, self.rect.bottom, self.rect.right, self.rect.bottom + self.rect.h // 2))
|
||||||
self.sun_timer = self.current_time
|
self.sun_timer = self.current_time
|
||||||
|
|
||||||
|
|
||||||
class PeaShooter(Plant):
|
class PeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.PEASHOOTER, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.PEASHOOTER, c.PLANT_HEALTH, bullet_group)
|
||||||
@ -276,9 +284,10 @@ class PeaShooter(Plant):
|
|||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 2000:
|
if (self.current_time - self.shoot_timer) > 2000:
|
||||||
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, self.rect.y,
|
||||||
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
|
|
||||||
class RepeaterPea(Plant):
|
class RepeaterPea(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.REPEATERPEA, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.REPEATERPEA, c.PLANT_HEALTH, bullet_group)
|
||||||
@ -287,11 +296,12 @@ class RepeaterPea(Plant):
|
|||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 2000:
|
if (self.current_time - self.shoot_timer) > 2000:
|
||||||
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, self.rect.y,
|
||||||
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.bullet_group.add(Bullet(self.rect.right + 40, self.rect.y, self.rect.y,
|
self.bullet_group.add(Bullet(self.rect.right + 40, self.rect.y, self.rect.y,
|
||||||
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
|
|
||||||
class ThreePeaShooter(Plant):
|
class ThreePeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_groups, map_y):
|
def __init__(self, x, y, bullet_groups, map_y):
|
||||||
Plant.__init__(self, x, y, c.THREEPEASHOOTER, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.THREEPEASHOOTER, c.PLANT_HEALTH, None)
|
||||||
@ -301,16 +311,17 @@ class ThreePeaShooter(Plant):
|
|||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 2000:
|
if (self.current_time - self.shoot_timer) > 2000:
|
||||||
offset_y = 9 # modify bullet in the same y position with bullets of other plants
|
offset_y = 9 # modify bullet in the same y position with bullets of other plants
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
tmp_y = self.map_y + (i - 1)
|
tmp_y = self.map_y + (i - 1)
|
||||||
if tmp_y < 0 or tmp_y >= c.GRID_Y_LEN:
|
if tmp_y < 0 or tmp_y >= c.GRID_Y_LEN:
|
||||||
continue
|
continue
|
||||||
dest_y = self.rect.y + (i - 1) * c.GRID_Y_SIZE + offset_y
|
dest_y = self.rect.y + (i - 1) * c.GRID_Y_SIZE + offset_y
|
||||||
self.bullet_groups[tmp_y].add(Bullet(self.rect.right, self.rect.y, dest_y,
|
self.bullet_groups[tmp_y].add(Bullet(self.rect.right, self.rect.y, dest_y,
|
||||||
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
|
|
||||||
class SnowPeaShooter(Plant):
|
class SnowPeaShooter(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.SNOWPEASHOOTER, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.SNOWPEASHOOTER, c.PLANT_HEALTH, bullet_group)
|
||||||
@ -319,9 +330,10 @@ class SnowPeaShooter(Plant):
|
|||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 2000:
|
if (self.current_time - self.shoot_timer) > 2000:
|
||||||
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, self.rect.y,
|
||||||
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True))
|
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
|
|
||||||
class WallNut(Plant):
|
class WallNut(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.WALLNUT, c.WALLNUT_HEALTH, None)
|
Plant.__init__(self, x, y, c.WALLNUT, c.WALLNUT_HEALTH, None)
|
||||||
@ -347,6 +359,7 @@ class WallNut(Plant):
|
|||||||
self.changeFrames(self.cracked2_frames)
|
self.changeFrames(self.cracked2_frames)
|
||||||
self.cracked2 = True
|
self.cracked2 = True
|
||||||
|
|
||||||
|
|
||||||
class CherryBomb(Plant):
|
class CherryBomb(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.CHERRYBOMB, c.WALLNUT_HEALTH, None)
|
Plant.__init__(self, x, y, c.CHERRYBOMB, c.WALLNUT_HEALTH, None)
|
||||||
@ -373,7 +386,7 @@ class CherryBomb(Plant):
|
|||||||
if self.start_boom:
|
if self.start_boom:
|
||||||
if self.bomb_timer == 0:
|
if self.bomb_timer == 0:
|
||||||
self.bomb_timer = self.current_time
|
self.bomb_timer = self.current_time
|
||||||
elif(self.current_time - self.bomb_timer) > 500:
|
elif (self.current_time - self.bomb_timer) > 500:
|
||||||
self.health = 0
|
self.health = 0
|
||||||
else:
|
else:
|
||||||
if (self.current_time - self.animate_timer) > 100:
|
if (self.current_time - self.animate_timer) > 100:
|
||||||
@ -385,6 +398,7 @@ class CherryBomb(Plant):
|
|||||||
|
|
||||||
self.image = self.frames[self.frame_index]
|
self.image = self.frames[self.frame_index]
|
||||||
|
|
||||||
|
|
||||||
class Chomper(Plant):
|
class Chomper(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.CHOMPER, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.CHOMPER, c.PLANT_HEALTH, None)
|
||||||
@ -415,8 +429,8 @@ class Chomper(Plant):
|
|||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if (self.state == c.IDLE and zombie.state != c.DIGEST and
|
if (self.state == c.IDLE and zombie.state != c.DIGEST and
|
||||||
self.rect.x <= zombie.rect.right and
|
self.rect.x <= zombie.rect.right and
|
||||||
(self.rect.right + c.GRID_X_SIZE//3 >= zombie.rect.x)):
|
(self.rect.right + c.GRID_X_SIZE // 3 >= zombie.rect.x)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -448,6 +462,7 @@ class Chomper(Plant):
|
|||||||
self.attack_zombie.kill()
|
self.attack_zombie.kill()
|
||||||
self.setIdle()
|
self.setIdle()
|
||||||
|
|
||||||
|
|
||||||
class PuffShroom(Plant):
|
class PuffShroom(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.PUFFSHROOM, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.PUFFSHROOM, c.PLANT_HEALTH, bullet_group)
|
||||||
@ -472,15 +487,16 @@ class PuffShroom(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 + 10, self.rect.y + 10,
|
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
|
||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if (self.rect.x <= zombie.rect.right and
|
if (self.rect.x <= zombie.rect.right and
|
||||||
(self.rect.right + c.GRID_X_SIZE * 4 >= zombie.rect.x)):
|
(self.rect.right + c.GRID_X_SIZE * 4 >= zombie.rect.x)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class PotatoMine(Plant):
|
class PotatoMine(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.POTATOMINE, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.POTATOMINE, c.PLANT_HEALTH, None)
|
||||||
@ -489,7 +505,7 @@ class PotatoMine(Plant):
|
|||||||
self.init_timer = 0
|
self.init_timer = 0
|
||||||
self.bomb_timer = 0
|
self.bomb_timer = 0
|
||||||
self.explode_y_range = 0
|
self.explode_y_range = 0
|
||||||
self.explode_x_range = c.GRID_X_SIZE//3 * 2
|
self.explode_x_range = c.GRID_X_SIZE - 10
|
||||||
|
|
||||||
def loadImages(self, name, scale):
|
def loadImages(self, name, scale):
|
||||||
self.init_frames = []
|
self.init_frames = []
|
||||||
@ -518,7 +534,7 @@ class PotatoMine(Plant):
|
|||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if (not self.is_init and zombie.rect.right >= self.rect.x and
|
if (not self.is_init and zombie.rect.right >= self.rect.x and
|
||||||
(zombie.rect.x - self.rect.x) <= self.explode_x_range):
|
(zombie.rect.x - self.rect.x) <= self.explode_x_range):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -529,6 +545,7 @@ class PotatoMine(Plant):
|
|||||||
elif (self.current_time - self.bomb_timer) > 500:
|
elif (self.current_time - self.bomb_timer) > 500:
|
||||||
self.health = 0
|
self.health = 0
|
||||||
|
|
||||||
|
|
||||||
class Squash(Plant):
|
class Squash(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.SQUASH, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.SQUASH, c.PLANT_HEALTH, None)
|
||||||
@ -555,7 +572,7 @@ class Squash(Plant):
|
|||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if (self.state == c.IDLE and self.rect.x <= zombie.rect.right and
|
if (self.state == c.IDLE and self.rect.x <= zombie.rect.right and
|
||||||
(self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)):
|
(self.rect.right + c.GRID_X_SIZE >= zombie.rect.x)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -583,6 +600,7 @@ class Squash(Plant):
|
|||||||
def getPosition(self):
|
def getPosition(self):
|
||||||
return self.orig_pos
|
return self.orig_pos
|
||||||
|
|
||||||
|
|
||||||
class Spikeweed(Plant):
|
class Spikeweed(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.SPIKEWEED, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.SPIKEWEED, c.PLANT_HEALTH, None)
|
||||||
@ -599,7 +617,7 @@ class Spikeweed(Plant):
|
|||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if (self.rect.x <= zombie.rect.right and
|
if (self.rect.x <= zombie.rect.right and
|
||||||
(self.rect.right >= zombie.rect.x)):
|
(self.rect.right >= zombie.rect.x)):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -615,6 +633,7 @@ class Spikeweed(Plant):
|
|||||||
if self.canAttack(zombie):
|
if self.canAttack(zombie):
|
||||||
zombie.setDamage(1, False)
|
zombie.setDamage(1, False)
|
||||||
|
|
||||||
|
|
||||||
class Jalapeno(Plant):
|
class Jalapeno(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.JALAPENO, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.JALAPENO, c.PLANT_HEALTH, None)
|
||||||
@ -639,7 +658,7 @@ class Jalapeno(Plant):
|
|||||||
|
|
||||||
def animation(self):
|
def animation(self):
|
||||||
if self.start_explode:
|
if self.start_explode:
|
||||||
if(self.current_time - self.animate_timer) > 100:
|
if (self.current_time - self.animate_timer) > 100:
|
||||||
self.frame_index += 1
|
self.frame_index += 1
|
||||||
if self.frame_index >= self.frame_num:
|
if self.frame_index >= self.frame_num:
|
||||||
self.health = 0
|
self.health = 0
|
||||||
@ -657,6 +676,7 @@ class Jalapeno(Plant):
|
|||||||
def getPosition(self):
|
def getPosition(self):
|
||||||
return self.orig_pos
|
return self.orig_pos
|
||||||
|
|
||||||
|
|
||||||
class ScaredyShroom(Plant):
|
class ScaredyShroom(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group):
|
||||||
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
|
||||||
@ -683,7 +703,7 @@ class ScaredyShroom(Plant):
|
|||||||
|
|
||||||
def needCry(self, zombie):
|
def needCry(self, zombie):
|
||||||
if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right and
|
if (zombie.state != c.DIE and self.rect.x <= zombie.rect.right and
|
||||||
self.rect.x + self.cry_x_range > zombie.rect.x):
|
self.rect.x + self.cry_x_range > zombie.rect.x):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -702,9 +722,10 @@ class ScaredyShroom(Plant):
|
|||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 2000:
|
if (self.current_time - self.shoot_timer) > 2000:
|
||||||
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 40, self.rect.y + 40,
|
self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 40, self.rect.y + 40,
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
class SunShroom(Plant):
|
class SunShroom(Plant):
|
||||||
def __init__(self, x, y, sun_group):
|
def __init__(self, x, y, sun_group):
|
||||||
Plant.__init__(self, x, y, c.SUNSHROOM, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.SUNSHROOM, c.PLANT_HEALTH, None)
|
||||||
@ -747,6 +768,7 @@ class SunShroom(Plant):
|
|||||||
self.rect.bottom + self.rect.h // 2, self.is_big))
|
self.rect.bottom + self.rect.h // 2, self.is_big))
|
||||||
self.sun_timer = self.current_time
|
self.sun_timer = self.current_time
|
||||||
|
|
||||||
|
|
||||||
class IceShroom(Plant):
|
class IceShroom(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.ICESHROOM, c.PLANT_HEALTH, None)
|
Plant.__init__(self, x, y, c.ICESHROOM, c.PLANT_HEALTH, None)
|
||||||
@ -783,7 +805,7 @@ class IceShroom(Plant):
|
|||||||
|
|
||||||
def animation(self):
|
def animation(self):
|
||||||
if self.start_freeze:
|
if self.start_freeze:
|
||||||
if(self.current_time - self.animate_timer) > 500:
|
if (self.current_time - self.animate_timer) > 500:
|
||||||
self.frame_index += 1
|
self.frame_index += 1
|
||||||
if self.frame_index >= self.frame_num:
|
if self.frame_index >= self.frame_num:
|
||||||
self.health = 0
|
self.health = 0
|
||||||
@ -804,6 +826,7 @@ class IceShroom(Plant):
|
|||||||
def getPosition(self):
|
def getPosition(self):
|
||||||
return self.orig_pos
|
return self.orig_pos
|
||||||
|
|
||||||
|
|
||||||
class HypnoShroom(Plant):
|
class HypnoShroom(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.HYPNOSHROOM, 1, None)
|
Plant.__init__(self, x, y, c.HYPNOSHROOM, 1, None)
|
||||||
@ -825,6 +848,7 @@ class HypnoShroom(Plant):
|
|||||||
|
|
||||||
self.frames = self.idle_frames
|
self.frames = self.idle_frames
|
||||||
|
|
||||||
|
|
||||||
class WallNutBowling(Plant):
|
class WallNutBowling(Plant):
|
||||||
def __init__(self, x, y, map_y, level):
|
def __init__(self, x, y, map_y, level):
|
||||||
Plant.__init__(self, x, y, c.WALLNUTBOWLING, 1, None)
|
Plant.__init__(self, x, y, c.WALLNUTBOWLING, 1, None)
|
||||||
@ -881,7 +905,7 @@ class WallNutBowling(Plant):
|
|||||||
if self.vel_y == 0:
|
if self.vel_y == 0:
|
||||||
if self.map_y == 0:
|
if self.map_y == 0:
|
||||||
direc = 1
|
direc = 1
|
||||||
elif self.map_y == (c.GRID_Y_LEN-1):
|
elif self.map_y == (c.GRID_Y_LEN - 1):
|
||||||
direc = -1
|
direc = -1
|
||||||
else:
|
else:
|
||||||
if random.randint(0, 1) == 0:
|
if random.randint(0, 1) == 0:
|
||||||
@ -906,6 +930,7 @@ class WallNutBowling(Plant):
|
|||||||
# must keep the center postion of image when rotate
|
# must keep the center postion of image when rotate
|
||||||
self.rect = self.image.get_rect(center=self.init_rect.center)
|
self.rect = self.image.get_rect(center=self.init_rect.center)
|
||||||
|
|
||||||
|
|
||||||
class RedWallNutBowling(Plant):
|
class RedWallNutBowling(Plant):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Plant.__init__(self, x, y, c.REDWALLNUTBOWLING, 1, None)
|
Plant.__init__(self, x, y, c.REDWALLNUTBOWLING, 1, None)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import pygame as pg
|
|||||||
from .. import tool
|
from .. import tool
|
||||||
from .. import constants as c
|
from .. import constants as c
|
||||||
|
|
||||||
|
|
||||||
class Zombie(pg.sprite.Sprite):
|
class Zombie(pg.sprite.Sprite):
|
||||||
def __init__(self, x, y, name, health, head_group=None, damage=1):
|
def __init__(self, x, y, name, health, head_group=None, damage=1):
|
||||||
pg.sprite.Sprite.__init__(self)
|
pg.sprite.Sprite.__init__(self)
|
||||||
@ -36,7 +37,9 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.hit_timer = 0
|
self.hit_timer = 0
|
||||||
self.speed = 1
|
self.speed = 1
|
||||||
self.freeze_timer = 0
|
self.freeze_timer = 0
|
||||||
self.is_hypno = False # the zombie is hypo and attack other zombies when it ate a HypnoShroom
|
self.dead_timer = 4800
|
||||||
|
self.losthead_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):
|
def loadFrames(self, frames, name, image_x, colorkey=c.BLACK):
|
||||||
frame_list = tool.GFX[name]
|
frame_list = tool.GFX[name]
|
||||||
@ -64,7 +67,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.freezing()
|
self.freezing()
|
||||||
|
|
||||||
def walking(self):
|
def walking(self):
|
||||||
if self.health <= 0:
|
if (self.losHead and (self.current_time - self.losthead_timer) > self.dead_timer):
|
||||||
self.setDie()
|
self.setDie()
|
||||||
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
||||||
self.changeFrames(self.losthead_walk_frames)
|
self.changeFrames(self.losthead_walk_frames)
|
||||||
@ -83,7 +86,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.rect.x -= self.speed
|
self.rect.x -= self.speed
|
||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if self.health <= 0:
|
if (self.losHead and (self.current_time - self.losthead_timer) > self.dead_timer):
|
||||||
self.setDie()
|
self.setDie()
|
||||||
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
||||||
self.changeFrames(self.losthead_attack_frames)
|
self.changeFrames(self.losthead_attack_frames)
|
||||||
@ -107,7 +110,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def freezing(self):
|
def freezing(self):
|
||||||
if self.health <= 0:
|
if (self.losHead and (self.current_time - self.losthead_timer) > self.dead_timer):
|
||||||
self.setDie()
|
self.setDie()
|
||||||
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
|
||||||
if self.old_state == c.WALK:
|
if self.old_state == c.WALK:
|
||||||
@ -119,6 +122,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.setWalk()
|
self.setWalk()
|
||||||
|
|
||||||
def setLostHead(self):
|
def setLostHead(self):
|
||||||
|
self.losthead_timer = self.current_time
|
||||||
self.losHead = True
|
self.losHead = True
|
||||||
if self.head_group is not None:
|
if self.head_group is not None:
|
||||||
self.head_group.add(ZombieHead(self.rect.centerx, self.rect.bottom))
|
self.head_group.add(ZombieHead(self.rect.centerx, self.rect.bottom))
|
||||||
@ -153,7 +157,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.image = self.frames[self.frame_index]
|
self.image = self.frames[self.frame_index]
|
||||||
if self.is_hypno:
|
if self.is_hypno:
|
||||||
self.image = pg.transform.flip(self.image, True, False)
|
self.image = pg.transform.flip(self.image, True, False)
|
||||||
if(self.current_time - self.hit_timer) >= 200:
|
if (self.current_time - self.hit_timer) >= 200:
|
||||||
self.image.set_alpha(255)
|
self.image.set_alpha(255)
|
||||||
else:
|
else:
|
||||||
self.image.set_alpha(192)
|
self.image.set_alpha(192)
|
||||||
@ -229,6 +233,7 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
self.is_hypno = True
|
self.is_hypno = True
|
||||||
self.setWalk()
|
self.setWalk()
|
||||||
|
|
||||||
|
|
||||||
class ZombieHead(Zombie):
|
class ZombieHead(Zombie):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
Zombie.__init__(self, x, y, c.ZOMBIE_HEAD, 0)
|
Zombie.__init__(self, x, y, c.ZOMBIE_HEAD, 0)
|
||||||
@ -236,13 +241,14 @@ class ZombieHead(Zombie):
|
|||||||
|
|
||||||
def loadImages(self):
|
def loadImages(self):
|
||||||
self.die_frames = []
|
self.die_frames = []
|
||||||
die_name = self.name
|
die_name = self.name
|
||||||
self.loadFrames(self.die_frames, die_name, 0)
|
self.loadFrames(self.die_frames, die_name, 0)
|
||||||
self.frames = self.die_frames
|
self.frames = self.die_frames
|
||||||
|
|
||||||
def setWalk(self):
|
def setWalk(self):
|
||||||
self.animate_interval = 100
|
self.animate_interval = 100
|
||||||
|
|
||||||
|
|
||||||
class NormalZombie(Zombie):
|
class NormalZombie(Zombie):
|
||||||
def __init__(self, x, y, head_group):
|
def __init__(self, x, y, head_group):
|
||||||
Zombie.__init__(self, x, y, c.NORMAL_ZOMBIE, c.NORMAL_HEALTH, head_group)
|
Zombie.__init__(self, x, y, c.NORMAL_ZOMBIE, c.NORMAL_HEALTH, head_group)
|
||||||
@ -259,7 +265,7 @@ class NormalZombie(Zombie):
|
|||||||
attack_name = self.name + 'Attack'
|
attack_name = self.name + 'Attack'
|
||||||
losthead_walk_name = self.name + 'LostHead'
|
losthead_walk_name = self.name + 'LostHead'
|
||||||
losthead_attack_name = self.name + 'LostHeadAttack'
|
losthead_attack_name = self.name + 'LostHeadAttack'
|
||||||
die_name = self.name + 'Die'
|
die_name = self.name + 'Die'
|
||||||
boomdie_name = c.BOOMDIE
|
boomdie_name = c.BOOMDIE
|
||||||
|
|
||||||
frame_list = [self.walk_frames, self.attack_frames, self.losthead_walk_frames,
|
frame_list = [self.walk_frames, self.attack_frames, self.losthead_walk_frames,
|
||||||
@ -272,6 +278,7 @@ class NormalZombie(Zombie):
|
|||||||
|
|
||||||
self.frames = self.walk_frames
|
self.frames = self.walk_frames
|
||||||
|
|
||||||
|
|
||||||
class ConeHeadZombie(Zombie):
|
class ConeHeadZombie(Zombie):
|
||||||
def __init__(self, x, y, head_group):
|
def __init__(self, x, y, head_group):
|
||||||
Zombie.__init__(self, x, y, c.CONEHEAD_ZOMBIE, c.CONEHEAD_HEALTH, head_group)
|
Zombie.__init__(self, x, y, c.CONEHEAD_ZOMBIE, c.CONEHEAD_HEALTH, head_group)
|
||||||
@ -308,6 +315,7 @@ class ConeHeadZombie(Zombie):
|
|||||||
|
|
||||||
self.frames = self.helmet_walk_frames
|
self.frames = self.helmet_walk_frames
|
||||||
|
|
||||||
|
|
||||||
class BucketHeadZombie(Zombie):
|
class BucketHeadZombie(Zombie):
|
||||||
def __init__(self, x, y, head_group):
|
def __init__(self, x, y, head_group):
|
||||||
Zombie.__init__(self, x, y, c.BUCKETHEAD_ZOMBIE, c.BUCKETHEAD_HEALTH, head_group)
|
Zombie.__init__(self, x, y, c.BUCKETHEAD_ZOMBIE, c.BUCKETHEAD_HEALTH, head_group)
|
||||||
@ -344,6 +352,7 @@ class BucketHeadZombie(Zombie):
|
|||||||
|
|
||||||
self.frames = self.helmet_walk_frames
|
self.frames = self.helmet_walk_frames
|
||||||
|
|
||||||
|
|
||||||
class FlagZombie(Zombie):
|
class FlagZombie(Zombie):
|
||||||
def __init__(self, x, y, head_group):
|
def __init__(self, x, y, head_group):
|
||||||
Zombie.__init__(self, x, y, c.FLAG_ZOMBIE, c.FLAG_HEALTH, head_group)
|
Zombie.__init__(self, x, y, c.FLAG_ZOMBIE, c.FLAG_HEALTH, head_group)
|
||||||
@ -373,6 +382,7 @@ class FlagZombie(Zombie):
|
|||||||
|
|
||||||
self.frames = self.walk_frames
|
self.frames = self.walk_frames
|
||||||
|
|
||||||
|
|
||||||
class NewspaperZombie(Zombie):
|
class NewspaperZombie(Zombie):
|
||||||
def __init__(self, x, y, head_group):
|
def __init__(self, x, y, head_group):
|
||||||
Zombie.__init__(self, x, y, c.NEWSPAPER_ZOMBIE, c.NEWSPAPER_HEALTH, head_group)
|
Zombie.__init__(self, x, y, c.NEWSPAPER_ZOMBIE, c.NEWSPAPER_HEALTH, head_group)
|
||||||
|
|||||||
@ -146,7 +146,7 @@ FLAG_ZOMBIE = 'FlagZombie'
|
|||||||
NEWSPAPER_ZOMBIE = 'NewspaperZombie'
|
NEWSPAPER_ZOMBIE = 'NewspaperZombie'
|
||||||
BOOMDIE = 'BoomDie'
|
BOOMDIE = 'BoomDie'
|
||||||
|
|
||||||
LOSTHEAD_HEALTH = 5
|
LOSTHEAD_HEALTH = 2
|
||||||
NORMAL_HEALTH = 10
|
NORMAL_HEALTH = 10
|
||||||
FLAG_HEALTH = 15
|
FLAG_HEALTH = 15
|
||||||
CONEHEAD_HEALTH = 20
|
CONEHEAD_HEALTH = 20
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -330,7 +330,7 @@ class Level(tool.State):
|
|||||||
if self.bar_type == c.CHOSSEBAR_BOWLING:
|
if self.bar_type == c.CHOSSEBAR_BOWLING:
|
||||||
ratio = 0.6
|
ratio = 0.6
|
||||||
else:
|
else:
|
||||||
ratio = 0.7
|
ratio = 0.5
|
||||||
collided_func = pg.sprite.collide_circle_ratio(ratio)
|
collided_func = pg.sprite.collide_circle_ratio(ratio)
|
||||||
for i in range(self.map_y_len):
|
for i in range(self.map_y_len):
|
||||||
hypo_zombies = []
|
hypo_zombies = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user