qiyuan -震惊,马化腾为了这游戏坐公交,原因竟然是。。。

# 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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值