Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
using UnityEngine;
using System.Collections;
using LitJson;
public class CommunicationCenter : MonoBehaviour 
{
	public static CommunicationCenter Instance;
	
	public GameObject smallCamera;
	public GameObject smallCamera1;
	public GameObject smallCamera2;
	public GameObject smallCameraInizio;
	public GameObject smallCameraNemico;
	public GameObject smallCameraInizio2;
	public GameObject smallCameraInizio3;

	private string missionName;
	private string description;
	
	public enum ShipLimit{NO_LIMIT,LIMIT};

	//private ShipLimit shipLimit;

	private int haveToKill;

	//RESIST: resist fixed time to win.
	//LIMIT: should finish in fixed time.
	public enum TimeLimit{NO_LIMIT,RESIST,LIMIT};
	public TimeLimit timeLimit;
	private int resistTime;

	private float smallCameraShowTime = 0;
	private float smallCameraShowTime1 = 8;
	private float smallCameraShowTime2 = 13;
	private float smallCameraShowTime3 = 16;
	public float tempoCameraNemico = 5f;
	public float tempoCamera2 = 7.5f;
	public float tempoCamera3 = 12.5f;

	private TimeWindow timeWindow;

	private bool finished = false;

	private int allies;
	void Awake()
	{
		Instance = this;
	}
	void Start()
	{
		ShowSmallCameraInizio(true);
		timeWindow = TimeWindow.Instance;
		if(GlobalObject.Instance!=null)
		{
			LoadDataOfMission(GlobalObject.Instance.nowLevel);
		}
		if(EnemyPool.Instance!=null)
		{
			EnemyPool.Instance.StartGame();
		}

		if (AllyPool.Instance!=null)
		{
			AllyPool.Instance.StartGame();
		}
	}
	void LoadDataOfMission(int missionID)
	{
		try
		{
			haveToKill = 0;
			TextAsset ta = Resources.Load("Json/mission")as TextAsset;
			JsonData jd = JsonMapper.ToObject(ta.text);
			jd = jd["missions"];
			JsonData missionData = jd[missionID];
			missionName = missionData["name"].ToString();
			description = missionData["description"].ToString();
			JsonData enemies = missionData["enemies"];
			for(int i=0;i<enemies.Count;i++)
			{
				int cnt = int.Parse(enemies["type"+i].ToString());
				haveToKill += cnt;
				EnemyPool.Instance.InsertEnemy(i,cnt);
			}
			allies = int.Parse(missionData["allies"].ToString());

			AllyPool.Instance.InsertAlly(0, allies);

			JsonData subMission = missionData["submissions"];
			//int kill = int.Parse(subMission["kill-enemy-number"].ToString());
			/*
			if(kill==0)
			{
				shipLimit = ShipLimit.NO_LIMIT;
			}
			else
			{
				shipLimit = ShipLimit.LIMIT;
			}*/

			resistTime = int.Parse(subMission["time"].ToString());
			if(resistTime <0)
			{
				resistTime = -resistTime;
				timeWindow.timeToShow = resistTime;
				timeWindow.direction = -1;
				timeLimit = TimeLimit.LIMIT;
			}
			else if(resistTime>0)
			{
				timeWindow.timeToShow = resistTime;
				timeWindow.direction = -1;
				timeLimit = TimeLimit.RESIST;
			}
			else
			{
				timeWindow.timeToShow = 0;
				timeWindow.direction = 1;
				timeLimit = TimeLimit.NO_LIMIT;
			}

			MessageWindow.Instance.NewMessage(missionName);
			MessageWindow.Instance.NewMessage(description);

		}
		catch(JsonException e)
		{
			Debug.Log(e.Message);
		}
	}

	void Update()
	{
		smallCameraShowTime-=Time.deltaTime;
		smallCameraShowTime1 -= Time.deltaTime;
		smallCameraShowTime2 -= Time.deltaTime;
		smallCameraShowTime3 -= Time.deltaTime;
		tempoCameraNemico -= Time.deltaTime;
		tempoCamera2 -= Time.deltaTime;
		tempoCamera3 -= Time.deltaTime;

		if (tempoCameraNemico < 0 && smallCameraShowTime1 > 0) {
						ShowSmallCameraNemico (true);
				} else 
			ShowSmallCameraNemico (false);;

		if (tempoCamera2 < 0 && smallCameraShowTime2 > 0) {
						ShowSmallCameraInizio2 (true);
				} else
						ShowSmallCameraInizio2 (false);

		if (tempoCamera3 < 0 && smallCameraShowTime3 > 0) {
			ShowSmallCameraInizio3(true);
		} else
			ShowSmallCameraInizio3(false);

		if(smallCameraShowTime<0)
		{
			ShowSmallCamera(false);
			ShowSmallCamera1(false);
			ShowSmallCamera2(false);
			ShowSmallCameraInizio(false);
		}

		if(!finished)
		{
			CheckTask();
		}
	}

	public void DestroyOneEnemy(GameObject enemy)
	{
		ShowSmallCamera(true);

		PilotNameGenerator cmp = enemy.GetComponent<PilotNameGenerator>();
		if (cmp != null)
		{
			MessageWindow.Instance.NewMessage(cmp.getPilotName() + " enemy's ship has been destroyed!");
		}
		EnemyPool.Instance.DestroyOneEnemy(enemy);
		haveToKill--;
	}

