Subversion Repository Public Repository

Nextrek

Diff Revisions 140 vs 141 for /3DSpace/Assets/Custum/Scripts/EnemyShip.cs

Diff revisions: vs.
  @@ -26,9 +26,7 @@
26 26
27 27 private static float WARP_SPEED = 10000.0f;
28 28 private static float EVADE_DISTANCE = 400.0f;
29 -
30 - private static float WEAPON_AIM = 2.5f; // degrees
31 -
29 +
32 30 private float timeToShot = 0;
33 31 private int availableShoots = 0;
34 32
  @@ -87,12 +85,58 @@
87 85 }
88 86 }
89 87
88 + GameObject _lastTarget = null;
89 + float _timer = 0;
90 + private static float CHANGE_TARGET_TIMER = 5000.0f;
91 +
90 92 void Update()
91 93 {
94 + //Transform spaceShip = GameManager.Instance.spaceShip;
95 + //if (spaceShip==null) return;
96 + _timer += Time.deltaTime;
97 +
98 + if ((_lastTarget == null) || (_timer > CHANGE_TARGET_TIMER))
99 + {
100 + _timer = 0;
101 + _lastTarget = GameManager.GetClosestShip(GameManager.ALLY_TAG, this.gameObject);
102 + }
103 +
104 + if (_lastTarget == null) return;
105 +
106 + Transform spaceShip = _lastTarget.transform;
107 +
92 108 if(shipType==ShipType.SMALL_SHIP)
93 109 {
94 - DoSmallShip();
110 + DoSmallShip(spaceShip);
95 111 }
112 +
113 + /***
114 + * Fire routine
115 + */
116 +
117 + timeToShot -= Time.deltaTime;
118 + if(timeToShot>0.0f) {
119 + return;
120 + }
121 +
122 + Vector3 targetDir = spaceShip.position - this.transform.position;
123 + if (targetDir.magnitude > shootRange) return;
124 +
125 + if(shipType==ShipType.SMALL_SHIP)
126 + {
127 + float cosAlpha = Vector3.Dot (this.transform.forward, targetDir);
128 + if (cosAlpha < 0.5f) return;
129 + }
130 +
131 + if (availableShoots > 0) {
132 + availableShoots--;
133 + Fire();
134 + timeToShot += fireRate;
135 + } else {
136 + timeToShot = reloadTime;
137 + availableShoots += maxShoots;
138 + }
139 +
96 140 }
97 141
98 142 void OnComplete()
  @@ -103,42 +147,25 @@
103 147 {
104 148 foreach (Vector3 _wmp in weaponMountPoints)
105 149 {
106 - Quaternion small = Quaternion.Euler(Random.Range(-WEAPON_AIM,WEAPON_AIM),
107 - Random.Range(-WEAPON_AIM,WEAPON_AIM),
108 - Random.Range(-WEAPON_AIM,WEAPON_AIM)
109 - );
110 - small = small*this.transform.rotation;
111 -
112 150 Vector3 _pos = transform.position + transform.right * _wmp.x + transform.up * _wmp.y + transform.forward * _wmp.z;
113 - Transform _laserShot = (Transform) Instantiate(laserShotPrefab, _pos, small);
114 - _laserShot.GetComponent<SU_LaserShot>().firedBy = transform;
151 + if(shipType==ShipType.SMALL_SHIP)
152 + {
153 + WeaponFireUtils.FireLaser(laserShotPrefab, _pos, this.transform.rotation, this.gameObject, GameManager.ALLY_TAG);
154 + }
155 + else
156 + {
157 + WeaponFireUtils.FireLaserTurret(laserShotPrefab, _pos, this.transform.rotation, this.gameObject, GameManager.ALLY_TAG);
158 + }
115 159 }
116 -
160 +
117 161 if (soundEffectFire != null)
118 162 {
119 163 audio.PlayOneShot(soundEffectFire);
120 164 }
121 165 }
122 -
123 - GameObject _lastTarget = null;
124 - float _timer = 0;
125 - private static float CHANGE_TARGET_TIMER = 5000.0f;
126 -
127 - void DoSmallShip()
166 +
167 + void DoSmallShip(Transform spaceShip)
128 168 {
129 - //Transform spaceShip = GameManager.Instance.spaceShip;
130 - //if (spaceShip==null) return;
131 - _timer += Time.deltaTime;
132 -
133 - if ((_lastTarget == null) || (_timer > CHANGE_TARGET_TIMER))
134 - {
135 - _timer = 0;
136 - _lastTarget = GameManager.GetClosestShip(GameManager.ALLY_TAG, this.gameObject);
137 - }
138 -
139 - if (_lastTarget == null) return;
140 -
141 - Transform spaceShip = _lastTarget.transform;
142 169
143 170 if (isEnteringArea)
144 171 {
  @@ -182,29 +209,5 @@
182 209 this.transform.rotation = Quaternion.LookRotation (newDir);
183 210
184 211 this.transform.Translate( Vector3.forward * speed );
185 -
186 - /***
187 - * Fire routine
188 - */
189 -
190 - timeToShot -= Time.deltaTime;
191 - if(timeToShot>0.0f) {
192 - return;
193 - }
194 -
195 - targetDir = spaceShip.position - this.transform.position;
196 - if (targetDir.magnitude > shootRange) return;
197 -
198 - float cosAlpha = Vector3.Dot (this.transform.forward, targetDir);
199 - if (cosAlpha < 0.5f) return;
200 -
201 - if (availableShoots > 0) {
202 - availableShoots--;
203 - Fire();
204 - timeToShot += fireRate;
205 - } else {
206 - timeToShot = reloadTime;
207 - availableShoots += maxShoots;
208 - }
209 212 }
210 213 }