您当前的位置: 首页 >  Python

80 python - 打飞机案例(代码优化-抽象出基类)

杨林伟 发布时间:2019-08-17 11:18:18 ,浏览量:2

#coding=utf-8
import time
import random
import pygame
from pygame.locals import *

class Base(object):
    def __init__(self,screen,name):
        self.name = name
        #设置要显示内容的窗口
        self.screen = screen


class Plane(Base):
    def __init__(self,screen,name):
        super().__init__(screen,name)
        self.image = pygame.image.load(self.imageName).convert()
        #用来存储英雄飞机发射的所有子弹
        self.bulletList = []

    def display(self):
        #更新飞机的位置
        self.screen.blit(self.image,(self.x,self.y))
        #判断一下子弹的位置是否越界,如果是,那么就要删除这颗子弹
        #
        #这种方法会漏掉很多需要删除的数据
        # for i in self.bulletList:
        #     if i.y480-50:
            self.direction = "left"
        elif self.x890 or self.y            
关注
打赏
1688896170
查看更多评论
0.1025s