	public void DestroyOneAlly(GameObject ally)
	{
		ShowSmallCamera1(true);

		//AllyPool.Instance.DestroyOneAlly(ally);
		MessageWindow.Instance.NewMessage("An ally ship has been destroyed!");
		//haveToKill--;
	}

	public void AllyDestroyOneEnemy(GameObject enemy)
	{
		ShowSmallCamera(true);
		PilotNameGenerator cmp = enemy.GetComponent<PilotNameGenerator>();
		if (cmp != null)
		{
			MessageWindow.Instance.NewMessage(cmp.getPilotName() + " enemy's ship has been destroyed by an ally!");
		}

		EnemyPool.Instance.DestroyOneEnemy(enemy);
		haveToKill--;
	}

	public void ShowSmallCamera(bool show)
	{
		if(smallCamera.activeSelf!=show)
		{
			smallCamera.SetActive(show);
		}
		if(show)
		{
			smallCameraShowTime = 5;
		}
	}

	public void ShowSmallCamera1(bool show)
	{
		if(smallCamera1.activeSelf!=show)
		{
			smallCamera1.SetActive(show);
		}
		if(show)
		{
			smallCameraShowTime = 5;
		}
	}

	public void ShowSmallCamera2(bool show)
	{
		if(smallCamera2.activeSelf!=show)
		{
			smallCamera2.SetActive(show);
		}
		if(show)
		{
			smallCameraShowTime = 5;
		}
	}

	public void ShowSmallCameraInizio(bool show)
	{
		if(smallCameraInizio.activeSelf!=show)
		{
			smallCameraInizio.SetActive(show);
		}
		if(show)
		{
			smallCameraShowTime = 7.5F;
		}
	}

	public void ShowSmallCameraInizio2(bool show)
	{
		if(smallCameraInizio2.activeSelf!=show)
		{
			smallCameraInizio2.SetActive(show);
		}
	}

	public void ShowSmallCameraInizio3(bool show)
	{
		if(smallCameraInizio3.activeSelf!=show)
		{
			smallCameraInizio3.SetActive(show);
		}
	}

	public void ShowSmallCameraNemico(bool show)
	{
		if(smallCameraNemico.activeSelf!=show)
		{
			smallCameraNemico.SetActive(show);
		}
	}

	void CheckTask()
	{
		if (!EnemyPool.Instance) return;

		if(EnemyPool.Instance.getRemainingEnemiesToKill() == 0)
		{
			WinGame();
			return;
		}

		if(timeLimit==TimeLimit.RESIST && timeWindow.timeToShow<=0 && haveToKill<=0)
		{
			WinGame();
			return;
		}
		if(timeLimit==TimeLimit.LIMIT && timeWindow.timeToShow <= 0)
		{
			FailGame();
			return;
		}
		if((timeLimit==TimeLimit.NO_LIMIT || timeLimit==TimeLimit.LIMIT) && haveToKill<=0)
		{
			WinGame();
			return;
		}
	}

	public void WinGame()
	{
		finished = true;
		SU_Spaceship ship = GameManager.GetHero().GetComponent<SU_Spaceship>();
		ship.Finish();
		GlobalObject.Instance.WinThisLevel(true);
	}

	public void FailGame()
	{
		finished = true;
		if(GameManager.GetHero()!=null)
		{
			GameManager.GetHero().gameObject.SetActive(false);
		}
		if (GlobalObject.Instance)
		{
			GlobalObject.Instance.WinThisLevel(false);
		}
	}
}

Commits for Nextrek/3DSpace/Assets/Custum/Scripts/CommunicationCenter.cs

Diff revisions: vs.
Revision Author Commited Message
144 Diff Diff LMancini picture LMancini Mon 17 Nov, 2014 15:18:43 +0000
140 Diff Diff LMancini picture LMancini Thu 13 Nov, 2014 23:04:13 +0000
131 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 18:25:48 +0000

Merge.

130 Diff Diff LMancini picture LMancini Thu 06 Nov, 2014 18:03:48 +0000
127 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 16:52:49 +0000

Aggiungo PilotNameGenerator.cs

Genera nomi random alle navi... così sembra più figo :) :)

126 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 14:45:25 +0000

Cleanup, warnings e altre minchiate :)

125 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 13:44:02 +0000

Migliorata la ricerca del nemico più vicino pesando di più la differenza angolare.
Migliorato lo script dei missili.

122 Diff Diff DRuega picture DRuega Thu 06 Nov, 2014 10:12:00 +0000

Tocco Magico :P
1) Centralizzata creazione navi
2) Levato dove possibile *.Instance.spaceShip
3) Implementato GameManager.GetClosestEnemy usato da Ally. In un secondo momento va messo nella logica del missile.
GetClosestEnemy usa una funzione score valutando distanza e angolo; Privilegia obiettivi sul vettore forward.

120 Diff Diff LMancini picture LMancini Wed 05 Nov, 2014 18:41:05 +0000
119 LMancini picture LMancini Wed 05 Nov, 2014 15:33:48 +0000