using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 奖励
 /// </summary>
 public class Award : MonoBehaviour {

     ; //0 gun   1 explode

     public float speed = 1.5f;

     void Update(){
         this.transform.Translate( Vector3.down*Time.deltaTime*speed );
         if(this.transform.position.y<=-4.5f){
             Destroy(this.gameObject);
         }
     }
 }

Award

 using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 背景移动
 /// </summary>
 public class BackgroundTransform : MonoBehaviour {

     public static float moveSpeed = 2f;

     void Update () {
         this.transform.Translate( Vector3.down * moveSpeed * Time.deltaTime );
         Vector3 postion = this.transform.position;
         if(postion.y<=-8.52f){
             ,postion.z );
         }
     }
 }

BackgroundTransform

 using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 子弹
 /// </summary>
 public class Bullet : MonoBehaviour {

     ;

     // Update is called once per frame
     void Update () {
         transform.Translate( Vector3.up * speed *Time.deltaTime );
         if(transform.position.y>4.3f){
             Destroy(this.gameObject);
         }
     }

     void OnTriggerEnter2D(Collider2D other) {
         if(other.tag=="Enemy"){
             if(!other.GetComponent<Enemy>().isDeath){
                 other.gameObject.SendMessage("BeHit");
                 GameObject.Destroy(this.gameObject);
             }
         }
     }

 }

Bullet

 using UnityEngine;
 using System.Collections;

 public enum EnemyType{
     smallEnemy,
     middleEnemy,
     bigEnemy
 }

 /// <summary>
 /// 敌人
 /// </summary>
 public class Enemy : MonoBehaviour {

     ;

     ;

     ;

     public EnemyType type= EnemyType.smallEnemy;

     public bool isDeath = false;

     public Sprite[] explosionSprites;

     ;

     ;

     private SpriteRenderer render;

     public float hitTimer = 0.2f;
     private float resetHitTime ;

     public Sprite[] hitSprites;

     // Use this for initialization
     void Start () {
         render = this.GetComponent<SpriteRenderer>();

         resetHitTime=hitTimer;
         hitTimer=;
     }

     // Update is called once per frame
     void Update () {
         this.transform.Translate( Vector3.down*speed*Time.deltaTime );
         if(this.transform.position.y<=-5.6f){
             Destroy(this.gameObject);
         }

         if(isDeath){
                 timer+=Time.deltaTime;
                 int frameIndex = (int)(timer/(1f/explosionAnimationFrame));
                 if(frameIndex>=explosionSprites.Length){
                     //destroy
                     Destroy(this.gameObject);
                 }else{
                     render.sprite= explosionSprites[frameIndex];
                 }
         }else{
             if(type==EnemyType.middleEnemy||type==EnemyType.bigEnemy){
                 ){
                     hitTimer-=Time.deltaTime;

                     int frameIndex = (int)((resetHitTime-hitTimer)/(1f/explosionAnimationFrame));
                     frameIndex%=;
                     render.sprite= hitSprites[frameIndex];
                 }
             }
         }
     }

     public void BeHit(){
         hp-=;
         // explosion
         ){
             toDie();
         }else{
             hitTimer=resetHitTime;
         }
     }

     private void toDie(){
         if(!isDeath){
             isDeath=true;
             GameManager._instance.score+=score;
         }
     }
 }

Enemy

 using UnityEngine;
 using System.Collections;

 public enum GameState{
     Runing,
     Pause
 }

 /// <summary>
 /// 游戏管理
 /// </summary>
 public class GameManager : MonoBehaviour {

     public static GameManager _instance;

     ;

     private GUIText guiText;
     public GameState gameState = GameState.Runing;

     void Awake(){
         _instance=this;
         guiText=GameObject.FindGameObjectWithTag("ScoreGUI").GetComponent<GUIText>();
     }

     // Update is called once per frame
     void Update () {
         guiText.text="Score:"+score;
     }
     public void transfromGameState(){
         if(gameState==GameState.Runing){
             pauseGame();
         }else if(gameState==GameState.Pause){
             continueGame();
         }
     }

     public void pauseGame(){
         Time.timeScale=;// time.delatTime = 0
         gameState=GameState.Pause;
     }
     public void continueGame(){
         Time.timeScale=;
         gameState=GameState.Runing;
     }
 }

GameManager

 using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 游戏暂停
 /// </summary>
 public class GamePause : MonoBehaviour {

     void OnMouseUpAsButton() {
         print ("click me!");
         GameManager._instance.transfromGameState();

         GetComponent<AudioSource>().Play();
     }

 }

GamePause

 using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 飞机的枪
 /// </summary>
 public class Gun : MonoBehaviour {

     public float rate =0.2f;

     public GameObject bullet;

     public void fire(){
         GameObject.Instantiate(bullet,transform.position,Quaternion.identity );
     }

     public void openFire(){
         InvokeRepeating(,rate);
     }

     public void stopFire(){
         CancelInvoke("fire");
     }

 }

