基于android平台的游戏设计—_—太空保卫战毕业论文(编辑修改稿)内容摘要:

lane 类读取主战飞机的信息进行绘制。 当主战飞机发射子弹时,会创建 Buller 对象并添加到指定容器中,此时MoveThread 同样需要定时改变子弹对象的位置。 在以上过程中,全部需要 PlaneActivity 的管理与 ConstantUtil 的参与。 (四 )游戏总流程图 ( 五 )游戏实体相关类的实现 飞机 Plane 类的实现,其代码如下: package。 import。 import。 import。 12 import。 import。 public class Plane { private int x。 //飞机的坐标 private int y。 int life。 //生命 private int dir。 //飞机的方向 ,0 静止, 1 上 ,2 右上, 3右, 4右下, 5下,6 左下, 7左, 8 左上 private int type。 //飞机的类型 Bitmap bitmap1。 //当前向下飞机的图片 Bitmap bitmap2。 //当前向上飞机的图片 Bitmap bitmap3。 //当前飞机的图片 GameView gameView。 //GameView 的引用 private int span = 10。 //飞机走一步的像素 int bulletType = 1。 public Plane(int x, int y, int type, int dir,int life, GameView gameView){ = gameView。 = x。 = y。 = type。 = dir。 = life。 initBitmap()。 } public void initBitmap(){ if(type == 1){//当类型为 1时 bitmap1 = ((), 13 )。 bitmap2 = ((), )。 bitmap3 = ((), )。 } } public void draw(Canvas canvas){ if(dir == ){//向上 (bitmap2, x, y,new Paint())。 } else if(dir == ){//向下 (bitmap1, x, y,new Paint())。 } else{//其他情况使用的图片 (bitmap3, x, y,new Paint())。 } } public void fire(){//打子弹的方法 if(bulletType == 1){ Bullet b = new Bullet(+75, +8, 1, ,gameView)。 (b)。 } else if(bulletType == 2){ Bullet b = new Bullet(+75, +4, 3, ,gameView)。 14 (b)。 } else { Bullet b = new Bullet(+75, +4, 3, ,gameView)。 (b)。 Bullet b2 = new Bullet(+55, , 4, ,gameView)。 (b2)。 Bullet b3 = new Bullet(+55, +12, 5, ,gameView)。 (b3)。 } if(){ (1,0)。 //播放音乐 } } public boolean contain(Bullet b){ if(isContain(, , (), ())){//检测成功。 //自己的生命减 1 if(0){//当生命小于 0 时 = 2。 if(()){ ()。 } if(){ (3,0)。 } 15 Message msg1 = (1)。 (msg1)。 // 向主activity 发送 Handler 消息 } return true。 } return false。 } public boolean contain(ChangeBullet cb){ if(isContain(, , (), ())){//检测成功 += 1。 return true。 } return false。 } public boolean contain(EnemyPlane ep){ if(isContain(, , (), ())){//检测成功。 //自己的生命减 1 if(0){//当生命小于 0 时 = 2。 if(()){ ()。 } if(){ (3,0)。 } 16 (1)。 // 向主activity 发送 Handler 消息 } return true。 } return false。 } public boolean contain(Life l){//检测玩家飞机是否撞血块 if(isContain(, , (), ())){//检测成功 if(){ ++。 //生命加一 } return true。 } return false。 } private boolean isContain(int otherX, int otherY, int otherWidth, int otherHeight){//判断两个矩形是否碰撞 int xd = 0。 //大的 x int yd = 0。 //大大 y int xx = 0。 //小的 x int yx = 0。 //小的 y int width = 0。 int height = 0。 boolean xFlag = true。 //玩家飞机 x是否在前 boolean yFlag = true。 //玩家飞机 y是否在前 if( = otherX){ xd =。 17 xx = otherX。 xFlag = false。 }else{ xd = otherX。 xx =。 xFlag = true。 } if( = otherY){ yd =。 yx = o。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。