funcode_微信版打飞机Funcode

上传人:仙*** 文档编号:87907985 上传时间:2022-05-10 格式:DOC 页数:22 大小:178KB
返回 下载 相关 举报
funcode_微信版打飞机Funcode_第1页
第1页 / 共22页
funcode_微信版打飞机Funcode_第2页
第2页 / 共22页
funcode_微信版打飞机Funcode_第3页
第3页 / 共22页
点击查看更多>>
资源描述
.FunCode游戏开发设计文档微信版打飞机编写:2017年5月18日目录一、问题定义1二、实验准备1三、可行性分析2四、用例图及类图设计2五、时序图设计与流程描述25.1 游戏初始化25.2键盘相关函数设计25.3 游戏运行相关设计25.4 碰撞函数设计25.5 游戏完毕设计2六、编码与实现2Plane 类2Player类2EnemyPlane类2Bullet类2PlaneItem类2SpriteFactory类2PlaneGame类2EnumDefine类2Lesson*类2. .一、问题定义开发一款微信打飞机的小游戏,实现自己飞机击毁敌机得分,吃到加血物品加血,吃到加魔的物品加魔,魔到一定值时可以通过吃掉相应物品在一定时间获得不同的子弹发射方式和飞机移动速度。规则如下:1.按下空格键游戏开场。2.通过WSAD 键控制玩家飞机移动上下左右移动,但不能飞出边境。3.玩家飞机每隔一段时间自动发射一发炮弹。4.玩家飞机被敌机碰到后,生命值会减少,生命值变为0的时候,游戏完毕。5.在游戏上方会一直出现电脑飞机敌机,敌机分为大、中、小三种类型,越小的飞机出现的几率越大。6.敌机被玩家飞机击中后,生命值会减少,生命值变为0时,该敌机被摧毁,玩家得分。越大的飞机越难击毁,击毁后玩家得分也越多。7.敌机飞到界面下方时,删除敌机。8.在界面外用一个文本显示玩家游戏得分。二、实验准备翻开FunCode,创立一个新的C+工程。注意:工程名称必须为英文和数字,且不能有空格。点击工程导入地图模板,从对话框中选取名称为WarPlane的模板导入。导入成功后,界面如下:查看模板设置。模板设置中有如下几点,在工程开发时需要用到:精灵的名称,创立精灵对象时,通过精灵名称把对象和精灵图片绑定在一起。玩家飞机的点,右下列图鼠标点击的位置就是玩家飞机的点,飞机发散子弹时,位置应该在点前方位置。子弹的碰撞边界的设定,把碰撞边界设置在图片中的有颜色区域,这样敌方飞机实际是碰撞到子弹图片的有颜色区域才发生碰撞事件,从而是游戏效果更逼真。在场景预览窗口中,点击游戏屏幕之外的区域,然后在编辑面板中修改窗口大小,该属性用来设置游戏运行时屏幕大小。屏幕位置中的宽高则是用来设置场景预览窗口中可见区域的大小。按下列图进展设置。也可以自行调整这两个区域大小,以及图片大小,从而到达最正确效果。三、可行性分析FunCode作为一个功能比拟简单,封装的库函数不多的,游戏开发引擎,上手比拟容易,对于开发平台的性能要求也不高,符合技术可行性和系统可行性。四、用例图及类图设计玩家控制飞机移动,飞机自动发射子弹,然后游戏一直循环,当飞机HP归0时游戏完毕。飞机类作为其他所有和飞机相关类的基类,PlaneGame类是控制类,这个游戏的主要实现在PlaneGame类中完成。包括设定子弹、开火、删除已摧毁精灵、通过名字获得精灵、播放动画、创立敌机、创立物品等动作。类的具体定义如下:飞机类:Plane 继承自CSprite类属性private int iHP飞机生命值private float fPoint*飞机当前位置中心点的*坐标private float fPointY飞机当前位置中心点的Y坐标private float fSpeed*飞机*轴方向移动速度private float fSpeedY飞机Y轴方向移动速度方法public int getHP()获取飞机生命值public void setHP(int hp)根据参数设置飞机生命值public float getPoint*()获得飞机的*坐标public void setPoint*(int *)设置飞机的*坐标public float getPointY()获得飞机的Y坐标public void setPointY(int y)设置飞机的Y坐标public float getMoveSpeed*()获得飞机*轴方向上速度public void setMoveSpeed*(float speed*)设置飞机*轴方向上速度public float getMoveSpeedY()获得飞机Y轴方向上速度public void setMoveSpeedY(float speedY)设置飞机Y轴方向上速度敌方飞机类:EnemyPlane 继承自Plane类属性private int iValue敌机价值,即玩家飞机击毁敌机后可获得分数private int iType飞机类型。0 大型敌机 1 中型敌机 2 小型敌机方法public int getValue()获取敌机价值public void setValue(int value)设置敌机价值public int getPlaneType()获取敌机类型public void setPlaneType(int planeType)设置敌机类型玩家飞机类:Player 继承自Plane类属性private int iScore玩家得分private float fFireTime玩家发射子弹的时间间隔,可理解为安装子弹需要的时间private float fUsedTime玩家飞机安装子弹已经用去的时间private int iMp魔抗值private bool flag标志位方法public int getScore()获取玩家得分public void setScore(int score)设置玩家得分public float getFireTime()获取玩家子弹发射间隔public void setFireTime(float fireTime)设置玩家子弹发射间隔public float getUsedTime()获取玩家飞机装弹已用时间public void setUsedTime(float usedTime)设置玩家飞机装弹已用时间public void move()玩家飞机移动public void stopMove(int hp)忘记飞机停顿移动public void fire()玩家飞机发射子弹public int getMP()获得魔抗public void setMP(int mp)设置魔抗public bool getflag()获得标志位public void setflag()设置标志位子弹类:Bullet 继承自Plane类属性private int iDamage子弹伤害值方法public int getiDamage()获取子弹伤害值public void setiDamage (int val)设置子弹伤害值精灵工厂类:SpriteFactory属性private static int iId静态成员变量。缺省值为0,每复制一个精灵时递增一次,用于作为新生成的精灵名称的后缀。例如:plane1, plane2, bullet3方法public CSprite *getSprite(int type)获取生产出的精灵。type:0 大型敌机 1 中型敌机 2 小型敌机 3 玩家飞机 4 子弹5,6,7,8,9 物品private static Player *createPlayer()创立玩家飞机对象private static EnemyPlane *createEnemyPlane(const int iType)创立敌方飞机对象private static Bullet *createBullet()玩家子弹精灵对象private static PlaneItem *createItem(const int iType)飞机游戏类:PlaneGame属性private static PlaneGame *pGame游戏对象private CTe*tSprite *pTe*tScore显示玩家得分的文本精灵private CTe*tSprite *pTe*tHp显示玩家生命值的文本精灵private CTe*tSprite *pTe*tMp显示玩家魔抗值的文本精灵private Player *pPlayer玩家飞机private List spriteList精灵集合private float fCreateEnemyTime生成一架新敌机的时间间隔,即生产一架新敌机需要的时间private float fUsedEnemyTime生产一架新敌机已经用去的时间private float fCreateItemTime生成一个物品的时间间隔,即生产一个物品需要的时间private float fUsedItemTime生产一个物品已经用去的时间private float fMPTime魔法能持续的时间private float fMPUsedTime魔法已经持续的时间private int bulletType子弹的类型private float speed飞机加速后的速度方法private PlaneGame()单例模式的做法,构造函数是私有的,用户不能直接创立该类对象public static PlaneGame *getPlaneGame()用户只能通过该方法获得PlaneGame对象,且对象为同一个public CSprite *getSpriteByName(const char* name)通过名称从集合中获取精灵敌方飞机、子弹public void setTe*tScore(int score)设置显示玩家得分的文本精灵对象public void setTe*tHp(int hp)设置显示玩家血量的文本精灵对象public void setTe*tMp(int mp)设置显示玩家魔抗的文本精灵对象public int getBulletType()获得子弹类型public void setBulletType(float time)根据时间设置子弹类型public void setBulletType(int type)设置子弹类型public float getfMPTime()获得魔抗能持续的时间间隔public void setfMPTime(float val)设置魔抗能持续的时间间隔public float getfMPUsedTime()获得魔抗已经持续的时间void setfMPUsedTime(float val)设置魔抗已经持续的时间public Player *getPlayer()获得玩家飞机public void setPlayer(Player *myPlane)设置玩家飞机public float getEnemyPlaneCreateTime()获得产生一架敌机的时间间隔public void setEnemyPlaneCreateTime (float createTime)设置产生一架敌机的时间间隔public float getEnemyPlaneUsedTime()获得生产一架敌机已经用去的敌机public void setEnemyPlaneUsedTime(float usedTime)设置生产一架敌机已经用去的敌机public List getEnemyPlaneList()获得敌机集合public List getBulletList()获得子弹集合public void playerFire(float time,int type)玩家飞机每隔一段时间发散一发子弹。参数time是屏幕每次刷新的时间public void destroyDeadSprites()从精灵集合中删除HP=0的精灵public void creatNewEnemyPlane(float time)每隔一段时间创立一架敌方飞机。参数time是屏幕每次刷新的时间public void creatNewItemPlane(float Time)每隔一段时间创立一个物品。参数time是屏幕每次刷新的时间public void destroyPlayer()删除玩家飞机public void playE*plodeAnimation(float *, float y)播放爆炸动画,参数是要爆炸的精灵当前所在位置坐标public void setspeed(float ispeed)设置子弹加速的速度public float getspeed()获得子弹加速的速度常量值类:EnumDefine属性Public static int BIG_ENEMY = 0 大型敌机public static int MEDIUM_ENEMY = 1中型敌机public static int SMALL_ENEMY = 2小型敌机public static int PLAYER_PLANE = 3玩家飞机public static int BULLET = 4子弹public static int HP = 5加血public static int MP = 6加魔抗public static int BULLET1 =7子弹1public static int BULLET2 = 8子弹2public static int BULLETSPEED = 9加速Public static int BIG_ENEMY_VALUE = 10 打掉大飞机的玩家得分Public static int MEDIUM_ENEMY _VALUE= 5打掉中飞机的玩家得分public static int SMALL_ENEMY _VALUE= 2打掉小飞机的玩家得分public static int BULLET_DAMAGE = 1子弹伤害public static int PLAYER_HP = 1玩家血量public static float PLAYER_SPEED = 30玩家速度public static float BULLET_SPEED = 50子弹速度public static float BIG_ENEMY_SPEED = 5大飞机速度public static float MEDIUN_ENEMY_SPEED = 10中飞机速度public static float SMALL_ENEMY_SPEED = 20小飞机速度public static float HP_SPEED = 20加血速度public static float MP_SPEED = 20加魔速度public static float BULLET1_SPEED = 20子弹1速度public static float BULLET2_SPEED = 20子弹2速度public static float BULLETSPEED_SPEED = 20飞机加速速度五、时序图设计与流程描述5.1 游戏初始化从PlaneGame中后的一个单例模式的PlaneGame对象,产生玩家飞机,把玩家飞机放到PlaneGame的对象pGame中。5.2键盘相关函数设计键盘按下有两种情况,如果游戏状态为0并且按下的是空格,就把游戏状态设为1,如果游戏状态是2并且按下的为WASD这几个键,则就给玩家飞机设置速度让其移动。键盘松开就把玩家飞机速度归05.3 游戏运行相关设计游戏运行的主过程,先更新玩家的得分、MP值和HP值,如果HP=0游戏完毕。然后设置子弹的类型,飞机自动开火。在列表中删除已经被摧毁的精灵,生成新的敌机和新的物品。对于子弹开火的函数,先判断生成子弹易用的时间是否大于等于需要的时间,然后根据子弹的类型选择哪几个点,然后获取点坐标,设置为子弹的坐标,然后把子弹对象放入集合,将生成子弹已用的时间归0。在集合中循环删除精灵,先获得HP值,判断是否大于0,对于小于等于0的精灵,如果是敌机,就给玩家加分,然后删除敌机,播放动画。如果是子弹,就直接删除。如果是物品,就直接删除。根据坐标设置动画精灵的坐标,设置时长,播放动画。如果生成一架敌机的已用时间大于等于需要时间,就从精灵工程中获得一架新的飞机,这里通过生成随机数,在1-50之间时,就生产小型敌机;在51-80之间时,就生产中型敌机;在81-100之间时,就生产大型敌机。如果生成一个物品的已用时间大于等于需要时间,就从精灵工程中获得一个新的物品,这里通过生成随机数,在1-10之间时,就生产加血物品;在11-30之间时,就生产加魔物品;在31-50之间时,就生产子弹1;在51-80之间时,就生产子弹2;在81-100之间时,就生产飞机加速。5.4 碰撞函数设计如果玩家与敌机碰撞,敌机HP归0,玩家HP-1,如果敌机与子弹碰撞,子弹HP归0,敌机HP-1。如果玩家与物品碰撞,物品HP归0,加血则玩家HP+1,加魔则玩家MP+1,子弹1则改变子弹类型为1,子弹2则改变子弹类型为2,飞机加速则改变玩家速度。如果游戏状态为2,且与世界边界碰撞的是敌机、子弹或者物品,则删除精灵。5.5 游戏完毕设计删除玩家飞机、被摧毁的敌机,然后清空精灵集合。六、编码与实现Plane 类#include monClass.hclassPlane:publicCSpritepublic:Plane(constchar*name);virtualPlane();intgetHP()returniHP;voidsetHP(inthp)iHP=hp;floatgetPoint*()fPoint*=GetSpritePosition*();returnfPoint*;voidsetPoint*(float*)fPoint*=*;SetSpritePosition*(*);floatgetPointY()fPointY=GetSpritePositionY();returnfPointY;voidsetPointY(floaty)fPointY=y;SetSpritePositionY(y);floatgetMoveSpeed*()returnfSpeed*;voidsetMoveSpeed*(floatspeed*)fSpeed*=speed*;SetSpriteLinearVelocity*(speed*);floatgetMoveSpeedY()returnfSpeedY;voidsetMoveSpeedY(floatspeedY)fSpeedY=speedY;SetSpriteLinearVelocityY(speedY);protected:private:intiHP;floatfPoint*;floatfPointY;floatfSpeed*;floatfSpeedY;Player类#include Plane.hclassPlayer:publicPlanepublic:Player(constchar*name);virtualPlayer();intgetMP()returniMp;voidsetMP(intmp)iMp=mp;intgetiScore()returniScore;voidsetiScore(intval)iScore=val;floatgetfFireTime()returnfFireTime;voidsetfFireTime(floatval)fFireTime=val;floatgetfUsedTime()returnfUsedTime;voidsetfUsedTime(floatval)fUsedTime=val;voidMove();voidstopMove(inthp);voidfire();boolgetflag()returnflag;voidsetflag()if(flag)flag=false;elseflag=true;protected:private:intiMp;intiScore;floatfFireTime;floatfUsedTime;boolflag;EnemyPlane类#include classEnemyPlane:publicPlanepublic:EnemyPlane(constchar*name);virtualEnemyPlane();intgetiValue()returniValue;voidsetiValue(intval)iValue=val;intgetiType()returniType;voidsetiType(intval)iType=val;protected:private:intiValue;intiType;Bullet类#include Plane.hclassBullet:publicPlanepublic:Bullet(constchar*name);virtualBullet();intgetiDamage()returniDamage;voidsetiDamage(intval)iDamage=val;protected:private:intiDamage;PlaneItem类#include Plane.hclassPlaneItem:publicPlanepublic:PlaneItem(constchar*name);virtualPlaneItem();intgetiType()returniType;voidsetiType(constinttype)iType=type;protected:private:intiType;SpriteFactory类#include monClass.h#include Plane.h#include Player.h#include EnemyPlane.h#include Bullet.h#include PlaneItem.hclassSpriteFactorypublic:SpriteFactory();virtualSpriteFactory();staticCSprite*getSprite(inttype);staticvoidInit();protected:private:staticPlayer*createPlayer();staticEnemyPlane*createEnemyPlane(constintiType);staticBullet*createBullet();staticPlaneItem*createItem(constintiType);staticintiID;PlaneGame类#include monClass.h#include Plane.h#include Player.h#include EnemyPlane.h#include Bullet.h#include EnumDefine.h#include SpriteFactory.h#include usingnamespacestd;classPlaneGamepublic:virtualPlaneGame();staticPlaneGame*getPlaneGame();CSprite*getSpriteByName(constchar*name);voidsetTe*tScore(intscore);voidsetTe*tHp(inthp);voidsetTe*tMp(intmp);intgetBulletType()returnbulletType;voidsetBulletType(floattime);voidsetBulletType(inttype)bulletType=type;floatgetfMPTime()returnfMPTime;voidsetfMPTime(floatval)fMPTime=val;floatgetfMPUsedTime()returnfMPUsedTime;voidsetfMPUsedTime(floatval)fMPUsedTime=val;Player*getPlayer()returnpPlayer;voidsetPlayer(Player*myPlane)pPlayer=myPlane;floatgetEnemyPlaneCreateTime()returnfCreateEnemyTime;voidsetEnemyPlaneCreateTime(floatcreateTime)fCreateEnemyTime=createTime;floatgetEnemyPlaneUsedTime()returnfUsedEnemyTime;voidsetEnemyPlaneUsedTime(floatusedTime)fUsedEnemyTime=usedTime;floatgetItemCreateTime()returnfCreateItemTime;voidsetItemCreateTime(floatcreateTime)fCreateItemTime=createTime;floatgetItemUsedTime()returnfUsedItemTime;voidsetItemUsedTime(floatusedTime)fUsedItemTime=usedTime;listgetEnemyPlaneList();listgetBulletList();listgetSpriteList()returnspriteList;voidplayerFire(floattime,inttype);voiddestroyDeadSprites();voidcreatNewEnemyPlane(floatTime);voidcreatNewItemPlane(floatTime);voiddestroyWorldLimit(constchar*name);voiddestroyPlayer();voiddestroyAll();voidplayE*plodeAnimation(float*,floaty,inttype);voidsetspeed(floatispeed)speed=ispeed;floatgetspeed()returnspeed;protected:private:staticPlaneGame*pGame;staticintiID;CTe*tSprite*pTe*tScore;CTe*tSprite*pTe*tHp;CTe*tSprite*pTe*tMp;Player*pPlayer=NULL;listspriteList;floatfCreateEnemyTime;floatfUsedEnemyTime;floatfCreateItemTime;floatfUsedItemTime;floatfMPTime;floatfMPUsedTime;intbulletType;PlaneGame();floatspeed;EnumDefine类classEnumDefinepublic:EnumDefine();virtualEnumDefine();staticconstintBIG_ENEMY=0;staticconstintMEDIUM_ENEMY=1;staticconstintSMALL_ENEMY=2;staticconstintPLAYER_PLANE=3;staticconstintBULLET=4;staticconstintBULLET_DAMAGE=1;staticconstintBIG_ENEMY_VALUE=10;staticconstintMEDIUM_ENEMY_VALUE=5;staticconstintSMALL_ENEMY_VALUE=2;staticconstfloatPLAYER_SPEED=30.0f;staticconstfloatBULLET_SPEED=50.0f;staticconstfloatBIG_ENEMY_SPEED=5.0f;staticconstfloatMEDIUN_ENEMY_SPEED=10.0f;staticconstfloatSMALL_ENEMY_SPEED=20.0f;staticconstintPLAYER_HP=;staticconstintHP=5;staticconstintMP=6;staticconstintBULLET1=7;staticconstintBULLET2=8;staticconstintBULLETSPEED=9;staticconstfloatHP_SPEED=20.0f;staticconstfloatMP_SPEED=20.0f;staticconstfloatBULLET1_SPEED=20.0f;staticconstfloatBULLET2_SPEED=20.0f;staticconstfloatBULLETSPEED_SPEED=20.0f;protected:private:;Lesson*类#include #include PlaneGame.h#include SpriteFactory.hclassCGameMainprivate:intm_iGameState;CSprite*GameBegin=newCSprite(GameBegin);public:CGameMain();CGameMain();intGetGameState()returnm_iGameState;voidSetGameState(constintiState)m_iGameState=iState;voidGameMainLoop(floatfDeltaTime);voidGameInit();voidGameRun(floatfDeltaTime);voidGameEnd();voidOnKeyDown(constintiKey,constboolbAltPress,constboolbShiftPress,constboolbCtrlPress);voidOnSpriteColSprite(constchar*szSrame,constchar*szTarName);voidOnSpriteColWorldLimit(constchar*szName,constintiColSide);voidOnKeyUp(constintiKey);e*ternCGameMaing_GameMain;.
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!