harry 飛機大戰2

2021-10-01 22:41:11 字數 1263 閱讀 4505

# 1。0  載入背景

# 2。0 載入飛機

# 3,0 監控滑鼠鍵盤操作並且控制飛機移動

import random

import pygame

import sys

defmain()

:# 1,建立視窗

screen = pygame.display.set_mode(

(480

,852),

0,32)

# 2.建立乙個背景: 1.load 匯入 2.blit 放到螢幕上

background = pygame.image.load(

'background.png'

) plane = pygame.image.load(

'hero1.png'

) planex =

210 planey =

300while

true

:# event 事件,我們對電腦的每一種操作,例如按鍵,按滑鼠,移動滑鼠

for event in pygame.event.get():

if event.

type

== pygame.quit:

pygame.quit(

) sys.exit(

)elif event.

type

== pygame.keydown:

# 往左

if event.key == pygame.k_a or event.key == pygame.k_left:

planex -=

5if planex <-20

: planex =

5elif event.key == pygame.k_d:

planex +=

5# # 修改飛機的x座標

# planey += 1

# planex += 1

screen.blit(background,(0

,0))

# 把背景放在視窗上

screen.blit(plane,

(planex,planey)

)# 確定飛機的位置,控制飛機的座標

pygame.display.update(

)if __name__ ==

'__main__'

: main(

)

harry 飛機大戰

1.0 import pygame 匯入pygame工具包 pygame.init 初始化 plane rect pygame.rect 100,500,120,125 1 x座標 2 y座標來確定位置 3 寬度和4 高度來確定大小 scr pygame.display.set mode 480 7...

boren 飛機大戰2

import pygame import sys back 返回,後面 ground 地面 哪一行 確定戰機的位置,27行,用座標確定戰機位置 型別 1。初始化 defzhu pygame.init 2。設定乙個視窗 chuangkou pygame.display.set mode 400 700...

python入門實戰 飛機大戰(2)

目標 使用面相物件設計飛機大戰遊戲類 根據明確的職責,設計planegame類如下 外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳 img 3yfapo4n 1592320505799 media 15025159832322 009 e6 b8 b8 e6 88 8f e4 b8 bb...