求助求助
1.主程序import sys
import pygame
from settings import Setting as st
from ship import *
import game_functions as gf
def run_game():
"""初始化游戏 并创建一个1200x800的一个屏幕对象"""
pygame.init()
#创建一个seings的实例对象
setting = st()
screen = pygame.display.set_mode((setting.screen_width,setting.screen_height))
pygame.display.set_caption("liuxingyu")
#设置背景颜色
#创建一个飞船吧
ship = Ship(screen)
while True:
#监视鼠标和键盘事件
gf.check_events(ship)
#for event in pygame.event.get():
#if event.type == pygame.QUIT:
#pygame.quit()
#sys.exit()
ship.update()
#每次循环都重绘屏幕
screen.fill(setting.be_color)
ship.blitem()
#让最近的屏幕刷新可见
pygame.display.flip()
run_game()
2.ship
import pygame
class Ship():
def __init__(self,screen):
#初始化飞船并为其设置开始位置
self.screen =screen
#加载飞船的图片并设置其接近矩形
self.airship='F://python//alien_invasion//images//ship.bmp'
self.image = pygame.image.load(self.airship)
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
#这个函数表示显示一个suface 而我们将suface存放在self.image中
#将每架飞船存放在屏幕底部中央
self.rect.centerx =self.screen_rect.centerx
self.rect.bottom =self.screen_rect.bottom
#移动标志
self.move_right = False
self.move_left = False
def update(self):
if self.move_right:
self.rect.centerx +=1
if self.move_right:
self.rect.centerx -=1
def blitem(self):
#在指定的地方生成一个飞机
self.screen.blit(self.image,self.rect)
3.响应键盘和鼠标的模块
import pdb
import sys
import pygame
def check_events(ship):
"""响应鼠标和键盘的事件"""
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_RIGHT:
ship.move_right = True
elif event.key == pygame.K_LEFT:
ship.move_left = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
ship.move_right = False
elif event.key == pygame.K_LEFT:
ship.move_left = False
4. ??? 求助啥啊
页:
[1]