基于Android平台的游戏设计——太空保卫战毕业论文_第1页
基于Android平台的游戏设计——太空保卫战毕业论文_第2页
基于Android平台的游戏设计——太空保卫战毕业论文_第3页
基于Android平台的游戏设计——太空保卫战毕业论文_第4页
基于Android平台的游戏设计——太空保卫战毕业论文_第5页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、石家庄科技信息职业学院毕 业 论 文题 目: 基 于 android 平 台 的 游 戏设 计太 空 保 卫 战 学 号: 0 9 0 1 2 4 0 1 6 姓 名: 宋少伟 专业班级: 游戏开发 指导教师: 刘永伟 完成日期: 2011年12月 16 日 太 空 保 卫 战摘要:android是google公司为首的oha研发的一个开源智能手机平台。随着互联网和物联网的广泛应用,得到了学术界和产业界的支持,越来越多的创意应用到android应用程序中,席卷了整个手机产业。近来随着手机的快速发展,各种各样的手机游戏层出不穷,使得我们能有更多的娱乐项目,而射击类游戏是节奏比较快,要求玩家通过快

2、速的反应与游戏进行交互,从而考验玩家的灵敏度以及放松玩家大脑,是玩家身心休闲娱乐太空保卫战便是运行在android上的一种滚屏动作类游戏,其中融入了很多动作类游戏特有的技术,且画面流畅、声音震撼。关键词: android应用程序 j2me plane类 enemyplane类 bullet类too empty and defend warabstract:android is google company headed by oha research and development of an open source platform of intelligent mobile phone.

3、with the advent of the internet and networking applications, obtained the academic and industry support, more and more creative application to the android application, swept the whole of mobile phone industry.recently with the rapid development of mobile phone, all kinds of mobile phone game emerge

4、in an endless stream, so that we can have more entertainment projects, while shooting game is relatively fast pace, for game player through rapid response and games to interact, so as to test the sensitivity of game player and relaxed game player brain, mental and physical recreation is game players

5、pace war is run in the android on a scrolling action games, which incorporates many action games unique technology, and smooth picture, sound rock.key words: android application j2me class plane class enemyplane class bullet目 录一、引言 3(一)课题背景 3(二)本课题研究的意义 3(三) 本课题的研究方法 3二、课题相关基础 4 (一) 游戏情节 4(二)功能介绍 4(

6、三) 目标平台 7三、设计方案 8 (一)游戏的架构 8(二)游戏的框架简介图 9(三)游戏界面基本框架及介绍 10(四) 游戏总流程图 11si(五)游戏实体相关类的实现 11 1、飞机plane类的实现 11. 2、敌机enemyplane类的实现19 3、子弹bullet类的实现24 四i2棋盘和棋子、结论 27 参考文献 28正 文一、引言 (一)课题背景android是google公司为首的oha研发的一个开源智能手机平台。随着互联网和物联网的广泛应用,得到了学术界和产业界的支持,越来越多的创意应用到android应用程序中,席卷了整个手机产业。随着android游戏的普及,andr

7、oid应用的需求势必会越来越大。并且android相对于其他的手机操作系统具有开放、平等、无界限、方便以及硬件丰富性等的特性。这将是一个潜力巨大的市场会吸引无数软件开发商和开发者投身其中。太空保卫战便是运行在android上的一种滚屏动作类游戏,其中融入了很多动作类游戏特有的技术,且画面流畅、声音震撼。(二)本课题研究的意义近来随着手机的快速发展,各种各样的手机游戏层出不穷,使得我们能有更多的娱乐项目,而射击类游戏是节奏比较快,要求玩家通过快速的反应与游戏进行交互,从而考验玩家的灵敏度以及放松玩家大脑,是玩家身心休闲娱乐。当今市面上流行的手机游戏类型繁多,不同类型的游戏自然有其独特的设计方式以

