|
@@ -3,60 +3,59 @@ |
3 |
3 |
|
|
4 |
4 |
|
public class EnemyShip : MonoBehaviour |
5 |
5 |
|
{ |
|
6 |
+ |
public static float ROTATION_SPEED = 0.75f; // degrees |
|
7 |
+ |
|
6 |
8 |
|
public enum ShipType {SMALL_SHIP, BIG_SHIP}; |
7 |
9 |
|
public ShipType shipType; |
8 |
10 |
|
public float life = 1000; |
|
11 |
+ |
public float topSpeed = 100.0f; |
|
12 |
+ |
public int maxShoots = 5; |
|
13 |
+ |
public float fireRate = 0.5f; |
|
14 |
+ |
public float reloadTime = 5.0f; |
|
15 |
+ |
public float shootRange = 2000.0f; |
9 |
16 |
|
|
10 |
17 |
|
public Vector3[] weaponMountPoints; |
11 |
18 |
|
public Transform laserShotPrefab; |
12 |
19 |
|
public AudioClip soundEffectFire; |
13 |
20 |
|
|
14 |
|
- |
public static float FIRE_RATE = 0.5f; |
15 |
|
- |
public static float RELOAD_TIME = 5.0f; |
16 |
|
- |
public static int MAX_SHOOTS = 5; |
17 |
|
- |
|
18 |
|
- |
public static float MIN_DISTANCE = 50.0f; |
|
21 |
+ |
private static float BIG_ENEMY_MIN_RANGE = 10000.0f; |
|
22 |
+ |
private static float BIG_ENEMY_MAX_RANGE = 20000.0f; |
19 |
23 |
|
|
20 |
|
- |
public static float MAX_SPEED = 100.0f; |
21 |
|
- |
public static float ROTATION_SPEED = 0.75f; // degrees |
22 |
|
- |
|
23 |
|
- |
public static float BIG_ENEMY_MIN_RANGE = 10000.0f; |
24 |
|
- |
public static float BIG_ENEMY_MAX_RANGE = 20000.0f; |
|
24 |
+ |
private static float SMALL_ENEMY_INITIAL_RANGE = 20000.0f; |
|
25 |
+ |
private static float SMALL_ENEMY_START_RANGE = 3500.0f; |
25 |
26 |
|
|
26 |
|
- |
public static float SMALL_ENEMY_MIN_RANGE = 3000.0f; |
27 |
|
- |
public static float SMALL_ENEMY_MAX_RANGE = 8000.0f; |
28 |
|
- |
|
29 |
|
- |
public static float EVADE_DISTANCE = 400.0f; |
|
27 |
+ |
private static float WARP_SPEED = 10000.0f; |
|
28 |
+ |
private static float EVADE_DISTANCE = 400.0f; |
30 |
29 |
|
|
31 |
|
- |
public static float WEAPON_AIM = 2.5f; // degrees |
|
30 |
+ |
private static float WEAPON_AIM = 2.5f; // degrees |
32 |
31 |
|
|
33 |
|
- |
private float timeToShot = RELOAD_TIME; |
34 |
|
- |
private int availableShoots = MAX_SHOOTS; |
|
32 |
+ |
private float timeToShot = 0; |
|
33 |
+ |
private int availableShoots = 0; |
35 |
34 |
|
|
36 |
|
- |
private Material mat; |
37 |
35 |
|
private bool isAlive = true; |
38 |
36 |
|
|
|
37 |
+ |
private bool isEnteringArea = true; |
|
38 |
+ |
private Vector3 initialPosition; |
|
39 |
+ |
|
39 |
40 |
|
float genCoord(float min_distance, float max_distance) { |
40 |
41 |
|
return (Random.value - Random.value) * (min_distance + Random.value * (max_distance-min_distance)); |
41 |
42 |
|
} |
42 |
43 |
|
|
43 |
|
- |
public string pilotName; |
44 |
|
- |
|
45 |
44 |
|
void Start() |
46 |
45 |
|
{ |
47 |
|
- |
pilotName = PilotNameGenerator.GetNick(); |
48 |
|
- |
|
49 |
46 |
|
if(shipType==ShipType.SMALL_SHIP) |
50 |
47 |
|
{ |
51 |
|
- |
this.transform.position = new Vector3( |
52 |
|
- |
genCoord(SMALL_ENEMY_MIN_RANGE, SMALL_ENEMY_MAX_RANGE), |
53 |
|
- |
genCoord(SMALL_ENEMY_MIN_RANGE, SMALL_ENEMY_MAX_RANGE), |
54 |
|
- |
genCoord(SMALL_ENEMY_MIN_RANGE, SMALL_ENEMY_MAX_RANGE) ); |
|
48 |
+ |
this.transform.position = Random.onUnitSphere * SMALL_ENEMY_INITIAL_RANGE; |
|
49 |
+ |
Transform spaceShip = GameManager.GetHero(); |
|
50 |
+ |
if (spaceShip != null) |
|
51 |
+ |
{ |
|
52 |
+ |
this.transform.LookAt(spaceShip.position); |
|
53 |
+ |
return; |
|
54 |
+ |
} |
|
55 |
+ |
|
55 |
56 |
|
} |
56 |
57 |
|
else |
57 |
58 |
|
{ |
58 |
|
- |
pilotName = PilotNameGenerator.GetTitle() + " " + pilotName; |
59 |
|
- |
|
60 |
59 |
|
this.transform.position = new Vector3( |
61 |
60 |
|
genCoord(BIG_ENEMY_MIN_RANGE, BIG_ENEMY_MAX_RANGE), |
62 |
61 |
|
genCoord(BIG_ENEMY_MIN_RANGE, BIG_ENEMY_MAX_RANGE), |
|
@@ -128,6 +127,19 @@ |
128 |
127 |
|
|
129 |
128 |
|
if (spaceShip==null) return; |
130 |
129 |
|
|
|
130 |
+ |
if (isEnteringArea) |
|
131 |
+ |
{ |
|
132 |
+ |
if (Vector3.Distance(this.transform.position, spaceShip.position) > SMALL_ENEMY_START_RANGE) |
|
133 |
+ |
{ |
|
134 |
+ |
this.transform.Translate( Vector3.forward * WARP_SPEED * Time.deltaTime ); |
|
135 |
+ |
return; |
|
136 |
+ |
} |
|
137 |
+ |
else |
|
138 |
+ |
{ |
|
139 |
+ |
isEnteringArea = false; |
|
140 |
+ |
} |
|
141 |
+ |
} |
|
142 |
+ |
|
131 |
143 |
|
/*** |
132 |
144 |
|
* Navigation routine |
133 |
145 |
|
*/ |
|
@@ -136,7 +148,7 @@ |
136 |
148 |
|
// The step size is equal to speed times frame time. |
137 |
149 |
|
float step = ROTATION_SPEED * Time.deltaTime; |
138 |
150 |
|
|
139 |
|
- |
float speed = MAX_SPEED * Time.deltaTime; |
|
151 |
+ |
float speed = topSpeed * Time.deltaTime; |
140 |
152 |
|
|
141 |
153 |
|
Vector3 targetDir; |
142 |
154 |
|
|
|
@@ -147,15 +159,16 @@ |
147 |
159 |
|
|
148 |
160 |
|
} else { |
149 |
161 |
|
targetDir = spaceShip.position - this.transform.position; |
|
162 |
+ |
targetDir.Normalize(); |
150 |
163 |
|
} |
151 |
164 |
|
|
152 |
165 |
|
//Debug.DrawLine (this.transform.position, this.transform.position + targetDir*100.0f, Color.green); |
153 |
166 |
|
|
154 |
167 |
|
Vector3 newDir = Vector3.RotateTowards (this.transform.forward, targetDir, step, 0.0f); |
155 |
168 |
|
this.transform.rotation = Quaternion.LookRotation (newDir); |
156 |
|
- |
if (distance > MIN_DISTANCE) { |
157 |
|
- |
this.transform.Translate( Vector3.forward * speed ); |
158 |
|
- |
} |
|
169 |
+ |
|
|
170 |
+ |
this.transform.Translate( Vector3.forward * speed ); |
|
171 |
+ |
|
159 |
172 |
|
/*** |
160 |
173 |
|
* Fire routine |
161 |
174 |
|
*/ |
|
@@ -166,16 +179,18 @@ |
166 |
179 |
|
} |
167 |
180 |
|
|
168 |
181 |
|
targetDir = spaceShip.position - this.transform.position; |
|
182 |
+ |
if (targetDir.magnitude > shootRange) return; |
|
183 |
+ |
|
169 |
184 |
|
float cosAlpha = Vector3.Dot (this.transform.forward, targetDir); |
170 |
|
- |
if (cosAlpha < 0.0f) return; |
|
185 |
+ |
if (cosAlpha < 0.5f) return; |
171 |
186 |
|
|
172 |
187 |
|
if (availableShoots > 0) { |
173 |
188 |
|
availableShoots--; |
174 |
189 |
|
Fire(); |
175 |
|
- |
timeToShot += FIRE_RATE; |
|
190 |
+ |
timeToShot += fireRate; |
176 |
191 |
|
} else { |
177 |
|
- |
timeToShot = RELOAD_TIME; |
178 |
|
- |
availableShoots += MAX_SHOOTS; |
|
192 |
+ |
timeToShot = reloadTime; |
|
193 |
+ |
availableShoots += maxShoots; |
179 |
194 |
|
} |
180 |
195 |
|
} |
181 |
196 |
|
} |