Gun

 using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 飞机
 /// </summary>
 public class Hero : MonoBehaviour {

     public bool animation = true;

     ;

     ;

     public Sprite[] sprites;

     public float superGunTime = 10f;

     public Gun gunTop;
     public Gun gunLeft;
     public Gun gunRight;

     private float resetSuperGunTime ;

     private SpriteRenderer spriteRender;

     private bool isMouseDown = false;

     private Vector3 lastMousePosition = Vector3.zero;

     private Transform hero;

     ;

     void Start(){
         spriteRender = this.GetComponent<SpriteRenderer>();
         hero = GameObject.FindGameObjectWithTag("Player").transform;

         resetSuperGunTime = superGunTime;
         superGunTime=;

         gunTop.openFire();
     }

     // Update is called once per frame
     void Update () {
         if(animation){
             timer+=Time.deltaTime;// 1f/frameCountPersconds
             int frameIndex = (int)(timer/(1f/frameCountPersconds));
             ;
             spriteRender.sprite = sprites[frame];
         }
         )){
             isMouseDown=true;
         }
         )){
             isMouseDown=false;
             lastMousePosition = Vector3.zero;
         }
         if(isMouseDown && GameManager._instance.gameState==GameState.Runing ){
             if(lastMousePosition!=Vector3.zero){
                 //Camera.main.ScreenToWorldPoint(Input.mousePosition)
                 //print (Camera.main.ScreenToWorldPoint(Input.mousePosition));
                 Vector3 offset = Camera.main.ScreenToWorldPoint(Input.mousePosition) -lastMousePosition;

                 transform.position = transform.position+offset;
                 checkPosition();
             }
             lastMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         }
         superGunTime-=Time.deltaTime;
         ){
             ){
                 transformToSuperGun();
             }
         }else{
             ){
                 tranformToNormalGun();
             }
         }
     }

     private void transformToSuperGun(){
         gunCount=;
         gunLeft.openFire();
         gunRight.openFire();
         gunTop.stopFire();
     }
     private void tranformToNormalGun(){
         gunCount=;

         gunLeft.stopFire();
         gunRight.stopFire();
         gunTop.openFire();
     }

     private void checkPosition(){
         //check x -2.22f +2.22f
         // check y -3.9 3.4
         Vector3 pos = transform.position;
         float x = pos.x;
         float y = pos.y;
         if(x<-2.22f){
             x=-2.22f;
         }
         if(x>2.22f){
             x=2.22f;
         }
         if(y<-3.9f){
             y=-3.9f;
         }
         if(y>3.4f){
             y=3.4f;
         }
         transform.position= );
     }

     public void OnTriggerEnter2D(Collider2D collider){
         if(collider.tag=="Award"){
             GetComponent<AudioSource>().Play();
             Award award = collider.GetComponent<Award>();
             ){
                 //transform gun
                 superGunTime=resetSuperGunTime;
                 Destroy(collider.gameObject);
             }
         }
     }
 }

Hero

 using UnityEngine;
 using System.Collections;

 /// <summary>
 /// 敌人孵化
 /// </summary>
 public class Spawn : MonoBehaviour {

     public GameObject enemy0Prefab;
     public GameObject enemy1Prefab;
     public GameObject enemy2Prefab;

     public GameObject awardType0Prefab;
     public GameObject awardType1Prefab;

     public float enemy0Rate = 0.5f;
     public float enemy1Rate = 5f;
     public float enemy2Rate = 8f;

     ;

     ;

     // Use this for initialization
     void Start () {
         InvokeRepeating(,enemy0Rate);
         InvokeRepeating(,enemy1Rate);
         InvokeRepeating(,enemy2Rate);

         InvokeRepeating(,awardType0Rate);
         InvokeRepeating(,awardType1Rate);

     }

     // Update is called once per frame
     void Update () {

     }

     public void createEnemy0(){
         float x = Random.Range(-2.15f,2.15f);
         GameObject.Instantiate(enemy0Prefab,),Quaternion.identity);

     }
     public void createEnemy1(){
         float x = Random.Range(-2.04f,2.04f);
         GameObject.Instantiate(enemy1Prefab,),Quaternion.identity);

     }
     public void createEnemy2(){
         float x = Random.Range(-2.04f,2.04f);
         GameObject.Instantiate(enemy2Prefab,),Quaternion.identity);

     }

     public void createAwardType0(){
         GetComponent<AudioSource>().Play();
         float x = Random.Range(-2.1f,2.1f);
         GameObject.Instantiate(awardType0Prefab,),Quaternion.identity);
     }
     public void createAwardType1(){
         GetComponent<AudioSource>().Play();
         float x = Random.Range(-2.1f,2.1f);
         GameObject.Instantiate(awardType1Prefab,),Quaternion.identity);
     }
 }

Spawn

视频:https://pan.baidu.com/s/1jHTh3oy

项目:https://pan.baidu.com/s/1sljipdF