8、及独到的吸引玩家的地方,射击类游戏(shooting game)是一种比较古老的游戏类型手机游戏中的射击游戏也很流行,目前市面上的射击类游戏最多的是飞行射击游戏。太空保卫战就是属于飞行射击类游戏,是滚屏动作类游戏的一种。而滚屏动作类游戏是最传统的游戏类型之一,早期动作游戏的画面一般比较简单,没有复杂的游戏特效,主要是通过熟练操作技巧来进行游戏,一般是为了通关。而现在的动作类游戏则融入了很多新的元素,很多经典的关卡以及很多画面的特效,使其逐渐成为所有游戏类型里面款式最多,发展最快的一种。(三) 本课题的研究方法 相对于其他相同类型的游戏进行,提取其精华技术,并且融入较多新的元素。运用平台andr

9、oid2.1、eclipse开发软件,使用java进行语言开发,并且采用2d的呈现技术,是玩家玩得更加刺激震撼。并且游戏的添加上成绩排行功能,并将玩家的最好成绩保存下来,会大大提高游戏的可玩性。二、课题相关基础 (一) 游戏情节:本游戏是一款滚屏动作游戏,没有过多的情景设计。所以主要的工作是主战飞机生命的设计(血值或生命值)、道具的设计(换枪的道具及补血的道具)、关卡的设计等。此游戏还融入了很多动作类游戏特有的技术,使得画面流畅、声音震撼。游戏操作简单,易于上手,且火爆的游戏场面,快速、激烈、紧张的游戏节奏会使玩家产生浓厚兴趣。(二)功能介绍太空保卫战游戏主要包含欢迎界面、帮助界面以及游戏界面

10、。下面对该游戏的部分界面及运行效果进行简单的介绍:1、运行该游戏,通过ctrl+f12组合键将模拟器调成横屏,进入加载界面。图1 游戏的加载界面2、之后将进入欢迎动画界面。图2 游戏的欢迎动画1图3 游戏的欢迎动画2图3 游戏的欢迎界面33、欢迎动画播放完毕将进入选择界面,菜单界面包括“开始游戏”、“帮助”、“关闭声音”及“退出”按钮。图4 选择界面4、单击“帮助”按钮将进入“帮助”界面。图5 帮助界面5、单击开始游戏“按钮将进入游戏界面,在游戏界面中,玩家可通过上下左右键控制飞机移动,然后a键发射子弹打击敌人。图6 游戏界面8、如果玩家飞机坚持足够的时间没有爆炸的话,将看到关底。7、当顺利过

11、关时,会出现恭喜过关界面;当游戏失败时,则会出现失败界面。图7 游戏失败界面(三)目标平台:目标平台为android2.1 。开发语言:java开发软件:eclipse三、设计方案 (一)游戏的架构该项目中的类分成了4部分进行介绍1 共有类 activitv的实现类planeactivity:该类是通过扩展基类activity实现的,是整个游戏程序的入口。 键盘监听线程keythread:该类为手机键盘的监听线程,没隔一段时间读取一次键盘的状态值,并根据当前键盘状态做出相应的操作。 常量类constantutil:将游戏中用到的所有常量全部封装到该类中,便于管理与维护。2 辅助界面相关类 欢迎

12、界面welcomeview:该类为游戏欢迎界面的实现类,主要负责欢迎界面的绘制工作。欢迎界面的动画实现类welcomeviewthread:该类是为welcomeview服务的线程类,主要负责欢迎界面中动画的生成。帮助界面helpview:该类非常简单,主要负责绘制帮助界面的相关图片。加载界面processview:为了使游戏更加人性化,给玩家更好的体验,在长时间加载某些资源时,需要给出加载界面以提示玩家后台加载进度。胜利界面winview:该类为玩家顺利谷关后的恭喜过关界面。失败界面failview:该类为主战飞机死亡后显示的失败界面,在该界面中玩家可以选着重新游戏或退住游戏。 3 游戏界面

