当前位置: 代码网 > it编程>前端脚本>Python > 用Python写一个植物大战僵尸,找找90后童年的乐趣!

用Python写一个植物大战僵尸,找找90后童年的乐趣!

2024年08月01日 Python 我要评论
系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**

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

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com