会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 134038个问题
JAVA 全系列/第十五阶段:Spring Session会话管理/Spring Session 21961楼

[root@bogon deploy_study]# pip3 install uwsgi==2.0.18 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting uwsgi==2.0.18
  Downloading http://pypi.doubanio.com/packages/e7/1e/3dcca007f974fe4eb369bf1b8629d5e342bb3055e2001b2e5340aaefae7a/uwsgi-2.0.18.tar.gz (801kB)
    100% |████████████████████████████████| 808kB 9.8MB/s 
Installing collected packages: uwsgi
  Running setup.py install for uwsgi ... error
    Complete output from command /usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_lm5vsy4/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-g1ttlatt-record/install-record.txt --single-version-externally-managed --compile:
    /usr/lib64/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'descriptions'
      warnings.warn(msg)
    running install
    using profile: buildconf/default.ini
    detected include path: ['/usr/include', '/usr/local/include']
    Patching "bin_name" to properly install_scripts dir
    detected CPU cores: 2
    configured CFLAGS: -O2 -I. -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_ZLIB -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY -DUWSGI_VERSION="\"2.0.18\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="0" -DUWSGI_VERSION_MINOR="18" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"\"" -DUWSGI_YAML -DUWSGI_SSL -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(ugreen);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(ugreen);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);"
    *** uWSGI compiling server core ***
    [thread 1][gcc -pthread] core/utils.o
    [thread 0][gcc -pthread] core/protocol.o
    [thread 0][gcc -pthread] core/socket.o
    [thread 0][gcc -pthread] core/logging.o
    [thread 1][gcc -pthread] core/master.o
    [thread 1][gcc -pthread] core/master_utils.o
    [thread 0][gcc -pthread] core/emperor.o
    [thread 1][gcc -pthread] core/notify.o
    [thread 0][gcc -pthread] core/mule.o
    [thread 1][gcc -pthread] core/subscription.o
    [thread 0][gcc -pthread] core/stats.o
    [thread 1][gcc -pthread] core/sendfile.o
    [thread 1][gcc -pthread] core/async.o
    [thread 0][gcc -pthread] core/master_checks.o
    [thread 1][gcc -pthread] core/fifo.o
    [thread 0][gcc -pthread] core/offload.o
    [thread 1][gcc -pthread] core/io.o
    [thread 0][gcc -pthread] core/static.o
    [thread 0][gcc -pthread] core/websockets.o
    [thread 1][gcc -pthread] core/spooler.o
    [thread 0][gcc -pthread] core/snmp.o
    [thread 1][gcc -pthread] core/exceptions.o
    [thread 0][gcc -pthread] core/config.o
    [thread 1][gcc -pthread] core/setup_utils.o
    [thread 1][gcc -pthread] core/clock.o
    [thread 0][gcc -pthread] core/init.o
    [thread 1][gcc -pthread] core/buffer.o
    [thread 0][gcc -pthread] core/reader.o
    [thread 1][gcc -pthread] core/writer.o
    [thread 0][gcc -pthread] core/alarm.o
    [thread 1][gcc -pthread] core/cron.o
    [thread 0][gcc -pthread] core/hooks.o
    [thread 1][gcc -pthread] core/plugins.o
    [thread 0][gcc -pthread] core/lock.o
    [thread 1][gcc -pthread] core/cache.o
    [thread 0][gcc -pthread] core/daemons.o
    [thread 0][gcc -pthread] core/errors.o
    [thread 0][gcc -pthread] core/hash.o
    [thread 1][gcc -pthread] core/master_events.o
    [thread 0][gcc -pthread] core/chunked.o
    [thread 1][gcc -pthread] core/queue.o
    [thread 0][gcc -pthread] core/event.o
    [thread 1][gcc -pthread] core/signal.o
    [thread 0][gcc -pthread] core/strings.o
    [thread 1][gcc -pthread] core/progress.o
    [thread 0][gcc -pthread] core/timebomb.o
    [thread 1][gcc -pthread] core/ini.o
    [thread 0][gcc -pthread] core/fsmon.o
    [thread 1][gcc -pthread] core/mount.o
    [thread 0][gcc -pthread] core/metrics.o
    [thread 1][gcc -pthread] core/plugins_builder.o
    [thread 1][gcc -pthread] core/sharedarea.o
    [thread 0][gcc -pthread] core/rpc.o
    [thread 1][gcc -pthread] core/gateway.o
    [thread 0][gcc -pthread] core/loop.o
    [thread 1][gcc -pthread] core/cookie.o
    [thread 0][gcc -pthread] core/querystring.o
    [thread 1][gcc -pthread] core/rb_timers.o
    [thread 0][gcc -pthread] core/transformations.o
    [thread 1][gcc -pthread] core/uwsgi.o
    [thread 0][gcc -pthread] proto/base.o
    [thread 0][gcc -pthread] proto/uwsgi.o
    [thread 0][gcc -pthread] proto/http.o
    [thread 0][gcc -pthread] proto/fastcgi.o
    [thread 0][gcc -pthread] proto/scgi.o
    [thread 1][gcc -pthread] proto/puwsgi.o
    [thread 0][gcc -pthread] lib/linux_ns.o
    [thread 1][gcc -pthread] core/zlib.o
    [thread 0][gcc -pthread] core/yaml.o
    [thread 1][gcc -pthread] core/ssl.o
    [thread 0][gcc -pthread] core/legion.o
    [thread 1][gcc -pthread] core/dot_h.o
    [thread 1][gcc -pthread] core/config_py.o
    *** uWSGI compiling embedded plugins ***
    [thread 1][gcc -pthread] plugins/python/python_plugin.o
    In file included from plugins/python/python_plugin.c:1:
    plugins/python/uwsgi_python.h:2:10: 致命错误:Python.h:没有那个文件或目录
     #include <Python.h>
              ^~~~~~~~~~
    编译中断。
    
    ----------------------------------------
Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_lm5vsy4/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-g1ttlatt-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_lm5vsy4/uwsgi/