S老师 打飞机 学习的更多相关文章

  1. cocos2dx游戏开发——微信打飞机学习笔记(三)——WelcomeScene的搭建

    一.场景与层的关系: cocos2dx的框架可以说主要由导演,场景,层,精灵来构成: 1.其中导演,意如其名,就是操控整个游戏的一个单例,管理着整个游戏. 2.场景就像电影的一幕剧情,所以说,懂得如何 ...

  2. 郝斌老师C语言学习笔记(一)

    在给变量分配内存时,很可能这段内存存在以前其他程序使用留下的值.当使用VC编译器,若编译器发现没有给变量赋值而使用,就会返回一个以“85”开头的很大的数字(此时该段内存中为一个垃圾数,为了避免出现较常 ...

  3. cocos2dx游戏开发——微信打飞机学习笔记(九)——BulletLayer的搭建

    一.创建文件~ BulletLayer.h BulletLayer.cpp 二.How to do? (1)实例化BulletLayer方法的实现~ Bullet(PlayerLayer* temp) ...

  4. cocos2dx游戏开发——微信打飞机学习笔记(八)——EnemyLayer的搭建

    一.创建文件= =               EnemyLayer.h               EnemyLayer.cpp Ps:我绝对不是在凑字数~. 二.How to do? (1)一些宏 ...

  5. cocos2dx游戏开发——微信打飞机学习笔记(七)——Enemy的搭建

    一.文件创建~ Enemy.h Enemy.cpp 二.How to do? 由于我是已经完成成个游戏的功能,所以我会将游戏中enemy所需要的很多功能基本上都先考虑到了,如果大家自己在做的时候也许没 ...

  6. cocos2dx游戏开发——微信打飞机学习笔记(六)——PlayerLayer的搭建

    一.创建文件~ PlayerLayer.h PlayerLayer.cpp 一般类名都会和文件名有关系的~(在这里当然是一样) 二.How to do? 1.首先就是放一个飞机~ CC_SYNTHES ...

  7. cocos2dx游戏开发——微信打飞机学习笔记(五)——BackgroundLayer的搭建

    一.创建文件~ 文件名:BackgroundLayer.h BackgroundLayer.cpp 架构就跟前面的一样,我就直接进入正题 啦,而且github有完整代码,欢迎下载~ 二.创建滚动的背景 ...

  8. cocos2dx游戏开发——微信打飞机学习笔记(十)——碰撞检测的搭建

    一.七说八说        大家都发现了= =,做了那么多,发现就是摆设,完全没有打飞机的感觉,没有实现碰撞的监测.比如说呢,子弹和敌机,玩家与敌机就是需要有碰撞检测的说,然后在这篇我想会很长很长的教 ...

  9. 杨老师课堂_VBA学习教程之根据部门列创建工作表

    课件下载 : 方式1:本节课件下载地址:链接: https://pan.baidu.com/s/1rf5pRmZ95fjVbz70KYi6Aw 密码: q9yk 方式2:或点击此处下载 效果预览图: ...

随机推荐

  1. Linux U盘安装

    Ubuntu 15 U盘安装: 用UltraISO把iso文件写入到U盘中,选择hdd+模式. u盘启动后提示not a com32r image,先按tab键,然后输入live进入试用模式,然后再点 ...

  2. eclipse server和tomcat的区别,将server的部署目录改到自己安装的tomcat中及如何设置tomcat用户

    转:http://www.cnblogs.com/Yogurshine/archive/2013/06/05/3118525.html 一.发现问题(如果不把项目部署到tomcat的webapp目录下 ...

  3. loadrunner http协议性能测试脚本编写

    性能测试其实测的就是接口的性能,不管是用工具录制还是自己写,都是围绕接口的,录制也是把接口录制下来而已,但是录制下来的脚本比较乱,会把很多相关的请求都录下来. 在这里我们手动写HTTP协议的get.p ...

  4. CodeForces - 631C (截取法)

    C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  5. [深入理解Java虚拟机]<自动内存管理>

    Overview 走近Java:介绍Java发展史 第二部分:自动内存管理机制 程序员把内存控制的权利交给了Java虚拟机,从而可以在编码时享受自动内存管理.但另一方面一旦出现内存泄漏和溢出等问题,就 ...

  6. select标签的相关操作,选中,获取option的值,二级联动

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  7. HIVE点滴:group by和distinct语句的执行顺序

    同一条语句之中,如果同时有group by和distinct语句,是先group by后distinct,还是先distinct后group by呢? 先说结论:先group by后distinct. ...

  8. Java虚拟机的组成

    Java虚拟机主要分为以下五个区: 一.方法区: 1. 有时候也成为永久代,在该区内很少发生垃圾回收,但是并不代表不发生GC,在这里进行的GC主要是对方法区里的常量池和对类型的卸载 2. 方法区主要用 ...

  9. Shiro自定义Realm时用注解的方式注入父类的credentialsMatcher

    用Shiro做登录权限控制时,密码加密是自定义的. 数据库的密码通过散列获取,如下,算法为:md5,盐为一个随机数字,散列迭代次数为3次,最终将salt与散列后的密码保存到数据库内,第二次登录时将登录 ...

  10. 排序jq

    var arr = [1,2,3,4,5,6,7]; arr.sort(function (a, b) { 从大到小 if (a > b) { return 1; } else if (a &l ...