import pygame
import time #循环里面要sleep一下,不然一会儿就将内存占满了
from pygame.locals import \* #检测键盘
import random
import sys #退出系统
#动态的项目,先截个静态图来分析:化动为静,化难为易,一个西瓜切成块,再拼接起来
#拿到一个大项目,首先把项目的各个元素分成一个个的对象,确定对象具备的属性,方法,然后再组装成为一个项目
#玩家类:
#属性:显示窗口、位置、图片、子弹列表、移动状态
#方法:显示、移动、开火,凡是动作类都搞成方法
class player():
def \_\_init\_\_(self,screen):
self.screen=screen#将一个窗口对象作为了属性值
self.x=150
self.y=500
self.img =pygame.image.load("飞机\\\\hero.gif")
self.bullet\_list=\[\]
self.ifmoveright=0#0表示不移动,1表示移动
self.ifmoveleft=0
def display(self):
self.screen.blit(self.img,(self.x,self.y))
print()
for f in self.bullet\_list:
f.move()
f.display()
if f.y<=0:
self.bullet\_list.remove(f)
def move(self):
if self.ifmoveleft==1 and self.x>=-30:
self.x-=20
if self.ifmoveright==1 and self.x<=270:
self.x+=20