图片.png


图片.png


老师,我在安装uwsgi时,出现编译终止,然后报错,我在网上也搜不到

Python全系列/第十二阶段:Python_Django3框架/Django高级 21962楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 21966楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 21967楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 21968楼
JAVA 全系列/第十三阶段:高性能数据处理、NoSQL、分库分表/Redis 21969楼
Python全系列/第一阶段:AI驱动的Python编程/控制语句 21970楼
JAVA 全系列/第十四阶段:分布式文件存储与数据缓存/MongoDB 21971楼

"""
v1.24
    新增功能:
        1.音效处理
"""
# 导入pygame模块
import pygame,time,random

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 500
BG_COLOR = pygame.Color(0, 0, 0)
TEXT_COLOR=pygame.Color(255,0,0)
version="v1.24"
class MainGame():
    window = None
    my_tanke=None
    #存储敌方坦克的列表
    enemyTankeList=[]
    #定义敌方坦克的数量
    enemyTankeCount=5
    #存储我方子弹的列表
    myBulletList=[]
    #存储敌方子弹列表
    enemyBulletList=[]
    #存储爆炸效果列表
    explodeList=[]
    #存储墙壁列表
    wallList=[]
    # 开始游戏
    def startGame(self):
        # 加载主窗口
        # 初始化窗口
        pygame.display.init()
        # 设置窗口的大小及显示
        MainGame.window = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
        #初始化我方坦克
        self.createMyTanke()
        #初始化敌方坦克,并将敌方坦克添加到列表中
        self.createEnemyTanke()
        #初始化墙壁,并讲墙壁添加到列表中
        self.createWalls()
        # 设置窗口的标题
        pygame.display.set_caption("坦克大战"+version)
        while True:
            #使坦克的循环变慢
            time.sleep(0.02)
            # 设置填充色
            MainGame.window.fill(BG_COLOR)
            #获取事件
            self.getEvent()
            #绘制文字
            MainGame.window.blit(self.getTextSuface("敌方坦克剩余数量%d"%len(MainGame.enemyTankeList)),(10,10))
            #调用展示墙壁方法
            self.blitWalls()
            if MainGame.my_tanke and MainGame.my_tanke.live:
                # 调用坦克显示的方法
                MainGame.my_tanke.displayTanke()
            else:
                del MainGame.my_tanke
                MainGame.my_tanke=None
            #循环遍历敌方坦克列表,展示敌方坦克
            self.blitEnemyTanke()
            #调用移动方法
            #如果坦克的开关开启,才可以移动
            if MainGame.my_tanke and MainGame.my_tanke.live:
                if not MainGame.my_tanke.stop:
                    MainGame.my_tanke.move()
                    #调用碰撞墙壁的方法
                    MainGame.my_tanke.hitWalls()
                    MainGame.my_tanke.hitEnemyTanke()
            #调用渲染子弹列表的方法
            self.blitBullet()
            #调用敌方渲染子弹列表的方法
            self.blitEnemyBullet()
            #调用展示爆炸效果的方法
            self.displayExplodes()
            pygame.display.update()
    # 初始化我方坦克,并将我方坦克添加到列表中
    def createMyTanke(self):
        #初始化我方坦克
        MainGame.my_tanke = MyTanke(400,320)
        #创建音乐对象方法
        music=Music("img/start.wav")
        #调用音乐播放的方法
        music.play()
    # 初始化敌方坦克,并将敌方坦克添加到列表中
    def createEnemyTanke(self):
        top=100
        #循环生成敌方坦克
        for i in range(MainGame.enemyTankeCount):
            left=random.randint(0,600)
            speed=random.randint(1,4)
            enemy=EnemyTanke(left,top,speed)
            MainGame.enemyTankeList.append(enemy)
    #初始化墙壁,并将墙壁添加到列表中
    def createWalls(self):
        for i in range(6):
            wall=Wall(130*i,240)
            MainGame.wallList.append(wall)
    def blitWalls(self):
        for wall in MainGame.wallList:
            if wall.live:
                wall.displayWall()
            else:
                MainGame.wallList.remove(wall)
    # 循环遍历敌方坦克列表,展示敌方坦克
    def blitEnemyTanke(self):
        for enemyTanke in MainGame.enemyTankeList:
            if enemyTanke.live:
                enemyTanke.displayTanke()
                #敌方坦克移动的方法
                enemyTanke.randMove()
                #调用敌方坦克与墙壁的碰撞方法
                enemyTanke.hitWalls()
                # 敌方坦克是否撞到我方坦克
                enemyTanke.hitMyTanke()
                #调用敌方坦克的射击
                enemyBullet=enemyTanke.shot()
                #敌方子弹是否是None,如果不为None则添加到敌方子弹列表中
                if enemyBullet:
                     # 将敌方子弹存储到敌方子弹列表中
                     MainGame.enemyBulletList.append(enemyBullet)
            else:
                MainGame.enemyTankeList.remove(enemyTanke)
    #新增方法,展示爆炸效果列表中
    def displayExplodes(self):
        for explode in MainGame.explodeList:
            if explode.live:
                explode.displayExplode()
                music=Music("img/hit.wav")
                music.play()
            else:
                MainGame.explodeList.remove(explode)
    #将我方子弹加入到窗口中
    def blitBullet(self):
        for bullet in MainGame.myBulletList:
            #如果子弹还活着,绘制出来,否则,直接从列表中移除该子弹
            if bullet.live:
                bullet.displayBullet()
                # 让子弹移动
                bullet.bulletMove()
                #调用我方子弹与敌方坦克碰撞的方法
                bullet.myBullet_hit_enemyTanke()
                #调用判段我方子弹是否碰撞到墙壁的方法
                bullet.hit_Walls()
            else:
                MainGame.myBulletList.remove(bullet)
    #将敌方子弹加入到窗口中
    def blitEnemyBullet(self):
        for enemyBullet in MainGame.enemyBulletList:
            # 如果子弹还活着,绘制出来,否则,直接从列表中移除该子弹
            if enemyBullet.live:#判断敌方列表是否存活
                enemyBullet.displayBullet()
                # 让子弹移动
                enemyBullet.bulletMove()
                #调用判段我方子弹是否碰撞到墙壁的方法
                enemyBullet.hit_Walls()
                if MainGame.my_tanke and MainGame.my_tanke.live:
                    enemyBullet.enemyBullet_hit_myTanke()
            else:
                MainGame.enemyBulletList.remove(enemyBullet)
    # 结束游戏
    def endGame(self):
        print("谢谢使用,欢迎再次使用")
        exit()

    #左上角文字的绘制
    def getTextSuface(self,text):
        #初始化字体模块
        pygame.font.init()
        #查看所有的字体名称
        # print(pygame.font.get_fonts())
        #获取字体Font
        font=pygame.font.SysFont("kaiti",18)
        #绘制文字信息
        textSurface=font.render(text,True,TEXT_COLOR)
        return textSurface
    #获取事件
    def getEvent(self):
        #获取所有事件
        eventList=pygame.event.get()
        #遍历事件
        for event in eventList:
            #判断按下的键是关闭还是键盘按下
            #如果按的是退出,关闭窗口
            if event.type==pygame.QUIT:
                self.endGame()
            #如果是键盘的按下
            if event.type==pygame.KEYDOWN:
                # 点击ESC让我方坦克重生
                if event.key == pygame.K_ESCAPE and not MainGame.my_tanke:
                    # 创建我方坦克的方法
                    self.createMyTanke()
                if MainGame.my_tanke and MainGame.my_tanke.live:
                    #判断按下的是上、是下、左、右
                    if event.key==pygame.K_LEFT:
                        #切换方向
                        MainGame.my_tanke.direction="L"
                        #修改坦克的开关状态
                        MainGame.my_tanke.stop=False
                        # MainGame.my_tanke.move()
                        print("按下左键,坦克向左移动")
                    elif event.key==pygame.K_RIGHT:
                        # 切换方向
                        MainGame.my_tanke.direction = "R"
                        # 修改坦克的开关状态
                        MainGame.my_tanke.stop = False
                        # MainGame.my_tanke.move()
                        print("按下右键,坦克向右移动")
                    elif event.key==pygame.K_UP:
                        # 切换方向
                        MainGame.my_tanke.direction = "U"
                        # 修改坦克的开关状态
                        MainGame.my_tanke.stop = False
                        # MainGame.my_tanke.move()
                        print("按下上键,坦克向上移动")
                    elif event.key==pygame.K_DOWN:
                        # 切换方向
                        MainGame.my_tanke.direction = "D"
                        # 修改坦克的开关状态
                        MainGame.my_tanke.stop = False
                        # MainGame.my_tanke.move()
                        print("按下下键,坦克向下移动")
                    elif event.key==pygame.K_SPACE:
                        print("发射子弹")
                        if len(MainGame.myBulletList)<3:
                            # 产生一颗子弹
                            m = Bullet(MainGame.my_tanke)
                            # 将子弹加入到子弹列表
                            MainGame.myBulletList.append(m)
                            music=Music("img/fire.wav")
                            music.play()
                        else:
                            print("子弹数量不足")
                        print("当前屏幕中的子弹数量为:%d"%len(MainGame.myBulletList))
            # 松开方向键,坦克停止移动,修改坦克的开关状态
            if event.type==pygame.KEYUP:
                #判段松开的键是上、下、左、右的时候才停止坦克移动
                if event.key==pygame.K_UP or event.key==pygame.K_DOWN or event.key==pygame.K_LEFT or event.key==pygame.K_RIGHT:
                    if MainGame.my_tanke and MainGame.my_tanke.live:
                        MainGame.my_tanke.stop=True


