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
5 时间计数器
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 为一个 surface
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
6 发射计数器
self.shot_count = 0
增加射击方法
def shot(self):
6 记录是否应该射击
should_fire = false
for zombie in maingame.zombie_list:
if zombie.rect.y
发表评论