Updated by update.sh

This commit is contained in:
wszqkzqk 2021-10-29 12:46:55 +08:00
parent 09836b8ee8
commit d86ff87ffd
19 changed files with 128 additions and 90 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Cache after running the app
__pycache__/

View File

@ -9,7 +9,8 @@ PANEL_Y_START = 87
PANEL_X_START = 22
PANEL_Y_INTERNAL = 74
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,
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_num -= 1
if self.selected_num == CARD_LIST_NUM:
if self.selected_num >= CARD_MAX_NUM:
return
for card in self.card_list:
@ -319,7 +320,7 @@ class Panel():
for card in self.selected_cards:
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)
class MoveCard():

View File

@ -5,6 +5,7 @@ import pygame as pg
from .. import tool
from .. import constants as c
class Car(pg.sprite.Sprite):
def __init__(self, x, y, map_y):
pg.sprite.Sprite.__init__(self)
@ -35,6 +36,7 @@ class Car(pg.sprite.Sprite):
def draw(self, surface):
surface.blit(self.image, self.rect)
class Bullet(pg.sprite.Sprite):
def __init__(self, x, start_y, dest_y, name, damage, ice):
pg.sprite.Sprite.__init__(self)
@ -106,6 +108,7 @@ class Bullet(pg.sprite.Sprite):
def draw(self, surface):
surface.blit(self.image, self.rect)
class Plant(pg.sprite.Sprite):
def __init__(self, x, y, name, health, bullet_group, scale=1):
pg.sprite.Sprite.__init__(self)
@ -210,6 +213,7 @@ class Plant(pg.sprite.Sprite):
self.changeFrames(self.sleep_frames)
def setDamage(self, damage, zombie):
if not zombie.losHead:
self.health -= damage
self.hit_timer = self.current_time
if self.health == 0:
@ -218,6 +222,7 @@ class Plant(pg.sprite.Sprite):
def getPosition(self):
return self.rect.centerx, self.rect.bottom
class Sun(Plant):
def __init__(self, x, y, dest_x, dest_y, is_big=True):
if is_big:
@ -255,6 +260,7 @@ class Sun(Plant):
return True
return False
class SunFlower(Plant):
def __init__(self, x, y, sun_group):
Plant.__init__(self, x, y, c.SUNFLOWER, c.PLANT_HEALTH, None)
@ -265,9 +271,11 @@ class SunFlower(Plant):
if self.sun_timer == 0:
self.sun_timer = self.current_time - (c.FLOWER_SUN_INTERVAL - 6000)
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
class PeaShooter(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.PEASHOOTER, c.PLANT_HEALTH, bullet_group)
@ -279,6 +287,7 @@ class PeaShooter(Plant):
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
self.shoot_timer = self.current_time
class RepeaterPea(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.REPEATERPEA, c.PLANT_HEALTH, bullet_group)
@ -292,6 +301,7 @@ class RepeaterPea(Plant):
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
self.shoot_timer = self.current_time
class ThreePeaShooter(Plant):
def __init__(self, x, y, bullet_groups, map_y):
Plant.__init__(self, x, y, c.THREEPEASHOOTER, c.PLANT_HEALTH, None)
@ -311,6 +321,7 @@ class ThreePeaShooter(Plant):
c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False))
self.shoot_timer = self.current_time
class SnowPeaShooter(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.SNOWPEASHOOTER, c.PLANT_HEALTH, bullet_group)
@ -322,6 +333,7 @@ class SnowPeaShooter(Plant):
c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time
class WallNut(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.WALLNUT, c.WALLNUT_HEALTH, None)
@ -347,6 +359,7 @@ class WallNut(Plant):
self.changeFrames(self.cracked2_frames)
self.cracked2 = True
class CherryBomb(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.CHERRYBOMB, c.WALLNUT_HEALTH, None)
@ -385,6 +398,7 @@ class CherryBomb(Plant):
self.image = self.frames[self.frame_index]
class Chomper(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.CHOMPER, c.PLANT_HEALTH, None)
@ -448,6 +462,7 @@ class Chomper(Plant):
self.attack_zombie.kill()
self.setIdle()
class PuffShroom(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.PUFFSHROOM, c.PLANT_HEALTH, bullet_group)
@ -481,6 +496,7 @@ class PuffShroom(Plant):
return True
return False
class PotatoMine(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.POTATOMINE, c.PLANT_HEALTH, None)
@ -489,7 +505,7 @@ class PotatoMine(Plant):
self.init_timer = 0
self.bomb_timer = 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):
self.init_frames = []
@ -529,6 +545,7 @@ class PotatoMine(Plant):
elif (self.current_time - self.bomb_timer) > 500:
self.health = 0
class Squash(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.SQUASH, c.PLANT_HEALTH, None)
@ -583,6 +600,7 @@ class Squash(Plant):
def getPosition(self):
return self.orig_pos
class Spikeweed(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.SPIKEWEED, c.PLANT_HEALTH, None)
@ -615,6 +633,7 @@ class Spikeweed(Plant):
if self.canAttack(zombie):
zombie.setDamage(1, False)
class Jalapeno(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.JALAPENO, c.PLANT_HEALTH, None)
@ -657,6 +676,7 @@ class Jalapeno(Plant):
def getPosition(self):
return self.orig_pos
class ScaredyShroom(Plant):
def __init__(self, x, y, bullet_group):
Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group)
@ -705,6 +725,7 @@ class ScaredyShroom(Plant):
c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, True))
self.shoot_timer = self.current_time
class SunShroom(Plant):
def __init__(self, x, y, sun_group):
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.sun_timer = self.current_time
class IceShroom(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.ICESHROOM, c.PLANT_HEALTH, None)
@ -804,6 +826,7 @@ class IceShroom(Plant):
def getPosition(self):
return self.orig_pos
class HypnoShroom(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.HYPNOSHROOM, 1, None)
@ -825,6 +848,7 @@ class HypnoShroom(Plant):
self.frames = self.idle_frames
class WallNutBowling(Plant):
def __init__(self, x, y, map_y, level):
Plant.__init__(self, x, y, c.WALLNUTBOWLING, 1, None)
@ -906,6 +930,7 @@ class WallNutBowling(Plant):
# must keep the center postion of image when rotate
self.rect = self.image.get_rect(center=self.init_rect.center)
class RedWallNutBowling(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.REDWALLNUTBOWLING, 1, None)