class BaseItem(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
# 坦克类
class Tanke(BaseItem):
    #添加左边距离left,上边距离top
    def __init__(self,left,top):
        #保存加载的图片
        self.images={"U":pygame.image.load("img/p1tankU.gif"),
                     "D":pygame.image.load("img/p1tankD.gif"),
                     "L":pygame.image.load("img/p1tankL.gif"),
                     "R":pygame.image.load("img/p1tankR.gif"),
        }
        #方向
        self.direction="L"
        #根据当前图片的方向获取图片,图片返回的是surface
        self.image=self.images[self.direction]
        #根据经图片获取区域
        self.rect=self.image.get_rect()
        #设置区域的left和top
        self.rect.left=left
        self.rect.top=top
        # 速度,决定移动的快慢
        self.speed = 5
        #坦克移动的开关
        self.stop=True
        #新增属性live用来记录,坦克是否活着
        self.live=True
        #新增属性,用来记录坦克移动之前的坐标(用于坐标还原使用)
        self.oldLeft=self.rect.left
        self.oldTop=self.rect.top



    # 移动
    def move(self):
        #先记录移动之前的坐标
        self.oldLeft = self.rect.left
        self.oldTop = self.rect.top
        #判断坦克的方向进行移动
        if self.direction=="L":
            if self.rect.left>0:
                self.rect.left -= self.speed
        elif self.direction=="U":
            if self.rect.top>0:
                self.rect.top-=self.speed
        elif self.direction=="D":
            if self.rect.top+self.rect.height<SCREEN_HEIGHT:
                self.rect.top += self.speed
        elif self.direction=="R":
            if self.rect.left+self.rect.height<SCREEN_WIDTH:
                self.rect.left += self.speed
    def stay(self):
        self.rect.left=self.oldLeft
        self.rect.top=self.oldTop
    #新增碰撞墙壁的方法
    def hitWalls(self):
        for wall in MainGame.wallList:
            if pygame.sprite.collide_rect(wall,self):
                self.stay()


    # 射击
    def shot(self):
        return Bullet(self)

    # 展示坦克的方法
    def displayTanke(self):
        #获取展示的对象
        self.image=self.images[self.direction]
        #调用blit方法显示
        MainGame.window.blit(self.image,self.rect)

# 我方坦克类
class MyTanke(Tanke):
    def __init__(self,left,top):
        super(MyTanke, self).__init__(left,top)
    #新增主动碰撞到敌方的坦克的方法
    def hitEnemyTanke(self):
        for enemyTanke in MainGame.enemyTankeList:
            if pygame.sprite.collide_rect(enemyTanke,self):
                self.stay()


# 敌方坦克类
class EnemyTanke(Tanke):
    def __init__(self,left,top,speed):
        super(EnemyTanke, self).__init__(left,top)
        #self.live=True
        #加载图片集
        self.images={
            "U": pygame.image.load("img/enemy1U.gif"),
            "R": pygame.image.load("img/enemy1R.gif"),
            "L": pygame.image.load("img/enemy1L.gif"),
            "D": pygame.image.load("img/enemy1D.gif"),

        }
        #方向,随机生成敌方坦克的方向
        self.direction=self.randDirection()
        #根据方向获取图片
        self.image=self.images[self.direction]
        #区域
        self.rect=self.image.get_rect()
        #对left和top进行赋值
        self.rect.left=left
        self.rect.top=top
        #速度
        self.speed=speed
        #移动开关键
        self.flag=True
        # 新增加一个步数变量 step
        self.step = 60

    # 随机生成敌方坦克的方向
    def randDirection(self):
        num=random.randint(1,4)
        if num==1:
            return "U"
        elif num==2:
            return "L"
        elif num==3:
            return "R"
        elif num==4:
            return "D"
        # 敌方坦克随机移动的方法

    def randMove(self):
        if self.step <= 0:
            # 修改方向
            self.direction = self.randDirection()
            # 让步数复位
            self.step = 60
        else:
            self.move()
            # 让步数递减
            self.step -= 1

    # 重写shot()
    def shot(self):
        # 随机生成100以内的数
        num = random.randint(1, 1000)
        if num < 20:
            return Bullet(self)
    def hitMyTanke(self):
        if pygame.sprite.collide_rect(self,MainGame.my_tanke):
            #让敌方坦克停下来 stay()
            self.stay()

# 子弹类
class Bullet(BaseItem):
    def __init__(self,tanke):
        #加载图片
        self.image=pygame.image.load("img/enemymissile.gif")
        #坦克的方向决定子弹的方向
        self.direction=tanke.direction
        #获取区域
        self.rect=self.image.get_rect()
        #子弹的lef和top与方向有关
        if self.direction=="U":
            self.rect.left=tanke.rect.left+tanke.rect.width/2-self.rect.width/2
            self.rect.top=tanke.rect.top-self.rect.height
        elif self.direction=="D":
            self.rect.left=tanke.rect.left+tanke.rect.width/2-self.rect.width/2
            self.rect.top=tanke.rect.top+self.rect.height
        elif self.direction=="L":
            self.rect.left=tanke.rect.left-tanke.rect.width/2-self.rect.width/2
            self.rect.top=tanke.rect.top+self.rect.width/2-self.rect.width/2
        elif self.direction=="R":
            self.rect.left=tanke.rect.left+tanke.rect.width
            self.rect.top=tanke.rect.top + tanke.rect.width / 2 - self.rect.width / 2
        #子弹的速度
        self.speed=5
        #用来记录子弹是否碰撞
        self.live=True


    # 子弹的移动方法
    def bulletMove(self):
        if self.direction=="U":
            if self.rect.top>0:
                self.rect.top-=self.speed
            else:
                #修改状态值
                self.live=False
        elif self.direction=="D":
            if self.rect.top<SCREEN_HEIGHT-self.rect.height:
                self.rect.top+=self.speed
            else:
                # 修改状态值
                self.live = False
        elif self.direction=="L":
            if self.rect.left>0:
                self.rect.left-=self.speed
            else:
                # 修改状态值
                self.live = False
        elif self.direction=="R":
            if self.rect.left<SCREEN_WIDTH-self.rect.width:
                self.rect.left+=self.speed
            else:
                # 修改状态值
                self.live = False

    # 展示子弹方法
    def displayBullet(self):
        #将图片surface加载到窗口
        MainGame.window.blit(self.image,self.rect)

    #新增我方子弹碰撞敌方坦克的方法
    def myBullet_hit_enemyTanke(self):
        for enemyTanke in MainGame.enemyTankeList:
            if pygame.sprite.collide_rect(enemyTanke,self):
                #产生一个爆炸效果
                explode=Explode(enemyTanke)
                #将爆炸效果加入到爆炸效果列表中
                MainGame.explodeList.append(explode)
                self.live=False
                enemyTanke.live=False

    #新增敌方子弹与我方坦克的碰撞
    def enemyBullet_hit_myTanke(self):
        if pygame.sprite.collide_rect(self,MainGame.my_tanke):
            #产生爆炸效果,并加入到爆炸效果列表中
            explode=Explode(MainGame.my_tanke)
            #修改子弹状态
            # 将爆炸对象添加到爆炸列表中
            MainGame.explodeList.append(explode)
            # 修改敌方子弹与我方坦克的状态
            self.live=False
            #修改我方坦克状态
            MainGame.my_tanke.live=False
    #新增子弹与墙壁的碰撞
    def hit_Walls(self):
        for wall in MainGame.wallList:
            if pygame.sprite.collide_rect(self,wall):
                #修改子弹的活着属性
                self.live=False
                wall.hp-=1
                if wall.hp<=0:
                    wall.live=False




# 墙壁类
class Wall():
    def __init__(self,left,top):
        self.image=pygame.image.load("img/steels.gif")
        self.rect=self.image.get_rect()
        self.rect.left=left
        self.rect.top=top
        #用来判断墙壁是否应该在窗口中展示
        self.live=True
        #用来记录墙壁的生命值
        self.hp=3

    # 展示墙壁方法
    def displayWall(self):
        MainGame.window.blit(self.image,self.rect)


# 爆炸效果类
class Explode():
    def __init__(self,tanke):
        self.rect=tanke.rect
        self.step=0
        self.images=[
            pygame.image.load("img/blast0.gif"),
            pygame.image.load("img/blast1.gif"),
            pygame.image.load("img/blast2.gif"),
            pygame.image.load("img/blast3.gif"),
            pygame.image.load("img/blast4.gif")

        ]
        self.image=self.images[self.step]
        self.live=True

    # 展示爆炸效果方法
    def displayExplode(self):
        if self.step<len(self.images):
            MainGame.window.blit(self.image, self.rect)
            self.image=self.images[self.step]
            self.step+=1
        else:
            self.live=False
            self.step=0


#我方坦克出生
# 音效类
class Music():
    def __init__(self,fileName):
        self.fileName=fileName
        #先初始化混合器
        pygame.mixer.init()
        pygame.mixer.music.load(self.fileName)


    #开始播放音乐的方法
    def play(self):
        pygame.mixer.music.play()


if __name__ == "__main__":
    MainGame().startGame()
    # MainGame().getTextSuface()

tanke – tanke25.py 2021_5_6 20_58_45.png老师,这那错了

Python全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 21973楼
Python全系列/第二阶段:Python 深入与提高/模块 21975楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637