更改杨桃设定
This commit is contained in:
parent
c140a376ba
commit
9b91d881d0
@ -4,7 +4,7 @@ import pygame as pg
|
|||||||
from .. import tool
|
from .. import tool
|
||||||
from .. import constants as c
|
from .. import constants as c
|
||||||
|
|
||||||
plantInfo = (#元组 (植物名称, 卡片名称, 阳光, 冷却时间)
|
plantInfo = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间)
|
||||||
(c.PEASHOOTER,
|
(c.PEASHOOTER,
|
||||||
c.CARD_PEASHOOTER,
|
c.CARD_PEASHOOTER,
|
||||||
100,
|
100,
|
||||||
|
|||||||
@ -111,10 +111,11 @@ class Bullet(pg.sprite.Sprite):
|
|||||||
|
|
||||||
# 杨桃的子弹
|
# 杨桃的子弹
|
||||||
class StarBullet(Bullet):
|
class StarBullet(Bullet):
|
||||||
def __init__(self, x, start_y, damage, direction): # direction指星星飞行方向
|
def __init__(self, x, start_y, damage, direction, level): # direction指星星飞行方向
|
||||||
pg.sprite.Sprite.__init__(self)
|
pg.sprite.Sprite.__init__(self)
|
||||||
|
|
||||||
self.name = c.BULLET_STAR
|
self.name = c.BULLET_STAR
|
||||||
|
self.level = level
|
||||||
self.frames = []
|
self.frames = []
|
||||||
self.effect = False
|
self.effect = False
|
||||||
self.frame_index = 0
|
self.frame_index = 0
|
||||||
@ -186,11 +187,10 @@ class StarBullet(Bullet):
|
|||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
|
|
||||||
# 这里可以用坚果保龄球的代码改一下
|
# 这里用的是坚果保龄球的代码改一下,实现子弹换行
|
||||||
def handleMapYPosition(self):
|
def handleMapYPosition(self):
|
||||||
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery)
|
_, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery)
|
||||||
if self.map_y != map_y1:
|
if (self.map_y != map_y1) and (0 <= map_y1 <= self.level.map_y_len-1): # 换行
|
||||||
# 换行
|
|
||||||
self.level.bullet_groups[self.map_y].remove(self)
|
self.level.bullet_groups[self.map_y].remove(self)
|
||||||
self.level.bullet_groups[map_y1].add(self)
|
self.level.bullet_groups[map_y1].add(self)
|
||||||
self.map_y = map_y1
|
self.map_y = map_y1
|
||||||
@ -1136,9 +1136,10 @@ class TorchWood(Plant):
|
|||||||
i.kill()
|
i.kill()
|
||||||
|
|
||||||
class StarFruit(Plant):
|
class StarFruit(Plant):
|
||||||
def __init__(self, x, y, bullet_group):
|
def __init__(self, x, y, bullet_group, level):
|
||||||
Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group)
|
Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group)
|
||||||
self.shoot_timer = 0
|
self.shoot_timer = 0
|
||||||
|
self.level = level
|
||||||
|
|
||||||
def canAttack(self, zombie):
|
def canAttack(self, zombie):
|
||||||
if zombie.state != c.DIE:
|
if zombie.state != c.DIE:
|
||||||
@ -1152,10 +1153,10 @@ class StarFruit(Plant):
|
|||||||
|
|
||||||
def attacking(self):
|
def attacking(self):
|
||||||
if (self.current_time - self.shoot_timer) > 1400:
|
if (self.current_time - self.shoot_timer) > 1400:
|
||||||
self.bullet_group.add(StarBullet(self.rect.left + 10, self.rect.y, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD))
|
self.bullet_group.add(StarBullet(self.rect.left + 10, self.rect.y, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD, self.level))
|
||||||
self.bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - self.rect.h + 5, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD))
|
self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - self.rect.h + 5, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD, self.level))
|
||||||
self.bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD))
|
self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD, self.level))
|
||||||
self.bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y + 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN))
|
self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.bottom - 20, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN, self.level))
|
||||||
self.bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP))
|
self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP, self.level))
|
||||||
self.shoot_timer = self.current_time
|
self.shoot_timer = self.current_time
|
||||||
|
|
||||||
|
|||||||
@ -536,7 +536,7 @@ class Level(tool.State):
|
|||||||
elif self.plant_name == c.TORCHWOOD:
|
elif self.plant_name == c.TORCHWOOD:
|
||||||
new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y])
|
new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y])
|
||||||
elif self.plant_name == c.STARFRUIT:
|
elif self.plant_name == c.STARFRUIT:
|
||||||
new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y])
|
new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self)
|
||||||
|
|
||||||
if new_plant.can_sleep and self.background_type in {c.BACKGROUND_DAY, c.BACKGROUND_POOL, c.BACKGROUND_ROOF, c.BACKGROUND_WALLNUTBOWLING, c.BACKGROUND_SINGLE, c.BACKGROUND_TRIPLE}:
|
if new_plant.can_sleep and self.background_type in {c.BACKGROUND_DAY, c.BACKGROUND_POOL, c.BACKGROUND_ROOF, c.BACKGROUND_WALLNUTBOWLING, c.BACKGROUND_SINGLE, c.BACKGROUND_TRIPLE}:
|
||||||
new_plant.setSleep()
|
new_plant.setSleep()
|
||||||
@ -618,9 +618,12 @@ class Level(tool.State):
|
|||||||
self.shovel_rect.y = self.shovel_positon[1]
|
self.shovel_rect.y = self.shovel_positon[1]
|
||||||
|
|
||||||
def checkBulletCollisions(self):
|
def checkBulletCollisions(self):
|
||||||
collided_func = pg.sprite.collide_circle_ratio(0.7)
|
|
||||||
for i in range(self.map_y_len):
|
for i in range(self.map_y_len):
|
||||||
for bullet in self.bullet_groups[i]:
|
for bullet in self.bullet_groups[i]:
|
||||||
|
if bullet.name == c.BULLET_STAR:
|
||||||
|
collided_func = pg.sprite.collide_circle_ratio(1)
|
||||||
|
else:
|
||||||
|
collided_func = pg.sprite.collide_circle_ratio(0.7)
|
||||||
if bullet.state == c.FLY:
|
if bullet.state == c.FLY:
|
||||||
zombie = pg.sprite.spritecollideany(bullet, self.zombie_groups[i], collided_func)
|
zombie = pg.sprite.spritecollideany(bullet, self.zombie_groups[i], collided_func)
|
||||||
if zombie and zombie.state != c.DIE:
|
if zombie and zombie.state != c.DIE:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user