植物大战僵尸的画(植物大战僵尸介绍僵尸的名字)

class Map():

存储两张不同颜色的图片名称

map_names_list = [IMAGE_PATH + ‘map1.png’, IMAGE_PATH + ‘map2.png’]

初始化地图

def init(self, x, y, img_index):

self.image = pygame.image.load(Map.map_names_list[img_index])

self.position = (x, y)

是否能够种植

self.can_grow = True

加载地图

def load_map(self):

MainGame.window.blit(self.image, self.position)

植物大战僵尸的画

植物类

class Plant(pygame.sprite.Sprite):

def init(self):

super(Plant, self).init()

self.live = True

加载图片

def load_image(self):

if hasattr(self, ‘image’) and hasattr(self, ‘rect’):

MainGame.window.blit(self.image, self.rect)

else:

print(LOG)

向日葵类

class Sunflower(Plant):

def init(self, x, y):

super(Sunflower, self).init()

self.image = pygame.image.load(‘imgs/sunflower.png’)

self.rect = self.image.get_rect()

self.rect.x = x

self.rect.y = y

self.price = 50

self.hp = 100

self.time_count = 0

新增功能:生成阳光

def produce_money(self):

self.time_count += 1

if self.time_count == 25:

MainGame.money += 5

self.time_count = 0

向日葵加入到窗口中

def display_sunflower(self):

MainGame.window.blit(self.image, self.rect)

豌豆射手类

class PeaShooter(Plant):

def init(self, x, y):

super(PeaShooter, self).init()

self.image = pygame.image.load(‘imgs/peashooter.png’)

self.rect = self.image.get_rect()

self.rect.x = x

self.rect.y = y

self.price = 50

self.hp = 200

self.shot_count = 0

增加射击方法

def shot(self):

should_fire = False

for zombie in MainGame.zombie_list:

if zombie.re

转载请说明出处 内容投诉内容投诉
九幽软件 » 植物大战僵尸的画(植物大战僵尸介绍僵尸的名字)