# 1。导包
import pygame
# 类
"""
类名:feiji
属性:位置x,y;皮肤;血量
方法: show, move
"""
class feiji:
def __init__(self, CK):
self.x = 250
self.y = 500
self.pifu = pygame.image.load("hero1.png")
self.blood = 3
self.chuangkou = CK
def show(self):
self.chuangkou.blit(self.pifu, (self.x, self.y))
# 向左
def move_left(self):
self.x = self.x - 10
def move_right(self):
self.x = self.x + 10
"""
类名:子弹
属性:位置x,y;皮肤;血量
方法: show
"""
class zidan:
def __init__(self,CK):
self.x = 250
self.y = -500
self.pifu = pygame.image.load("enemy-3.gif")
self.chuangkou = CK
def show(self):
self.chuangkou.blit(self.pifu, (self.x, self.y))
def move(self):
self.y = self.y+100
# 敌机
"""
类名:diji
属性:位置x,y;皮肤;血量
方法: show, move
"""
class diji:
def __init__(self, CK):
self.x = 250
self.y = 0
self.pifu = pygame.image.load("enemy-1.gif")
self.chuangkou = CK
self.direction = "left"
def show(self):
self.chuangkou.blit(self.pifu, (self.x, self.y))
def move(self):
if self.direction == "left":
self.x = self.x - 10
elif self.direction == "right":
self.x = self.x + 10
if self.x < 0:
self.direction = "right"
elif self.x > 400:
self.direction = "left"
def key_control(hero):
# 判断我们是否点红叉了
# 事件
for shi_jian in pygame.event.get():
if shi_jian.type == pygame.QUIT:
pygame.quit()
if shi_jian.type == pygame.KEYDOWN:
if shi_jian.key == pygame.K_a:
hero.move_left()
elif shi_jian.key == pygame.K_d:
hero.move_right()
def main():
# 2。初始化
pygame.init()
# 3。设置窗口大小
chuang_kou = pygame.display.set_mode((400, 700))
# 4。设置标题
pygame.display.set_caption("米奇妙妙屋")
# 1.导入图片
background = pygame.image.load("background.png")
# 6。刷新 120 hz 1080 hz 显卡 计算画面
# 7. 新建对象:战机,敌机
伞兵一号 = feiji(chuang_kou)
炮灰一号 = diji(chuang_kou)
boss = zidan(chuang_kou)
while True:
key_control(伞兵一号)
chuang_kou.blit(background, (0, 0))
伞兵一号.show()
炮灰一号.show()
炮灰一号.move()
boss.show()
boss.move()
pygame.display.update()
# 5。退出游戏
pygame.quit()
if __name__ == '__main__':
main()
qiyuan -震惊,马化腾为了这游戏坐公交,原因竟然是。。。
最新推荐文章于 2020-09-03 10:28:00 发布