• Python游戏嗷大喵快跑设计


    全套资源下载地址:https://download.csdn.net/download/sheziqiong/86774416
    全套资源下载地址:https://download.csdn.net/download/sheziqiong/86774416
    目 录
    1 引言 1
    1.1 选题背景及意义 1
    1.2 国内外研究现状 1
    1.3 开发目标 2
    2 技术简介 2
    2.1 开发环境 2
    2.2 Python 2
    3 需求分析 2
    3.1 可行性分析 2
    3.1.1 硬件以及技术的可行性 2
    3.1.2 运行可行性分析 2
    3.2 功能性需求分析 2
    3.2.1 功能描述 2
    4 系统设计 3
    4.1 总体设计 3
    4.2 详细设计 3
    5 系统实现 3
    5.1 创建精灵 3
    5.2 创建滚动地图 5
    5.3 加载音频 5
    6 系统测试 7
    6.1 测试目的 7
    6.2 测试技术 7
    6.3 测试模块 7
    6.4 测试结果 7
    结束语 8
    致谢 10
    3 需求分析
    3.1 可行性分析
    3.1.1 硬件以及技术的可行性
    装有pycharm软件的电脑,直观的游戏图形界面,技术不是很复杂,所以技术上没问题是可行的。
    3.1.2 运行可行性分析
    玩家操作简单,对于玩家的游戏体验没有的问题。
    3.2 功能性需求分析
    3.2.1 功能描述
    本节通过对于用户的需求进行分析,首先思考到用户在使用这款游戏的时候,会想到这款应用的操作性,所以,在开发的时候我们把操作写的很简单
    4 系统设计
    4.1 总体设计
    游戏中一共有嗷大喵,恶龙,火焰,爆炸动画和果实(就是上方蓝色的矩形块)这几种精灵。这里我们使用到MyLibrary.py。上述这几个精灵都是 MySprite类实例化的对象。
    为了方便管理。我们建立了几个精灵组,本文转载自http://www.biyezuopin.vip/onews.asp?id=9642并且将一些精灵塞到了里面。

    4.2 详细设计
    创建精灵:
    创建精灵组
    创建怪物精灵
    创建爆炸动画
    创建玩家精灵
    创建子弹精灵
    创建滚动地图:
    定义一个滚动地图类
    创建地图对象
    加载音频:
    初始化音频模块
    加载音频文件
    播放音乐
    人物的跳跃
    跳跃函数

    # MyLibrary.py
    
    import sys, time, random, math, pygame
    from pygame.locals import *
    
    
    # 使用所提供字体打印文本
    def print_text(font, x, y, text, color=(255,255,255)):
        imgText = font.render(text, True, color)
        screen = pygame.display.get_surface() #req'd when function moved into MyLibrary
        screen.blit(imgText, (x,y))
    
    # MySprite class extends  pygame.sprite.Sprite
    #继承了sprite
    class MySprite(pygame.sprite.Sprite):
        
        def __init__(self):
            pygame.sprite.Sprite.__init__(self) # extend the base Sprite class
            self.master_image = None
            self.frame = 0
            self.old_frame = -1
            self.frame_width = 1
            self.frame_height = 1
            self.first_frame = 0
            self.last_frame = 0
            self.columns = 1
            self.last_time = 0
            self.direction = 0
            self.velocity = Point(0.0,0.0) 
    
        # X property
        def _getx(self): return self.rect.x
        def _setx(self,value): self.rect.x = value
        X = property(_getx,_setx)
    
        # Y property
        def _gety(self): return self.rect.y
        def _sety(self,value): self.rect.y = value
        Y = property(_gety,_sety)
    
        # position property
        def _getpos(self): return self.rect.topleft
        def _setpos(self,pos): self.rect.topleft = pos
        position = property(_getpos,_setpos)
    
    
        # load方法中定义了图片位置 长宽和帧的列数,由此来将素材切成一帧一帧
        def load(self, filename, width, height, columns):
            self.master_image = pygame.image.load(filename).convert_alpha()
            self.frame_width = width
            self.frame_height = height
            self.rect = Rect(0,0,width,height)
            self.columns = columns
            # try to auto-calculate total frames
            # 尝试自动计算总帧数
            rect = self.master_image.get_rect()
            self.last_frame = (rect.width // width) * (rect.height // height) - 1
    
        def update(self, current_time, rate=30):
            # update animation frame number
            # 更新帧数
            if current_time > self.last_time + rate:
                self.frame += 1
                if self.frame > self.last_frame:
                    self.frame = self.first_frame
                self.last_time = current_time
    
            # build current frame only if it changed
            if self.frame != self.old_frame:
                frame_x = (self.frame % self.columns) * self.frame_width
                frame_y = (self.frame // self.columns) * self.frame_height
                rect = Rect(frame_x, frame_y, self.frame_width, self.frame_height)
                self.image = self.master_image.subsurface(rect)
                self.old_frame = self.frame
    
        def __str__(self):
            return str(self.frame) + "," + str(self.first_frame) + \
                   "," + str(self.last_frame) + "," + str(self.frame_width) + \
                   "," + str(self.frame_height) + "," + str(self.columns) + \
                   "," + str(self.rect)
    
    # Point class
    class Point(object):
        def __init__(self, x, y):
            self.__x = x
            self.__y = y
    
        # X property
        def getx(self): return self.__x
        def setx(self, x): self.__x = x
        x = property(getx, setx)
    
        # Y property
        def gety(self): return self.__y
        def sety(self, y): self.__y = y
        y = property(gety, sety)
    
        def __str__(self):
            return "{X:" + "{:.0f}".format(self.__x) + \
                ",Y:" + "{:.0f}".format(self.__y) + "}"
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    全套资源下载地址:https://download.csdn.net/download/sheziqiong/86774416
    全套资源下载地址:https://download.csdn.net/download/sheziqiong/86774416

  • 相关阅读:
    拦截器与过滤器的区别
    判断测试结束的标准有哪些?
    测试用例的编写(面试常问)
    服务器搭建(TCP套接字)-基础版(客户端)
    【记录】数据透视表
    通过Selenium批量填写问卷
    双十二蓝牙耳机啥牌子好?2022年度热销蓝牙耳机排名
    分享篇:初识Canvas
    MySQL Explain性能调优详解
    玉米社:如何做好企业SEM竞价推广?数据分析不能少
  • 原文地址:https://blog.csdn.net/sheziqiong/article/details/127345700