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
using UnityEngine;
using System.Collections;
using LitJson;
public class CommunicationCenter : MonoBehaviour 
{
	public static CommunicationCenter Instance;
	
	public GameObject smallCamera;
	public GameObject smallCamera1;
	public GameObject smallCamera2;

	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 TimeWindow timeWindow;

	private bool finished = false;

	private int allies;
	void Awake()
	{
		Instance = this;
	}
	void Start()
	{
		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;
		if(smallCameraShowTime<0)
		{
			ShowSmallCamera(false);
			ShowSmallCamera1(false);
			ShowSmallCamera2(false);
		}
		if(!finished)
		{
			CheckTask();
		}
	}

	public void DestroyOneEnemy(GameObject enemy)
	{
		EnemyPool.Instance.DestroyOneEnemy(enemy);
		ShowSmallCamera(true);
		MessageWindow.Instance.NewMessage("An enemy ship has been destroyed!");
		haveToKill--;
	}

	public void DestroyOneAlly(GameObject ally)
	{
		AllyPool.Instance.DestroyOneAlly(ally);
		ShowSmallCamera1(true);
		MessageWindow.Instance.NewMessage("An ally ship has been destroyed!");
		haveToKill--;
	}

	public void AllyDestroyOneEnemy(GameObject enemy)
	{
		EnemyPool.Instance.DestroyOneEnemy(enemy);
		ShowSmallCamera(true);
		MessageWindow.Instance.NewMessage("An ally destroyed one enemy ship!");
		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;
		}
	}

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

		if(EnemyPool.Instance.aliveEnemy<=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
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 Diff Diff LMancini picture LMancini Wed 05 Nov, 2014 15:33:48 +0000
117 Diff Diff DRuega picture DRuega Tue 28 Oct, 2014 13:39:51 +0000
112 Diff Diff FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 14:21:59 +0000
107 FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 11:56:46 +0000