




免费预览已结束,剩余4页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统实验游戏:打飞机实验小组名单:窦晓磊一、 设计主要完成的任务解决的主要问题 设计一个打飞机游戏能够实现基本的游戏体验二、 解决的主要问题解决飞机的控制问题。解决子弹与飞机的碰撞问题。解决敌方飞机的刷新问题三、 设计的基本概念利用unity3d的一些函数来构建脚本,将脚本附加给原型使其可以接受控制。四、 总体设计:实现的方法和主要技术路线使用unity3d游戏制作软件进行游戏制作,将网上找到的材料原型增加属性以及添加脚本从而使游戏能够运行。建立Player.cs、Enemy.cs、Bullet.cs、Spaceship.cs、BackGround.cs、DestroyArea.cs、Emitter.cs、Explosion.cs、Manager.cs、Score.cs脚本来建立与模型之间的联系,起到控制飞机,子弹发射,子弹与飞机之间碰撞后的消失,飞机消失的爆炸动画,飞机的飞行区域,背景图案及音乐的设置,敌方飞机的出场以及得分。五、 详细设计:使用的主要控件、函数(1) 将从网上下载的飞机资源图片剪裁并制作成动画,己方飞机飞行动画,敌方飞机飞行动画,两方子弹。(2) 增添脚本Player.cs:用来控制飞船增添控制方法,速度,飞行区域,物体销毁。public class player : MonoBehaviour /Spaceship ComponentSpaceship spaceship;/ Use this for initializationIEnumerator Start () spaceship = GetComponent ();/持续发射子弹while (true) spaceship.Shot (transform);/播放音效GetComponent().Play();yield return new WaitForSeconds (spaceship.shotDelay);/间隔时间/ Update is called once per framevoid Update () /Right,Left/移动float x = Input.GetAxisRaw (Horizontal);/Up,Downfloat y = Input.GetAxisRaw (Vertical);Vector2 direction = new Vector2 (x, y).normalized;spaceship.Move (direction);Clamp ();void Clamp()/得到视口坐标0,0的世界坐标Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2 (0, 0);/得到视口坐标1,1的世界坐标Vector2 max = Camera.main.ViewportToWorldPoint (new Vector2 (1, 1);/得到player的世界坐标Vector2 pos = transform.position;/坐标位置校正pos.x = Mathf.Clamp (pos.x, min.x+0.24f, max.x-0.24f);pos.y = Mathf.Clamp (pos.y, min.y+0.32f, max.y-0.32f);transform.position = pos;/Called at the moment collision happensvoid OnTriggerEnter2D(Collider2D c)/得到碰撞物对象的LayerNamestring layerName=LayerMask.LayerToName(c.gameObject.layer);if (layerName = Bullet(enemy) /Delete the bulletDestroy (c.gameObject);if (layerName = Bullet(enemy) | layerName = Enemy) FindObjectOfType().Save();/Delete the playerDestroy (this.gameObject);/Explodespaceship.Explosion ();FindObjectOfType ().GameOver ();Enemy.cs:用来控制敌方飞机的血量、物理碰撞,销毁。public class Enemy : MonoBehaviour public int Hp = 1; public int point = 100;Spaceship spaceship;public bool canShot=true;/ Use this for initializationIEnumerator Start () spaceship = GetComponent ();spaceship.Move (transform.up * -1);while (true) for (int i = 0; i transform.childCount; i+) Transform shotPosition = transform.GetChild (i);if(canShot)spaceship.Shot (shotPosition);yield return new WaitForSeconds (spaceship.shotDelay);/ Update is called once per framevoid Update () /Called at the moment collision happensvoid OnTriggerEnter2D(Collider2D c)/得到碰撞物对象的LayerNamestring layerName=LayerMask.LayerToName(c.gameObject.layer);if (layerName != Bullet(player)return; /Delete the bullet Destroy(c.gameObject); Transform PlayerBulletTransform = c.transform.parent;Bullet bullet = PlayerBulletTransform.GetComponent ();Hp = Hp - bullet.power;if (Hp = 0) FindObjectOfType().AddPoint(point);/Delete the playerDestroy (this.gameObject);/Explodespaceship.Explosion (); else spaceship.GetAnimator().SetTrigger(damage); Spaceship:存储所有飞船的共同属性移动速度,子弹延迟时间,移动,子弹等。RequireComponent(typeof(Rigidbody2D)/提示加入组件public class Spaceship : MonoBehaviour /移动速度public float speed;/子弹延迟时间public float shotDelay;/子弹的prefabpublic GameObject bullet;/爆炸的prefabpublic GameObject explosion; private Animator animator;/ Use this for initializationvoid Start () animator = GetComponent();/ Update is called once per framevoid Update () public Animator GetAnimator() return animator; /生成子弹public void Shot(Transform origin)Instantiate (bullet, origin.position, origin.rotation);/移动public void Move(Vector2 direction)GetComponent().velocity = direction * speed;/爆炸public void Explosion()Instantiate(explosion,transform.position,transform.rotation);Explosion.cs:控制飞船的爆炸特效。public class Explosion : MonoBehaviour void OnAnimationFinish()Destroy (gameObject);Bullet.cs:控制子弹的速度以及子弹的销毁。Use this for initializationvoid Start () GetComponent().velocity = transform.up.normalized * speed;Destroy (gameObject, lifetime);BackGround.cs:控制背景图片public class BackGround : MonoBehaviour /文理偏移速度public float speed=0.1f;/ Use this for initializationvoid Start () / Update is called once per framevoid Update () /循环取得0-1之间的一个递增的值float y = Mathf.Repeat (Time.time * speed, 1);/根据上面的递增值生成一个Vector2对象Vector2 offset = new Vector2 (0, y);/这是物体的文理偏移GetComponent().sharedMaterial.SetTextureOffset(_MainTex,offset);DestroyArea.cs:提供销毁区域,销毁超过图景的子弹和敌军飞机public class DestroyArea : MonoBehaviour void OnTriggerExit2D(Collider2D c)Destroy (c.gameObject);Emitter.cs:控制敌方飞机出现的波次以及出现方法public class Emitter : MonoBehaviour /保存Wave的Prefabspublic GameObject waves;/当前的Waveprivate int currentWave;private Manager manager;/ Use this for initialization IEnumerator Start() if (waves.Length = 0) yield break; manager = FindObjectOfType(); while (true) / 创建Wave GameObject wave = (GameObject)Instantiate(wavescurrentWave, transform.position, Quaternion.identity); / wave.transform.parent = transform; while (wave.transform.childCount != 0) yield return new WaitForEndOfFrame(); /删除Wave Destroy(wave); if (waves.Length hightScore) hightScore = currScore; currentScoreGUIText.text = Your Score :+currScore.ToString(); hightScoreGUIText.text = HightScore: + hightScore.ToString(); void Init() currScore = 0; hightScore = PlayerPrefs.GetInt(highScoreKey, 0); public void AddPoint(int point) currScore += point; public void Save() PlayerPrefs.SetInt(highScoreKey, hightScore); Init(); 六、 完成的情况这个游戏完成了一个打飞机游戏的基本功能,能够开始游戏,控制飞机,合理爆炸,合理消失算是初步完成了这个游戏的预设任务。七、 简要的使用说明点击Play Plane.exe进入游戏之后点击键盘键x即可开始游戏,初始状态下有5秒的无敌时间,子弹为自动发射,右下角为当前得分,每次死亡后重新计分,右上角为最高得分,每波怪的得分不同,子弹发射速度以及血量也不尽相同,没7波算一个循环,第7波为boss。结束按键为ALT+F4
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年新能源汽车工程师考试试题及答案
- 2025年网络工程师资格考试题及答案
- 2025年风险管理与控制考试试卷及答案解读
- 2025年西方经济学基础知识考试试题及答案
- 医药行业MBO股权收购与人才发展战略整合协议
- 微信小程序电商代运营跨境电商合作框架协议
- 美妆品牌购物中心美妆专区品牌委托经营与产品研发合同
- 短视频社交型移动应用(APP)开发与运营管理协议
- 高端影视特效化妆假发胶水租赁与化妆效果优化协议
- 丹麦电商平台入驻与北欧生活方式营销服务协议
- 公安派出所优质建筑外观形象设计基础规范
- 第8章审计抽样练习题结合9销售循环
- 世界民族音乐鉴赏之欧洲篇课件
- 入团志愿书(2016版本)(可编辑打印标准A4) (1)
- 语文老师家长会PPT
- T梁台座计算书
- 01-《数值分析》实验指导书
- 第四章 潜孔钻机
- 佳能700D单反相机拍摄技巧[技巧]
- 农产品批发市场管理技术规范编制说明
- 重庆市婚姻介绍合同协议书范本模板
评论
0/150
提交评论