13、相关类 游戏主界面类gameview:该类为游戏菜单界面的实现类,负责界面绘制工作。 背景滚动线程类gameviewbackgroundthread:该类主要负责背景滚动、敌机以及各种道具的出现。 地图信息类maps:该类包含着地图的相关信息,例如敌机所有的移动路线、各个关卡中补血道具、换枪道具等。 物体移动线程类movethread:该线程负责除了我方主站飞机外所有可移动物的移动 4 情景相关类 主战飞机plane:该类为主战飞机的封装类,可有玩家控制其芳香以及移动状态。 敌机enenyplane:该类为敌机的封装类。 子弹类bullet:子弹的封装类,游戏中所有的子弹都为该类的对象。 爆炸

14、效果类explode:该类为爆炸效果的渲染类,负责在指定位置绘制爆炸效果。 爆炸换帧线程explodethread:该类是为爆炸效果服务的。当爆炸存在时,定时为每个爆炸效果换帧。 补血道具类life:该类是补血道具类,当主战飞机与该类的对象碰撞时,会为主站飞机增加一格血。 换枪道具类changebullet:该类为换枪道具类,当主战飞机与该类的对象碰撞时,会增加主战飞机所携带武器。(二)游戏的框架简介图图1 太空保卫战游戏类框架图1、启动游戏,在planeactivity中会先进入家在界面processview,然后后台加载欢迎界面welcomeview,当加载完成后将屏幕切换到欢迎界面,并启

15、动welcomeviewthread线程生成欢迎界面的动画效果。2、当欢迎动画播放完毕后屏幕会停留在选择状态等待玩家操作。3、当玩家点击“帮助”按钮时,将初始化帮助界面helpview并将其显示出来。4、当玩家单击“开始游戏”按钮时,屏幕将显示加载界面。后台将初始化游戏界面gameview,在地图信息类maps中初始化此关卡中所有敌机、变枪的道具、补血的道具等。5、初始化游戏界面的同时启动gameviewbackgroundthread线程,以滚动游戏界面的背景图片。6、当玩家发射炮弹或敌机发射炮弹时会创建炮弹类bullet的对象,并将其添加到已知的容器中。7、当游戏过程中如果需要显示爆炸效果

16、,会创建爆炸效果类explode以及explodethread类来渲染爆炸效果。8、游戏中所有类中使用的常量全部封装到常量类constantutil类中。(三)游戏界面基本框架及介绍图2 游戏界面基本框架1、gameview在初始化时会从maps读取当前关卡的地图信息,包括敌机、补血道具、换枪道具等。2、在界面初始化的同时,还需要启动movethread线程、gameviewbackgroundthread线程、keythread线程及explodethread线程。3、gameview会在适当的时候从plane类读取主战飞机的信息进行绘制。4、当主战飞机发射子弹时,会创建buller对象并添

17、加到指定容器中,此时movethread同样需要定时改变子弹对象的位置。5、在以上过程中,全部需要planeactivity的管理与constantutil的参与。(四)游戏总流程图(五)游戏实体相关类的实现1、飞机plane类的实现,其代码如下:package wyf.ytl;import android.graphics.bitmap;import android.graphics.bitmapfactory;import android.graphics.canvas;import android.graphics.paint;import android.os.message;publ

18、ic 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 p

19、lane(int x, int y, int type, int dir,int life, gameview gameview)this.gameview = gameview;this.x = x;this.y = y; this.type = type;this.dir = dir;this.life = life;initbitmap();public void initbitmap()if(type = 1)/当类型为1时bitmap1 = bitmapfactory.decoderesource(gameview.getresources(), r.drawable.plane1)