View File

@ -4,6 +4,7 @@ import pygame as pg
from .. import tool
from .. import constants as c
class Zombie(pg.sprite.Sprite):
def __init__(self, x, y, name, health, head_group=None, damage=1):
pg.sprite.Sprite.__init__(self)
@ -36,6 +37,8 @@ class Zombie(pg.sprite.Sprite):
self.hit_timer = 0
self.speed = 1
self.freeze_timer = 0
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):
@ -64,7 +67,7 @@ class Zombie(pg.sprite.Sprite):
self.freezing()
def walking(self):
if self.health <= 0:
if (self.losHead and (self.current_time - self.losthead_timer) > self.dead_timer):
self.setDie()
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
self.changeFrames(self.losthead_walk_frames)
@ -83,7 +86,7 @@ class Zombie(pg.sprite.Sprite):
self.rect.x -= self.speed
def attacking(self):
if self.health <= 0:
if (self.losHead and (self.current_time - self.losthead_timer) > self.dead_timer):
self.setDie()
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
self.changeFrames(self.losthead_attack_frames)
@ -107,7 +110,7 @@ class Zombie(pg.sprite.Sprite):
pass
def freezing(self):
if self.health <= 0:
if (self.losHead and (self.current_time - self.losthead_timer) > self.dead_timer):
self.setDie()
elif self.health <= c.LOSTHEAD_HEALTH and not self.losHead:
if self.old_state == c.WALK:
@ -119,6 +122,7 @@ class Zombie(pg.sprite.Sprite):
self.setWalk()
def setLostHead(self):
self.losthead_timer = self.current_time
self.losHead = True
if self.head_group is not None:
self.head_group.add(ZombieHead(self.rect.centerx, self.rect.bottom))
@ -229,6 +233,7 @@ class Zombie(pg.sprite.Sprite):
self.is_hypno = True
self.setWalk()
class ZombieHead(Zombie):
def __init__(self, x, y):
Zombie.__init__(self, x, y, c.ZOMBIE_HEAD, 0)
@ -243,6 +248,7 @@ class ZombieHead(Zombie):
def setWalk(self):
self.animate_interval = 100
class NormalZombie(Zombie):
def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.NORMAL_ZOMBIE, c.NORMAL_HEALTH, head_group)
@ -272,6 +278,7 @@ class NormalZombie(Zombie):
self.frames = self.walk_frames
class ConeHeadZombie(Zombie):
def __init__(self, x, y, 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
class BucketHeadZombie(Zombie):
def __init__(self, x, y, 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
class FlagZombie(Zombie):
def __init__(self, x, y, 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
class NewspaperZombie(Zombie):
def __init__(self, x, y, head_group):
Zombie.__init__(self, x, y, c.NEWSPAPER_ZOMBIE, c.NEWSPAPER_HEALTH, head_group)

View File

@ -146,7 +146,7 @@ FLAG_ZOMBIE = 'FlagZombie'
NEWSPAPER_ZOMBIE = 'NewspaperZombie'
BOOMDIE = 'BoomDie'
LOSTHEAD_HEALTH = 5
LOSTHEAD_HEALTH = 2
NORMAL_HEALTH = 10
FLAG_HEALTH = 15
CONEHEAD_HEALTH = 20

View File

@ -330,7 +330,7 @@ class Level(tool.State):
if self.bar_type == c.CHOSSEBAR_BOWLING:
ratio = 0.6
else:
ratio = 0.7
ratio = 0.5
collided_func = pg.sprite.collide_circle_ratio(ratio)
for i in range(self.map_y_len):
hypo_zombies = []