使用pygame 寫(xiě)一個(gè)飛機(jī)大戰(zhàn)游戲 但是只寫(xiě)出了一個(gè)飛機(jī)界面
import pygame
from color import Color
from add_picture import add_pic
from add_picture import add_text
pygame.init()
window = pygame.display.set_mode((400, 600)) #設(shè)置屏幕大小
window.fill((255, 255, 255)) #填充顏色
# =======================================================================
image_obj1 = pygame.image.load('file/background.png') # 標(biāo)題
image_obj2 = pygame.image.load('file/background.png') # 標(biāo)題
# image_obj3 = pygame.image.load('file/game_loading2.png') # 標(biāo)題
# # image_obj3 = ('file/game_loading2.png', (180, 360), angle=90, scale=0.8)
y1 = 0
y2 = -880
while True:
window.blit(image_obj2, (0, y2)) # 渲染位置
pygame.display.update() # 重新顯示
y2 += 1
if y2 == 0:
y2 = -880
window.blit(image_obj1, (0, y1))# 渲染位置
pygame.display.update() # 重新顯示
y1 += 1
if y1 == 880:
y1 = 0
# window.blit(image_obj3, (180, 360)) # 渲染位置
# pygame.display.update() # 重新顯示
add_pic('file/title.png', (93, 100), scale=0.5) # 標(biāo)題
add_pic('file/enemy1_5.png', (80, 200), scale=0.8) # 敵機(jī)1
add_pic('file/enemy1_5.png', (320, 260), scale=0.8) # 敵機(jī)2
add_pic('file/enemy2.png', (300, 40), scale=0.6) # 敵機(jī)3
add_pic('file/game_resume_nor.png', (100, 450), scale=0.8) # 開(kāi)始按鈕
pygame.draw.rect(window, (190, 190, 190), (90, 450, 220, 40)) # 創(chuàng)建矩形邊框
add_text('file/aa.ttf', 30, 'Start Game', (255, 0, 0), (140, 450))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()