20、;bitmap2 = bitmapfactory.decoderesource(gameview.getresources(), r.drawable.plane2);bitmap3 = bitmapfactory.decoderesource(gameview.getresources(), r.drawable.plane3);public void draw(canvas canvas)if(dir = constantutil.dir_up)/向上canvas.drawbitmap(bitmap2, x, y,new paint();else if(dir = constantutil

21、.dir_down)/向下canvas.drawbitmap(bitmap1, x, y,new paint();else/其他情况使用的图片canvas.drawbitmap(bitmap3, x, y,new paint();public void fire()/打子弹的方法if(bullettype = 1)bullet b = new bullet(this.x+75, this.y+8, 1, constantutil.dir_right,gameview);gameview.goodbollets.add(b);else if(bullettype = 2)bullet b = n

22、ew bullet(this.x+75, this.y+4, 3, constantutil.dir_right,gameview);gameview.goodbollets.add(b);else bullet b = new bullet(this.x+75, this.y+4, 3, constantutil.dir_right,gameview);gameview.goodbollets.add(b);bullet b2 = new bullet(this.x+55, this.y-4, 4, constantutil.dir_right_up,gameview);gameview.g

23、oodbollets.add(b2);bullet b3 = new bullet(this.x+55, this.y+12, 5, constantutil.dir_right_down,gameview);gameview.goodbollets.add(b3);if(gameview.activity.issound)gameview.playsound(1,0);/播放音乐public boolean contain(bullet b)if(iscontain(b.x, b.y, b.bitmap.getwidth(), b.bitmap.getheight()/检测成功this.li

24、fe-;/自己的生命减1if(this.life0)/当生命小于0时gameview.status = 2;if(gameview.mmediaplayer.isplaying()gameview.mmediaplayer.stop();if(gameview.activity.issound)gameview.playsound(3,0);message msg1 = gameview.activity.myhandler.obtainmessage(1);gameview.activity.myhandler.sendmessage(msg1);/向主activity发送handler消息

25、return true;return false;public boolean contain(changebullet cb)if(iscontain(cb.x, cb.y, cb.bitmap.getwidth(), cb.bitmap.getheight()/检测成功this.bullettype += 1;return true;return false;public boolean contain(enemyplane ep)if(iscontain(ep.x, ep.y, ep.bitmap.getwidth(), ep.bitmap.getheight()/检测成功this.li

26、fe-;/自己的生命减1if(this.life0)/当生命小于0时gameview.status = 2;if(gameview.mmediaplayer.isplaying()gameview.mmediaplayer.stop();if(gameview.activity.issound)gameview.playsound(3,0);gameview.activity.myhandler.sendemptymessage(1);/向主activity发送handler消息return true;return false;public boolean contain(life l)/检测

27、玩家飞机是否撞血块if(iscontain(l.x, l.y, l.bitmap.getwidth(), l.bitmap.getheight()/检测成功if(this.life= otherx)xd = this.x;xx = otherx;xflag = false;elsexd = otherx;xx = this.x;xflag = true;if(this.y = othery)yd = this.y;yx = othery;yflag = false;elseyd = othery;yx = this.y;yflag = true;if(xflag = true)width =

28、this.bitmap1.getwidth();else width = otherwidth;if(yflag = true)height = this.bitmap1.getheight();elseheight = otherheight;if(xd=xx&xd=yx&yd=0.20)/重叠面积超20%则判定为碰撞return true;return false;public void setdir(int dir) this.dir = dir;public int getspan()return span;public int getx() return x;public void

29、setx(int x) this.x = x;public int gety() return y;public void sety(int y) this.y = y;if(this.y constantutil.screenheight)this.y = constantutil.screenheight;2、敌机enemyplane类的实现,其代码如下:package wyf.ytl;import android.graphics.bitmap;import android.graphics.canvas;import android.graphics.paint;import andr

30、oid.os.message;public class enemyplane int x = constantutil.screenwidth;/飞机的坐标int y;boolean status;/飞机的状态long touchpoint;/触发点int type;/飞机的类型int life;/生命int spanx = 10;/飞机移动的x像素int spany = 5;/飞机移动的x像素bitmap bitmap;int start;/当前出发点int target;/当前目标点int step;/当前处于当前路径片段中第几步int path; public enemyplane(in

31、t start,int target,int step,int path, boolean status,long touchpoint, int type, int life)this.start=start;this.target=target;this.step=step;this.path=path;this.status = status;this.touchpoint = touchpoint;this.type = type;this.life = life;this.x=path0start;this.y=path1start;public void draw(canvas c

32、anvas)canvas.drawbitmap(bitmap, x, y, new paint();public void move()if(step=path2start)/一段路径走完,到下一段路径开始step=0;start=(start+1)%(path0.length);target=(target+1)%(path0.length);this.x=path0start;this.y=path1start;else/一段路径没有走完,继续走int xspan=(path0target-path0start)/path2start;int yspan=(path1target-path

33、1start)/path2start;this.x=this.x+xspan;this.y=this.y+yspan;step+;public void fire(gameview gameview)/打子弹的方法if(type = 3 & math.random()constantutil.booletspan2)bullet b1 = new bullet(x, y, 2, constantutil.dir_left,gameview);bullet b2 = new bullet(x, y, 2, constantutil.dir_left_down,gameview);bullet b

34、3 = new bullet(x, y, 2, constantutil.dir_left_up,gameview);gameview.badbollets.add(b1);gameview.badbollets.add(b2);gameview.badbollets.add(b3);else if(math.random()= otherx)xd = this.x;xx = otherx;xflag = false;elsexd = otherx;xx = this.x;xflag = true;if(this.y = othery)yd = this.y;yx = othery;yflag

35、 = false;elseyd = othery;yx = this.y;yflag = true;if(xflag = true)width = this.bitmap.getwidth();elsewidth = otherwidth;if(yflag = true)height = this.bitmap.getheight();elseheight = otherheight;if(xd=xx&xd=yx&yd=0.20)/重叠面积超20%则判定为碰撞return true;return false;public boolean contain(bullet b,gameview ga

36、meview)/判断子弹是否打中敌机if(iscontain(b.x, b.y, b.bitmap.getwidth(), b.bitmap.getheight()this.life-;/自己的生命减1if(this.life=0)/当生命小于0时if(gameview.activity.issound)gameview.playsound(2,0);this.status = false;/使自己不可见if(this.type = 3)/是关口时gameview.status = 3;/状态换成胜利状态if(gameview.mmediaplayer.isplaying()gameview.

37、mmediaplayer.stop();/将游戏背景音乐停止message msg1 = gameview.activity.myhandler.obtainmessage(5);gameview.activity.myhandler.sendmessage(msg1);/向主activity发送handler消息return true;return false;public int getx() return x;public void setx(int x) this.x = x;public int gety() return y;public void sety(int y) this

38、.y = y;3、子弹bullet类的实现,其代码如下:package wyf.ytl;import android.graphics.bitmap;import android.graphics.bitmapfactory;import android.graphics.canvas;import android.graphics.paint;/* * * 该类为子弹的封装类 * 记录了子弹自身的相关参数 * 外界通过调用move方法移动子弹 * */public class bullet int x;/子弹的坐标int y;int dir;/子弹的方向,0静止,1上,2右上,3右,4右下,

39、5下,6左下,7左,8左上int type;/子弹的类型bitmap bitmap;/当前子弹的图片gameview gameview;/gameview的引用private int movespan = 10;/移动的像素public bullet(int x, int y, int type, int dir,gameview gameview)this.gameview = gameview;this.x = x;this.y = y;this.type = type;this.dir = dir;this.initbitmap();public void initbitmap()if(type = 1)/当类型为1时bitmap = bitmapfactory.decoderesource(gameview.getresources(), r.drawable.bullet1);else if(type = 2)/类型为2时bitmap = bitmapfactory.decoderesource(gameview.getresources(), r.drawable.bullet2);else if(type = 3)/类型为3时bitmap = bitmapfactory.decoderesource(game

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论