tina -飛機大戰4.0

import pygame
import sys
import plane
import enemy


def key_control(hero):
    # event 事件:電腦監控們對電腦的每一次操作,包括鼠標移動,按鍵
    for shi_jian in pygame.event.get():
        # 判斷我們有沒有點擊退出
        if shi_jian.type == pygame.QUIT:
            sys.exit()
        # 判斷我們有沒有按鍵 Key
        elif shi_jian.type == pygame.KEYDOWN:
            print("你按鍵啦!!!!")
            if shi_jian.key == pygame.K_UP:
                hero.move_up()
            elif shi_jian.key == pygame.K_DOWN:
                hero.move_down()
            if shi_jian.key == pygame.K_RIGHT:
                hero.move_right()
            elif shi_jian.key == pygame.K_LEFT:
                hero.move_left()


def main():
    # 初始化,加載一些文件進來
    pygame.init()
    # 遊戲需要做一個窗口  dis 分開 play 玩  diaplay展覽
    chuang_kou = pygame.display.set_mode((400, 700))
    # 遊戲標題
    pygame.display.set_caption("反基督者")
    # 新建一個戰機對象、
    hero = plane.plane(chuang_kou)
    # 新建一個敵機對象、
    badegg = enemy.enemy(chuang_kou)
    # append
    # 設置電腦美過多少毫秒響應一次參數
    pygame.key.set_repeat(1,1)
    background = pygame.image.load("background.png")
    while True:
        key_control(hero)
        # 將圖片放到窗口上
        chuang_kou.blit(background, (0, 0))
        badegg.show()
        badegg.move_down()
        hero.show()
        # 刷新  up上date日期  update 升級,刷新
        pygame.display.update()


if __name__ == '__main__':
    main()

import pygame

# 戰機圖紙
class plane:
    # 魔法方法,記錄屬性
    def __init__(self,ck):
        self.x = 200
        self.y = 200
        self.picture = pygame.image.load("hero1.png")
        self.chuang_kou = ck

    def move_up(self):
        self.y -= 10
        if self.y < -124:
            self.y = 700

    def move_down(self):
        self.y += 10
        if self.y > 700:
            self.y = -120

    def move_right(self):
        self.x += 10
        if self.x > 350:
            self.x = 295

    def move_left(self):
        self.x -= 10
        if self.x < -10:
            self.x = 5

    def show(self):
        self.chuang_kou.blit(self.picture, (self.x, self.y))


import pygame

# 戰機圖紙
class enemy:
    # 魔法方法,記錄屬性
    def __init__(self,ck):
        self.x = 0
        self.y = 0
        self.picture = pygame.image.load("enemy-1.gif")
        self.chuang_kou = ck

    def move_down(self):
        self.y += 10
        if self.y > 700:
            self.y = -120

    def show(self):
        self.chuang_kou.blit(self.picture, (self.x, self.y))







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章