




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、操作系统实验游戏:打飞机实验小组名单:窦晓磊一、 设计主要完成的任务解决的主要问题 设计一个打飞机游戏能够实现基本的游戏体验二、 解决的主要问题解决飞机的控制问题。解决子弹与飞机的碰撞问题。解决敌方飞机的刷新问题三、 设计的基本概念利用unity3d的一些函数来构建脚本,将脚本附加给原型使其可以接受控制。四、 总体设计:实现的方法和主要技术路线使用unity3d游戏制作软件进行游戏制作,将网上找到的材料原型增加属性以及添加脚本从而使游戏能够运行。建立Player.cs、Enemy.cs、Bullet.cs、Spaceship.cs、BackGround.cs、DestroyArea.cs、Em
2、itter.cs、Explosion.cs、Manager.cs、Score.cs脚本来建立与模型之间的联系,起到控制飞机,子弹发射,子弹与飞机之间碰撞后的消失,飞机消失的爆炸动画,飞机的飞行区域,背景图案及音乐的设置,敌方飞机的出场以及得分。五、 详细设计:使用的主要控件、函数(1) 将从网上下载的飞机资源图片剪裁并制作成动画,己方飞机飞行动画,敌方飞机飞行动画,两方子弹。(2) 增添脚本Player.cs:用来控制飞船增添控制方法,速度,飞行区域,物体销毁。public class player : MonoBehaviour /Spaceship ComponentSpaceship s
3、paceship;/ Use this for initializationIEnumerator Start () spaceship = GetComponent<Spaceship> ();/持续发射子弹while (true) spaceship.Shot (transform);/播放音效GetComponent<AudioSource>().Play();yield return new WaitForSeconds (spaceship.shotDelay);/间隔时间/ Update is called once per framevoid Update
4、 () /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
5、 (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 c
6、ollision 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") FindObjectOfT
7、ype<Score>().Save();/Delete the playerDestroy (this.gameObject);/Explodespaceship.Explosion ();FindObjectOfType<Manager> ().GameOver ();Enemy.cs:用来控制敌方飞机的血量、物理碰撞,销毁。public class Enemy : MonoBehaviour public int Hp = 1; public int point = 100;Spaceship spaceship;public bool canShot=true;/
8、 Use this for initializationIEnumerator Start () spaceship = GetComponent<Spaceship> ();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 Wai
9、tForSeconds (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 bul
10、let Destroy(c.gameObject); Transform PlayerBulletTransform = c.transform.parent;Bullet bullet = PlayerBulletTransform.GetComponent<Bullet> ();Hp = Hp - bullet.power;if (Hp <= 0) FindObjectOfType<Score>().AddPoint(point);/Delete the playerDestroy (this.gameObject);/Explodespaceship.Exp
11、losion (); else spaceship.GetAnimator().SetTrigger("damage"); Spaceship:存储所有飞船的共同属性移动速度,子弹延迟时间,移动,子弹等。RequireComponent(typeof(Rigidbody2D)/提示加入组件public class Spaceship : MonoBehaviour /移动速度public float speed;/子弹延迟时间public float shotDelay;/子弹的prefabpublic GameObject bullet;/爆炸的prefabpublic
12、GameObject explosion; private Animator animator;/ Use this for initializationvoid Start () animator = GetComponent<Animator>();/ Update is called once per framevoid Update () public Animator GetAnimator() return animator; /生成子弹public void Shot(Transform origin)Instantiate (bullet, origin.posit
13、ion, origin.rotation);/移动public void Move(Vector2 direction)GetComponent<Rigidbody2D>().velocity = direction * speed;/爆炸public void Explosion()Instantiate(explosion,transform.position,transform.rotation);Explosion.cs:控制飞船的爆炸特效。public class Explosion : MonoBehaviour void OnAnimationFinish()Dest
14、roy (gameObject);Bullet.cs:控制子弹的速度以及子弹的销毁。Use this for initializationvoid Start () GetComponent<Rigidbody2D>().velocity = transform.up.normalized * speed;Destroy (gameObject, lifetime);BackGround.cs:控制背景图片public class BackGround : MonoBehaviour /文理偏移速度public float speed=0.1f;/ Use this for ini
15、tializationvoid 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<Renderer>().sharedMaterial.SetTextureOffset("_MainTex",offset);Dest
16、royArea.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
17、 for initialization IEnumerator Start() if (waves.Length = 0) yield break; manager = FindObjectOfType<Manager>(); while (true) / 创建Wave GameObject wave = (GameObject)Instantiate(wavescurrentWave, transform.position, Quaternion.identity); / wave.transform.parent = transform; while (wave.transfo
18、rm.childCount != 0) yield return new WaitForEndOfFrame(); /删除Wave Destroy(wave); if (waves.Length <= +currentWave) currentWave = 0; / Update is called once per framevoid Update () Manager.cs:控制提示语句的出现以及消失,开始游戏的按键设置等public class Manager : MonoBehaviour / Player Prefabpublic GameObject player;publi
19、c GameObject title;/ Use this for initializationvoid Start () title = GameObject.Find("Title");/ Update is called once per framevoid Update () if( IsPlaying() = false && Input.GetKeyDown(KeyCode.X) )GameStart();public void GameStart()title.SetActive(false);Instantiate(player, playe
20、r.transform.position, player.transform.rotation);public bool IsPlaying()return title.activeSelf = false;public void GameOver()title.SetActive(true);Score.cs:控制计数系统,提供一个最高纪录分数以及本次游戏分数public class Score : MonoBehaviour public GUIText hightScoreGUIText; public GUIText currentScoreGUIText; private int c
21、urrScore; private int hightScore; private string highScoreKey = "highScore"/ Use this for initializationvoid Start () Init();/ Update is called once per framevoid Update () if (currScore > hightScore) hightScore = currScore; currentScoreGUIText.text = "Your Score :"+currScore.ToString(); hightScoreGUIText.text = "HightScore: " + hightScore.ToString
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年大学化学趋势性试题及答案
- 《Lesson 1 Avatars》教学导学案(统编北师大版)
- 2020年全国数学高中联赛加试题目
- 武汉年会策划合同协议
- 快餐自助转让合同协议
- 武汉买房交定金合同协议
- 咖啡实体店转让协议合同
- 商服铺面租赁合同协议
- 吴中区解除劳动合同协议
- 品牌协议书模板
- 社区矫正人员心理健康教育讲座
- 测量员培训试题及答案
- 财富顾问理论考试题库(含答案)
- 职场沟通职场沟通与人际关系处理知到课后答案智慧树章节测试答案2025年春山东管理学院
- 标准第三方担保合同书
- 包头市石拐区凯通露天煤矿2022年度矿山地质环境年度治理计划
- 基于STM32的停车场智能管理系统
- 2023年北京市石景山区八角街道社区工作者招聘笔试题库及答案解析
- GB/T 31997-2015风力发电场项目建设工程验收规程
- GB/T 10686-2013铜合金工具防爆性能试验方法
- 《ArcGIS软件与应用(第2版)》配套教学课件
评论
0/150
提交评论