Rev 7 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | freddie | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Data; |
||
5 | using System.Drawing; |
||
6 | using System.Text; |
||
7 | using System.Windows.Forms; |
||
8 | |||
9 | namespace blockade |
||
10 | { |
||
11 | public partial class Form1 : Form |
||
12 | { |
||
13 | |||
14 | public class smoke |
||
15 | { |
||
16 | public Color colour; |
||
17 | public Point loc; |
||
18 | public int time; |
||
19 | |||
20 | public smoke(Color colourN, Point locN, int timeN) |
||
21 | { |
||
22 | colour = colourN; |
||
23 | loc = locN; |
||
24 | time = timeN; |
||
25 | } |
||
26 | } |
||
27 | |||
28 | public class enemyType |
||
29 | { |
||
30 | public float health, speed, spawnChance; |
||
31 | public int child, value, spawn; |
||
32 | public animg img; |
||
33 | |||
34 | public Image getImg() |
||
35 | { |
||
36 | return img.curImg(); |
||
37 | } |
||
38 | |||
39 | public Image getImg(int num) |
||
40 | { |
||
41 | img.runTime = num; |
||
42 | return img.curImg(); |
||
43 | } |
||
44 | |||
45 | public enemyType(string healthN, string speedN, string childN, string spawnN, string spawnChanceN, string imgN) |
||
46 | { |
||
47 | health = float.Parse(healthN); |
||
48 | speed = float.Parse(speedN); |
||
49 | child = int.Parse(childN); |
||
50 | img = new animg(imgN); |
||
51 | spawn = int.Parse(spawnN); |
||
52 | spawnChance = float.Parse(spawnChanceN); |
||
53 | value = (int)(speed * health / 20 + health / 20); |
||
54 | } |
||
55 | |||
56 | public enemyType(string[] data) |
||
57 | { |
||
58 | health = float.Parse(data[0]); |
||
59 | speed = float.Parse(data[1]); |
||
60 | child = int.Parse(data[2]); |
||
61 | spawn = int.Parse(data[3]); |
||
62 | spawnChance = float.Parse(data[4]); |
||
63 | img = new animg(data[5]); |
||
64 | value = (int)(speed * health / 50 + health / 20); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | public class enemy |
||
69 | { |
||
70 | public int type; |
||
71 | public float health; |
||
72 | public float angle; |
||
73 | public PointF loc; |
||
74 | public int imgTime; |
||
75 | public float dX, dY; |
||
76 | |||
77 | public void incImg() |
||
78 | { |
||
79 | imgTime++; |
||
80 | } |
||
81 | |||
82 | public enemy(int typeN, float healthN, float angleN, PointF locN) |
||
83 | { |
||
84 | // have to pass health, enemy cannot work it out |
||
85 | type = typeN; |
||
86 | health = healthN; |
||
87 | angle = angleN; |
||
88 | loc = locN; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | public class missileType |
||
93 | { |
||
94 | public Image img; |
||
95 | public int speed, damage, spread; |
||
96 | public float energy; |
||
97 | |||
98 | public missileType(string imgN, string speedN, string damageN, string spreadN, string energyN) |
||
99 | { |
||
100 | img = Image.FromFile(imgN); |
||
101 | speed = int.Parse(speedN); |
||
102 | damage = int.Parse(damageN); |
||
103 | spread = int.Parse(spreadN); |
||
104 | } |
||
105 | |||
106 | public missileType(string[] data) |
||
107 | { |
||
108 | img = Image.FromFile(data[0]); |
||
109 | speed = int.Parse(data[1]); |
||
110 | damage = int.Parse(data[2]); |
||
111 | spread = int.Parse(data[3]); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | public class towerType |
||
116 | { |
||
117 | public Color laserColour; |
||
118 | public int missileID; |
||
119 | public float maxEnergy, gainRate, useRate, damage; |
||
120 | public int cost, range, laserType, extRange, killNum; |
||
121 | public animg baseImg, turretImg; |
||
122 | public int req, delay; |
||
123 | public string sound; |
||
124 | public string name; |
||
125 | public string[] details; |
||
126 | |||
127 | public Image getBaseImg() |
||
128 | { |
||
129 | return baseImg.curImg(); |
||
130 | } |
||
131 | |||
132 | public Image getTurretImg() |
||
133 | { |
||
134 | return turretImg.curImg(); |
||
135 | } |
||
136 | |||
137 | public Image getBaseImg(int num) |
||
138 | { |
||
139 | baseImg.runTime = num; |
||
140 | return baseImg.curImg(); |
||
141 | } |
||
142 | |||
143 | public Image getTurretImg(int num) |
||
144 | { |
||
145 | turretImg.runTime = num; |
||
146 | return turretImg.curImg(); |
||
147 | } |
||
148 | |||
149 | public towerType(string laserColourN, string maxEnergyN, string gainRateN, string useRateN, string rangeN, string costN, string reqN, string delayN, string baseImgN, string turretImgN, string soundN, string laserTypeN, string extRangeN, string killNumN, string nameN, string detailsN) |
||
150 | { |
||
151 | laserColour = Color.FromName(laserColourN); |
||
152 | maxEnergy = int.Parse(maxEnergyN); |
||
153 | gainRate = float.Parse(gainRateN); |
||
154 | useRate = float.Parse(useRateN); |
||
155 | damage = useRate; |
||
156 | cost = int.Parse(costN); |
||
157 | range = int.Parse(rangeN); |
||
158 | req = int.Parse(reqN); |
||
159 | delay = int.Parse(delayN); |
||
160 | baseImg = new animg(baseImgN); |
||
161 | turretImg = new animg(turretImgN); |
||
162 | sound = soundN; |
||
163 | laserType = int.Parse(laserTypeN); |
||
164 | extRange = int.Parse(extRangeN); |
||
165 | killNum = int.Parse(killNumN); |
||
166 | name = nameN; |
||
167 | details = detailsN.Split(':'); |
||
168 | |||
169 | for (int i = 0; i < details.Length; i++) |
||
170 | details[i] = details[i].Replace('`', ','); |
||
171 | } |
||
172 | |||
173 | public towerType(string missileIDN, string maxEnergyN, string gainRateN, string rangeN, string costN, string reqN, string delayN, string baseImgN, string turretImgN, string soundN, string nameN, string detailsN) |
||
174 | { |
||
175 | missileID = int.Parse(missileIDN); |
||
176 | maxEnergy = int.Parse(maxEnergyN); |
||
177 | gainRate = float.Parse(gainRateN); |
||
178 | cost = int.Parse(costN); |
||
179 | range = int.Parse(rangeN); |
||
180 | req = int.Parse(reqN); |
||
181 | delay = int.Parse(delayN); |
||
182 | baseImg = new animg(baseImgN); |
||
183 | turretImg = new animg(turretImgN); |
||
184 | sound = soundN; |
||
185 | name = nameN; |
||
186 | details = detailsN.Split(':'); |
||
187 | |||
188 | for (int i = 0; i < details.Length; i++) |
||
189 | details[i] = details[i].Replace('`', ','); |
||
190 | } |
||
191 | |||
192 | public towerType(string[] data) |
||
193 | { |
||
194 | |||
195 | if (data.Length == 16) |
||
196 | { |
||
197 | laserColour = Color.FromName(data[0]); |
||
198 | maxEnergy = int.Parse(data[1]); |
||
199 | gainRate = float.Parse(data[2]); |
||
200 | useRate = float.Parse(data[3]); |
||
201 | damage = useRate; |
||
202 | cost = int.Parse(data[4]); |
||
203 | range = int.Parse(data[5]); |
||
204 | req = int.Parse(data[6]); |
||
205 | delay = int.Parse(data[7]); |
||
206 | baseImg = new animg(data[8]); |
||
207 | turretImg = new animg(data[9]); |
||
208 | sound = @"data/" + data[10]; |
||
209 | laserType = int.Parse(data[11]); |
||
210 | extRange = int.Parse(data[12]); |
||
211 | killNum = int.Parse(data[13]); |
||
212 | name = data[14]; |
||
213 | details = data[15].Split(':'); |
||
214 | } |
||
215 | else |
||
216 | { |
||
217 | missileID = int.Parse(data[0]); |
||
218 | maxEnergy = int.Parse(data[1]); |
||
219 | gainRate = float.Parse(data[2]); |
||
220 | cost = int.Parse(data[3]); |
||
221 | range = int.Parse(data[4]); |
||
222 | req = int.Parse(data[5]); |
||
223 | delay = int.Parse(data[6]); |
||
224 | baseImg = new animg(data[7]); |
||
225 | turretImg = new animg(data[8]); |
||
226 | sound = @"data/" + data[9]; |
||
227 | name = data[10]; |
||
228 | details = data[11].Split(':'); |
||
229 | } |
||
230 | |||
231 | for (int i = 0; i < details.Length; i++) |
||
232 | details[i] = details[i].Replace('`', ','); |
||
233 | |||
234 | } |
||
235 | } |
||
236 | |||
237 | public class tower |
||
238 | { |
||
239 | public int type, delayTime; |
||
240 | public float energy, glow, angle; |
||
241 | public bool fireing; |
||
242 | public Point loc; |
||
243 | public int baseTime, turretTime; |
||
244 | public List<int> targets; |
||
245 | // public WMPLib.WindowsMediaPlayer s; |
||
246 | |||
247 | public int target |
||
248 | { |
||
249 | get |
||
250 | { |
||
251 | if (targets.Count != 0) |
||
252 | return targets[0]; |
||
253 | else |
||
254 | return -1; |
||
255 | } |
||
256 | set |
||
257 | { |
||
258 | if (value == -1) |
||
259 | targets.Clear(); |
||
260 | else if (targets.Count == 0) |
||
261 | targets.Add(value); |
||
262 | else |
||
263 | targets[0] = value; |
||
264 | } |
||
265 | } |
||
266 | |||
267 | public void incImgs() |
||
268 | { |
||
269 | baseTime++; |
||
270 | turretTime++; |
||
271 | } |
||
272 | |||
273 | public tower(int typeN, Point locN, string soundLoc) |
||
274 | { |
||
275 | targets = new List<int>(); |
||
276 | type = typeN; |
||
277 | target = -1; |
||
278 | energy = 0; |
||
279 | glow = 0; |
||
280 | fireing = false; |
||
281 | loc = locN; |
||
282 | angle = 180.0f; |
||
283 | baseTime = 0; |
||
284 | turretTime = 0; |
||
285 | delayTime = 0; |
||
286 | // s = new WMPLib.WindowsMediaPlayer(); |
||
287 | // s.settings.autoStart = false; |
||
288 | // s.settings.volume = 50; |
||
289 | // s.URL = soundLoc; |
||
290 | } |
||
291 | |||
292 | } |
||
293 | |||
294 | /// <summary> |
||
295 | /// Animated Img for Blockade |
||
296 | /// </summary> |
||
297 | public class animg |
||
298 | { |
||
299 | |||
300 | public Image[] imgs; |
||
301 | public int[] delays; |
||
302 | public int runTime, maxRunTime; |
||
303 | public string stringEq; |
||
304 | |||
305 | public void inc() |
||
306 | { |
||
307 | runTime++; |
||
308 | if (runTime > maxRunTime) |
||
309 | runTime = 0; |
||
310 | } |
||
311 | |||
312 | public Image curImg() |
||
313 | { |
||
314 | int cDelay = 0; |
||
315 | for (int i = 0; i < delays.Length; i++) |
||
316 | { |
||
317 | cDelay += delays[i]; |
||
318 | if (cDelay > runTime) |
||
319 | return imgs[i]; |
||
320 | } |
||
321 | |||
322 | return imgs[0]; |
||
323 | } |
||
324 | |||
325 | public animg clone() |
||
326 | { |
||
327 | return new animg(stringEq); |
||
328 | } |
||
329 | |||
330 | public animg(string s) |
||
331 | { |
||
332 | stringEq = s; |
||
333 | string[] data = s.Split(':'); |
||
334 | |||
335 | imgs = new Image[(int)(data.Length / 2)]; |
||
336 | delays = new int[(int)(data.Length / 2)]; |
||
337 | |||
338 | int cDelay = 0; |
||
339 | for (int i = 0; i < data.Length; i += 2) |
||
340 | { |
||
341 | imgs[(int)(i / 2)] = Image.FromFile(@"data/" + data[i]); |
||
342 | delays[(int)(i / 2)] = int.Parse(data[i + 1]); |
||
343 | cDelay += delays[(int)(i / 2)]; |
||
344 | } |
||
345 | |||
346 | maxRunTime = cDelay; |
||
347 | |||
348 | } |
||
349 | |||
350 | } |
||
351 | |||
352 | public List<smoke> smokes = new List<smoke>(); |
||
353 | |||
354 | public List<enemyType> enemyTypes = new List<enemyType>(); |
||
355 | public List<missileType> missileTypes = new List<missileType>(); |
||
356 | public List<towerType> towerTypes = new List<towerType>(); |
||
357 | |||
358 | public List<enemy> enemies = new List<enemy>(); |
||
359 | public List<tower> towers = new List<tower>(); |
||
360 | |||
361 | public List<PictureBox> icons = new List<PictureBox>(); |
||
362 | |||
363 | string[] laserType0, laserType1, laserType2, cashA, livesA, levelA; |
||
364 | string[] laserTypeLookup; |
||
365 | |||
366 | string[] levels; |
||
367 | |||
368 | public int selTowerType = 0; |
||
369 | public int cash; |
||
370 | public int lives; |
||
371 | public int level = 0; |
||
372 | public int fCount; |
||
373 | public bool energyBars, autoRun, rangeRings, sound; |
||
374 | public Image yesImg, noImg, selImg, bgImg; |
||
375 | public float smokeMul; |
||
376 | public Color controlBGColour, controlFGColour; |
||
377 | public string detailText = ""; |
||
378 | public int lang; |
||
379 | |||
380 | Random rnd = new Random(); |
||
381 | |||
382 | public Form1(int language) |
||
383 | { |
||
384 | InitializeComponent(); |
||
385 | lang = language; |
||
386 | } |
||
387 | |||
388 | void mainLoop() |
||
389 | { |
||
390 | System.Threading.Thread.Sleep(1); |
||
391 | while (enemies.Count > 0) |
||
392 | { |
||
393 | fCount++; |
||
394 | Application.DoEvents(); |
||
395 | enemyLoop(); |
||
396 | towerLoop(); |
||
397 | missileLoop(); |
||
398 | smokeLoop(); |
||
399 | Application.DoEvents(); |
||
400 | draw(); |
||
401 | } |
||
402 | cash += (int)(lives / 2); |
||
403 | level++; |
||
404 | if (autoRun) |
||
405 | newRun(); |
||
406 | else |
||
407 | { |
||
408 | smokes.Clear(); |
||
409 | draw(); |
||
410 | } |
||
411 | } |
||
412 | |||
413 | void enemyLoop() |
||
414 | { |
||
415 | for (int i = enemies.Count - 1; i >= 0; i--) |
||
416 | { |
||
417 | enemies[i].incImg(); |
||
418 | if (enemies[i].health <= 0) |
||
419 | { |
||
420 | cash += enemyTypes[enemies[i].type].value; |
||
421 | if (enemyTypes[enemies[i].type].child == -1) |
||
422 | { |
||
423 | enemies.RemoveAt(i); |
||
424 | for (int j = 0; j < towers.Count; j++) |
||
425 | { |
||
426 | // loop removed |
||
427 | if (towers[j].target > i) |
||
428 | towers[j].target--; |
||
429 | else if (towers[j].target == i) |
||
430 | towers[j].target = -1; |
||
431 | } |
||
432 | } |
||
433 | else |
||
434 | { |
||
435 | enemies[i].type = enemyTypes[enemies[i].type].child; |
||
436 | enemies[i].health = enemyTypes[enemies[i].type].health; |
||
437 | initMove(i); |
||
438 | } |
||
439 | } |
||
440 | else |
||
441 | { |
||
442 | move(i); |
||
443 | if (enemyTypes[enemies[i].type].spawn != -1) |
||
444 | { |
||
445 | if (rnd.NextDouble() < enemyTypes[enemies[i].type].spawnChance) |
||
446 | { |
||
447 | enemies.Add(new enemy(enemyTypes[enemies[i].type].spawn, enemyTypes[enemyTypes[enemies[i].type].spawn].health, (float)getAngle(FtoP(enemies[i].loc), new Point(500, rnd.Next(40,360))), enemies[i].loc)); |
||
448 | initMove(enemies.Count - 1); |
||
449 | } |
||
450 | } |
||
451 | if (enemies[i].loc.X > 500) |
||
452 | { |
||
453 | lives--; |
||
454 | enemies.RemoveAt(i); |
||
455 | for (int j = 0; j < towers.Count; j++) |
||
456 | { |
||
457 | // loop removed |
||
458 | if (towers[j].target > i) |
||
459 | towers[j].target--; |
||
460 | else if (towers[j].target == i) |
||
461 | towers[j].target = -1; |
||
462 | } |
||
463 | } |
||
464 | } |
||
465 | } |
||
466 | } |
||
467 | |||
468 | void towerLoop() |
||
469 | { |
||
470 | for (int i = 0; i < towers.Count; i++) |
||
471 | { |
||
472 | towers[i].incImgs(); |
||
473 | if (towers[i].glow > 0) |
||
474 | towers[i].glow--; |
||
475 | if (towers[i].delayTime != 0) |
||
476 | towers[i].delayTime--; |
||
477 | |||
478 | if (towers[i].target == -1 || getDist(towers[i].loc, FtoP(enemies[towers[i].target].loc)) > towerTypes[towers[i].type].range) |
||
479 | { |
||
480 | towers[i].target = -1; |
||
481 | reTarget(i); |
||
482 | } |
||
483 | else if (towerTypes[towers[i].type].req != 0 && towers[i].energy >= towerTypes[towers[i].type].req) |
||
484 | { |
||
485 | if (towerTypes[towers[i].type].laserType == 2) |
||
486 | reTarget(i); |
||
487 | fire(i, true); |
||
488 | } |
||
489 | reAngle(i); |
||
490 | if (towers[i].fireing && towers[i].target != -1 && towers[i].energy >= towerTypes[towers[i].type].useRate) |
||
491 | { |
||
492 | // towers[i].s.controls.play(); |
||
493 | if (towerTypes[towers[i].type].laserColour == null) |
||
494 | { |
||
495 | } |
||
496 | else if (towers[i].delayTime == 0) |
||
497 | { |
||
498 | towers[i].energy -= towerTypes[towers[i].type].useRate; |
||
499 | int smokeSpreadWidth = (int)(getEnemyImg(towers[i].target).Width / 3); |
||
500 | int smokeSpreadHeight = (int)(getEnemyImg(towers[i].target).Height / 3); |
||
501 | int num = rnd.Next(1, (int)(towerTypes[towers[i].type].useRate / 100 + 2)); |
||
502 | switch (towerTypes[towers[i].type].laserType) |
||
503 | { |
||
504 | case (0): |
||
505 | { |
||
506 | enemies[towers[i].target].health -= towerTypes[towers[i].type].damage; |
||
507 | for (int j = 0; j < (int)(num * smokeMul + rnd.NextDouble() * 1.5 + 0.5); j++) |
||
508 | smokes.Add(new smoke(towerTypes[towers[i].type].laserColour, new Point((int)enemies[towers[i].target].loc.X + rnd.Next(-smokeSpreadWidth, smokeSpreadWidth), (int)enemies[towers[i].target].loc.Y + rnd.Next(-smokeSpreadHeight, smokeSpreadHeight)), 20)); |
||
509 | break; |
||
510 | } |
||
511 | case (1): |
||
512 | { |
||
513 | enemies[towers[i].target].health -= towerTypes[towers[i].type].damage; |
||
514 | for (int j = 0; j < (int)(num * smokeMul + rnd.NextDouble() * 1.5 + 0.5); j++) |
||
515 | smokes.Add(new smoke(towerTypes[towers[i].type].laserColour, new Point((int)enemies[towers[i].target].loc.X + rnd.Next(-smokeSpreadWidth, smokeSpreadWidth), (int)enemies[towers[i].target].loc.Y + rnd.Next(-smokeSpreadHeight, smokeSpreadHeight)), 20)); |
||
516 | break; |
||
517 | } |
||
518 | case (2): |
||
519 | { |
||
520 | for (int r = 0; r < towers[i].targets.Count; r++) |
||
521 | { |
||
522 | enemies[towers[i].targets[r]].health -= towerTypes[towers[i].type].damage / (float)towers[i].targets.Count; |
||
523 | for (int j = 0; j < (int)(num * smokeMul + rnd.NextDouble() * 1.5 / (float)towers[i].targets.Count + 0.5); j++) |
||
524 | smokes.Add(new smoke(towerTypes[towers[i].type].laserColour, new Point((int)enemies[towers[i].targets[r]].loc.X + rnd.Next(-smokeSpreadWidth, smokeSpreadWidth), (int)enemies[towers[i].targets[r]].loc.Y + rnd.Next(-smokeSpreadHeight, smokeSpreadHeight)), 20)); |
||
525 | } |
||
526 | break; |
||
527 | } |
||
528 | } |
||
529 | towers[i].glow = towerTypes[towers[i].type].useRate; |
||
530 | towers[i].delayTime += towerTypes[towers[i].type].delay; |
||
531 | } |
||
532 | } |
||
533 | else |
||
534 | { |
||
535 | fire(i, false); |
||
536 | towers[i].energy += towerTypes[towers[i].type].gainRate - rnd.Next(0, (int)Math.Ceiling((towerTypes[towers[i].type].gainRate / 5))); |
||
537 | if (towers[i].energy >= towerTypes[towers[i].type].maxEnergy && towers[i].target != -1) |
||
538 | { |
||
539 | towers[i].energy = towerTypes[towers[i].type].maxEnergy; |
||
540 | } |
||
541 | } |
||
542 | if (towers[i].energy > towerTypes[towers[i].type].maxEnergy) |
||
543 | towers[i].energy = towerTypes[towers[i].type].maxEnergy; |
||
544 | } |
||
545 | } |
||
546 | |||
547 | void missileLoop() |
||
548 | { |
||
549 | |||
550 | } |
||
551 | |||
552 | void smokeLoop() |
||
553 | { |
||
554 | for (int i = smokes.Count - 1; i >= 0 ; i--) |
||
555 | { |
||
556 | smokes[i].time--; |
||
557 | if (smokes[i].time <= 0) |
||
558 | smokes.RemoveAt(i); |
||
559 | } |
||
560 | } |
||
561 | |||
562 | void newRun() |
||
563 | { |
||
564 | if (level >= levels.Length) |
||
565 | { |
||
566 | level = 0; |
||
567 | for (int i = 0; i < enemyTypes.Count; i++) |
||
568 | { |
||
569 | enemyTypes[i].health *= 1.2f; |
||
570 | } |
||
571 | } |
||
572 | string[] data = levels[level].Split(','); |
||
573 | PointF start; |
||
574 | Point end; |
||
575 | for (int i = 0; i < data.Length; i++) |
||
576 | { |
||
577 | start = new PointF(rnd.Next(-150, -55), rnd.Next(40, 360)); |
||
578 | end = new Point(500, rnd.Next(40, 360)); |
||
579 | enemies.Add(new enemy(int.Parse(data[i]), enemyTypes[int.Parse(data[i])].health, (float)getAngle(FtoP(start), end), start)); |
||
580 | initMove(enemies.Count - 1); |
||
581 | enemies[enemies.Count - 1].imgTime = rnd.Next(enemyTypes[enemies[enemies.Count - 1].type].img.maxRunTime); |
||
582 | } |
||
583 | mainLoop(); |
||
584 | } |
||
585 | |||
586 | private void Form1_Load(object sender, EventArgs e) |
||
587 | { |
||
588 | initAll(); |
||
589 | } |
||
590 | |||
591 | public void initAll() |
||
592 | { |
||
593 | |||
594 | // handels |
||
595 | |||
596 | System.IO.StreamReader reader; |
||
597 | string r; |
||
598 | string[] lines; |
||
599 | |||
600 | // textLookUps |
||
601 | |||
602 | reader = new System.IO.StreamReader(@"data/gameTexts.dat", Encoding.UTF8); |
||
603 | lines = reader.ReadToEnd().Split('\n'); |
||
604 | |||
605 | laserType0 = lines[0].Split(':'); |
||
606 | laserType1 = lines[1].Split(':'); |
||
607 | laserType2 = lines[2].Split(':'); |
||
608 | cashA = lines[3].Split(':'); |
||
609 | livesA = lines[4].Split(':'); |
||
610 | levelA = lines[5].Split(':'); |
||
611 | |||
612 | laserTypeLookup = new String[3]; |
||
613 | laserTypeLookup[0] = laserType0[lang]; |
||
614 | laserTypeLookup[1] = laserType1[lang]; |
||
615 | laserTypeLookup[2] = laserType2[lang]; |
||
616 | |||
617 | // init start vars |
||
618 | |||
619 | reader = new System.IO.StreamReader(@"data/start.dat", Encoding.UTF8); |
||
620 | r = reader.ReadToEnd(); |
||
621 | reader.Close(); |
||
622 | string[] data = r.Split(','); |
||
623 | cash = int.Parse(data[0]); |
||
624 | lives = int.Parse(data[1]); |
||
625 | bgImg = Image.FromFile(@"data/" + data[2]); |
||
626 | beamF.Image = Image.FromFile(@"data/" + data[3]); |
||
627 | smokeMul = float.Parse(data[4]); |
||
628 | controlBGColour = Color.FromName(data[5]); |
||
629 | controlFGColour = Color.FromName(data[6]); |
||
630 | |||
631 | // basic UI stuff |
||
632 | |||
633 | this.Text = "Blockade!"; |
||
634 | yesImg = Image.FromFile(@"data/yesImg.png"); |
||
635 | noImg = Image.FromFile(@"data/noImg.png"); |
||
636 | selImg = Image.FromFile(@"data/selImg.png"); |
||
637 | goF.BackColor = controlBGColour; |
||
638 | goF.BackgroundImage = yesImg; |
||
639 | goF.Image = Image.FromFile(@"data/go.png"); |
||
640 | cashF.BackColor = controlBGColour; |
||
641 | livesF.BackColor = controlBGColour; |
||
642 | levelF.BackColor = controlBGColour; |
||
643 | cashF.ForeColor = controlFGColour; |
||
644 | livesF.ForeColor = controlFGColour; |
||
645 | levelF.ForeColor = controlFGColour; |
||
646 | |||
647 | |||
648 | // load ingame object types |
||
649 | |||
650 | reader = new System.IO.StreamReader(@"data/enemies.dat", Encoding.UTF8); |
||
651 | r = reader.ReadToEnd(); |
||
652 | reader.Close(); |
||
653 | lines = r.Split('\n'); |
||
654 | for (int i = 0; i < lines.Length; i++) |
||
655 | { |
||
656 | if (lines[i].Length != 0 && lines[i].Substring(0,1) != "#") |
||
657 | enemyTypes.Add(new enemyType(lines[i].Split(','))); |
||
658 | } |
||
659 | |||
660 | reader = new System.IO.StreamReader(@"data/missiles.dat", Encoding.UTF8); |
||
661 | r = reader.ReadToEnd(); |
||
662 | reader.Close(); |
||
663 | lines = r.Split('\n'); |
||
664 | for (int i = 0; i < lines.Length; i++) |
||
665 | { |
||
666 | if (lines[i].Length != 0 && lines[i].Substring(0,1) != "#") |
||
667 | missileTypes.Add(new missileType(lines[i].Split(','))); |
||
668 | } |
||
669 | |||
670 | reader = new System.IO.StreamReader(@"data/towers.dat", Encoding.UTF8); |
||
671 | r = reader.ReadToEnd(); |
||
672 | reader.Close(); |
||
673 | lines = r.Split('\n'); |
||
674 | for (int i = 0; i < lines.Length; i++) |
||
675 | { |
||
676 | if (lines[i].Length != 0 && lines[i].Substring(0, 1) != "#") |
||
677 | towerTypes.Add(new towerType(lines[i].Split(','))); |
||
678 | } |
||
679 | |||
680 | // load levels |
||
681 | |||
682 | reader = new System.IO.StreamReader(@"data/levels.dat"); |
||
683 | r = reader.ReadToEnd(); |
||
684 | reader.Close(); |
||
685 | levels = r.Split('\n'); |
||
686 | |||
687 | // set up Icons |
||
688 | |||
689 | Point iconLoc = new Point(); |
||
690 | |||
691 | for (int i = 0; i < towerTypes.Count; i++) |
||
692 | { |
||
693 | icons.Add(new PictureBox()); |
||
694 | icons[i].BackColor = controlBGColour; |
||
695 | icons[i].SizeMode = PictureBoxSizeMode.Zoom; |
||
696 | icons[i].Image = towerTypes[i].turretImg.imgs[0]; |
||
697 | iconLoc.X = 150 + (int)Math.Floor(i / 2.0) * 48; |
||
698 | icons[i].Visible = true; |
||
699 | icons[i].Click += new EventHandler(IconPress); |
||
700 | if ((float)Math.Floor(i / 2.0) != (float)(i / 2.0)) |
||
701 | iconLoc.Y = 454; |
||
702 | else |
||
703 | iconLoc.Y = 408; |
||
704 | icons[i].Location = iconLoc; |
||
705 | icons[i].Tag = i; |
||
706 | icons[i].Size = new Size(40, 40); |
||
707 | icons[i].MouseHover += new EventHandler(IconEnter); |
||
708 | icons[i].MouseLeave += new EventHandler(IconLeave); |
||
709 | Controls.Add(icons[i]); |
||
710 | icons[i].BringToFront(); |
||
711 | icons[i].Refresh(); |
||
712 | } |
||
713 | |||
714 | // close reader |
||
715 | |||
716 | reader.Close(); |
||
717 | |||
718 | // Draw everything... |
||
719 | |||
720 | drawBG(); |
||
721 | draw(); |
||
722 | |||
723 | } |
||
724 | |||
725 | public float notZero(float value) |
||
726 | { |
||
727 | if (value == 0) |
||
728 | return 0.01f; |
||
729 | else |
||
730 | return value; |
||
731 | } |
||
732 | |||
733 | public void draw() |
||
734 | { |
||
735 | |||
736 | for (int i = 0; i < icons.Count; i++) |
||
737 | { |
||
738 | if (cash < towerTypes[i].cost) |
||
739 | icons[i].BackgroundImage = noImg; |
||
740 | else if (selTowerType == i) |
||
741 | icons[i].BackgroundImage = selImg; |
||
742 | else |
||
743 | icons[i].BackgroundImage = yesImg; |
||
744 | } |
||
745 | |||
746 | cashF.Text = cashA[lang] + ": " + cash.ToString(); |
||
747 | livesF.Text = lives.ToString() + " " + livesA[lang]; |
||
748 | levelF.Text = levelA[lang] + ": " + level.ToString(); |
||
749 | |||
750 | Bitmap img = new Bitmap(500, 400); |
||
751 | Graphics g = Graphics.FromImage(img); |
||
752 | PointF[] points; |
||
753 | |||
754 | // draw towers |
||
755 | Image baseImg, turretImg; |
||
756 | for (int i = 0; i < towers.Count; i++) |
||
757 | { |
||
758 | baseImg = getBaseImg(i); |
||
759 | turretImg = getTurretImg(i); |
||
760 | if (towers[i].fireing && towers[i].delayTime == towerTypes[towers[i].type].delay && towerTypes[towers[i].type].laserColour != null && towers[i].target != -1) |
||
761 | { |
||
762 | switch (towerTypes[towers[i].type].laserType) |
||
763 | { |
||
764 | case (0): |
||
765 | { |
||
766 | g.DrawLine(new Pen(towerTypes[towers[i].type].laserColour, 3), (PointF)towers[i].loc, enemies[towers[i].target].loc); |
||
767 | break; |
||
768 | } |
||
769 | case (1): |
||
770 | { |
||
771 | //laser |
||
772 | points = new PointF[getDist(towers[i].loc, FtoP(enemies[towers[i].target].loc)) / 50 + 3]; |
||
773 | points[0] = enemies[towers[i].target].loc; |
||
774 | points[points.Length - 1] = towers[i].loc; |
||
775 | for (int j = 1; j < points.Length - 1; j++) |
||
776 | points[j] = new PointF(enemies[towers[i].target].loc.X + notZero(towers[i].loc.X - (int)enemies[towers[i].target].loc.X) / points.Length * j + rnd.Next(-points.Length - 4, points.Length + 4), enemies[towers[i].target].loc.Y + notZero(towers[i].loc.Y - (int)enemies[towers[i].target].loc.Y) / points.Length * j + rnd.Next(-points.Length - 4, points.Length + 4)); |
||
777 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 3), points); |
||
778 | // //impactThing |
||
779 | // points = new PointF[getDist(towers[i].loc, FtoP(enemies[towers[i].target].loc)) / 50 + 3]; |
||
780 | // points[0] = enemies[towers[i].target].loc; |
||
781 | // points[points.Length - 1] = enemies[towers[i].target].loc; |
||
782 | // for (int j = 1; j < points.Length - 1; j++) |
||
783 | // points[j] = new PointF((int)enemies[towers[i].target].loc.X + rnd.Next(-(int)(enemyTypes[enemies[towers[i].target].type].img.imgs[0].Width * 0.8), (int)(enemyTypes[enemies[towers[i].target].type].img.imgs[0].Width * 0.8)), (int)enemies[towers[i].target].loc.Y + rnd.Next(-(int)(enemyTypes[enemies[towers[i].target].type].img.imgs[0].Height * 0.8), (int)(enemyTypes[enemies[towers[i].target].type].img.imgs[0].Height * 0.8))); |
||
784 | // g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 3), points); |
||
785 | break; |
||
786 | } |
||
787 | case (2): |
||
788 | { |
||
789 | //initialLaser |
||
790 | points = new PointF[getDist(towers[i].loc, FtoP(enemies[towers[i].target].loc)) / 50 + 3]; |
||
791 | points[0] = enemies[towers[i].target].loc; |
||
792 | points[points.Length - 1] = towers[i].loc; |
||
793 | for (int j = 1; j < points.Length - 1; j++) |
||
794 | points[j] = new PointF(enemies[towers[i].target].loc.X + notZero(towers[i].loc.X - (int)enemies[towers[i].target].loc.X) / points.Length * j + rnd.Next(-points.Length - 4, points.Length + 4), enemies[towers[i].target].loc.Y + notZero(towers[i].loc.Y - (int)enemies[towers[i].target].loc.Y) / points.Length * j + rnd.Next(-points.Length - 4, points.Length + 4)); |
||
795 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 3), points); |
||
796 | //furtherLasers |
||
797 | for (int r = 1; r < towers[i].targets.Count; r++) |
||
798 | { |
||
799 | points = new PointF[getDist(towers[i].loc, FtoP(enemies[towers[i].targets[r]].loc)) / 50 + 3]; |
||
800 | points[0] = enemies[towers[i].targets[r]].loc; |
||
801 | points[points.Length - 1] = enemies[towers[i].targets[r - 1]].loc; |
||
802 | for (int j = 1; j < points.Length - 1; j++) |
||
803 | points[j] = new PointF(enemies[towers[i].targets[r]].loc.X + notZero(enemies[towers[i].targets[r - 1]].loc.X - (int)enemies[towers[i].targets[r]].loc.X) / points.Length * j + rnd.Next(-points.Length - 4, points.Length + 4), enemies[towers[i].targets[r]].loc.Y + notZero(enemies[towers[i].targets[r - 1]].loc.Y - (int)enemies[towers[i].targets[r]].loc.Y) / points.Length * j + rnd.Next(-points.Length - 4, points.Length + 4)); |
||
804 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 3), points); |
||
805 | } |
||
806 | break; |
||
807 | } |
||
808 | } |
||
809 | } |
||
810 | |||
811 | g.TranslateTransform(towers[i].loc.X, towers[i].loc.Y); |
||
812 | if (energyBars) |
||
813 | { |
||
814 | if (towers[i].fireing) |
||
815 | g.FillRectangle(Brushes.Maroon, (int)(-turretImg.Width / 2), (int)(-turretImg.Height / 2) - 5, (int)(towers[i].energy / towerTypes[towers[i].type].maxEnergy * turretImg.Width), 3); |
||
816 | else if (towers[i].energy < towerTypes[towers[i].type].req) |
||
817 | g.FillRectangle(Brushes.Green, (int)(-turretImg.Width / 2), (int)(-turretImg.Height / 2) - 5, (int)(towers[i].energy / towerTypes[towers[i].type].maxEnergy * turretImg.Width), 3); |
||
818 | else |
||
819 | g.FillRectangle(Brushes.LawnGreen, (int)(-turretImg.Width / 2), (int)(-turretImg.Height / 2) - 5, (int)(towers[i].energy / towerTypes[towers[i].type].maxEnergy * turretImg.Width), 3); |
||
820 | } |
||
821 | g.RotateTransform(towers[i].angle); |
||
822 | g.DrawImage(turretImg, (int)(-turretImg.Width / 2), (int)(-turretImg.Height / 2)); |
||
823 | g.ResetTransform(); |
||
824 | } |
||
825 | |||
826 | // draw enemies |
||
827 | for (int i = 0; i < enemies.Count; i++) |
||
828 | { |
||
829 | g.TranslateTransform(enemies[i].loc.X, enemies[i].loc.Y); |
||
830 | g.RotateTransform(enemies[i].angle); |
||
831 | g.DrawImage(getEnemyImg(i), (int)(-getEnemyImg(i).Width / 2), (int)(-getEnemyImg(i).Height / 2)); |
||
832 | g.ResetTransform(); |
||
833 | } |
||
834 | |||
835 | //draw smoke |
||
836 | for (int i = 0; i < smokes.Count; i++) |
||
837 | { |
||
838 | g.FillEllipse(new SolidBrush(Color.FromArgb(100, smokes[i].colour.R, smokes[i].colour.B, smokes[i].colour.G)), smokes[i].loc.X - (int)(smokes[i].time / 5), smokes[i].loc.Y - (int)(smokes[i].time / 5), smokes[i].time, smokes[i].time); |
||
839 | } |
||
840 | |||
841 | //draw energy flux!! |
||
842 | for (int i = 0; i < towers.Count; i++) |
||
843 | { |
||
844 | if (towers[i].fireing && towers[i].delayTime == towerTypes[towers[i].type].delay && towerTypes[towers[i].type].laserColour != null && towers[i].target != -1) |
||
845 | { |
||
846 | g.FillEllipse(new SolidBrush(Color.FromArgb((int)(towers[i].glow / towerTypes[towers[i].type].maxEnergy * 100), towerTypes[towers[i].type].laserColour.R, towerTypes[towers[i].type].laserColour.B, towerTypes[towers[i].type].laserColour.G)), (int)(towers[i].loc.X - towers[i].glow / 2), (int)(towers[i].loc.Y - towers[i].glow / 2), towers[i].glow, towers[i].glow); |
||
847 | } |
||
848 | } |
||
849 | |||
850 | Font font1 = new Font(FontFamily.GenericMonospace, 10, FontStyle.Regular, GraphicsUnit.Pixel); |
||
851 | |||
852 | StringFormat sf = new StringFormat(); |
||
853 | sf.Alignment = StringAlignment.Center; |
||
854 | |||
855 | //LOOSE TEXT |
||
856 | if (lives <= 0) |
||
857 | g.DrawString("You Loose!\nHAHAHA!", new Font(FontFamily.GenericMonospace, 40, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(controlFGColour), 250, 200, sf); |
||
858 | |||
859 | if (detailText != "" && enemies.Count == 0) |
||
860 | g.DrawString(textWrap(font1, detailText, 450), font1, new SolidBrush(controlFGColour), 250, 400 - TextRenderer.MeasureText(textWrap(font1, detailText, 450), font1).Height, sf); |
||
861 | |||
862 | view.Image = (Image)img.Clone(); |
||
863 | g.Dispose(); |
||
864 | img.Dispose(); |
||
865 | |||
866 | cashF.Refresh(); |
||
867 | livesF.Refresh(); |
||
868 | levelF.Refresh(); |
||
869 | view.Refresh(); |
||
870 | |||
871 | } |
||
872 | |||
873 | public string textWrap(Font font, string textN, int width) |
||
874 | { |
||
875 | string text = textN; |
||
876 | int lastSpace = 1; |
||
877 | for (int i = 1; i < text.Length; i++) |
||
878 | { |
||
879 | if (text.Substring(i, 1) == " ") |
||
880 | lastSpace = i; |
||
881 | if (TextRenderer.MeasureText(text.Substring(0, i), font).Width > width) |
||
882 | text = text.Substring(0, lastSpace) + "\n" + text.Substring(lastSpace + 1); |
||
883 | } |
||
884 | return text; |
||
885 | } |
||
886 | |||
887 | public void drawBG() |
||
888 | { |
||
889 | |||
890 | Bitmap img = new Bitmap(500, 400); |
||
891 | Graphics g = Graphics.FromImage(img); |
||
892 | |||
893 | g.DrawImage(bgImg, 0, 0); |
||
894 | |||
895 | Image baseImg; |
||
896 | for (int i = 0; i < towers.Count; i++) |
||
897 | { |
||
898 | baseImg = getBaseImg(i); |
||
899 | g.TranslateTransform(towers[i].loc.X, towers[i].loc.Y); |
||
900 | g.DrawImage(baseImg, (int)(-baseImg.Width / 2), (int)(-baseImg.Height / 2)); |
||
901 | if (rangeRings) |
||
902 | g.DrawEllipse(new Pen(towerTypes[towers[i].type].laserColour, 3), -towerTypes[towers[i].type].range, -towerTypes[towers[i].type].range, towerTypes[towers[i].type].range * 2, towerTypes[towers[i].type].range * 2); |
||
903 | g.ResetTransform(); |
||
904 | } |
||
905 | |||
906 | view.BackgroundImage = (Image)img.Clone(); |
||
907 | g.Dispose(); |
||
908 | img.Dispose(); |
||
909 | |||
910 | } |
||
911 | |||
912 | private void view_MouseClick(object sender, MouseEventArgs e) |
||
913 | { |
||
914 | if (e.Button == MouseButtons.Left) |
||
915 | { |
||
916 | if (cash >= towerTypes[selTowerType].cost) |
||
917 | { |
||
918 | for (int i = 0; i < towers.Count; i++) |
||
919 | { |
||
920 | if (getDist(towers[i].loc, e.Location) < Math.Max(towerTypes[towers[i].type].baseImg.imgs[0].Width, towerTypes[towers[i].type].baseImg.imgs[0].Width) / 2 + Math.Max(towerTypes[selTowerType].baseImg.imgs[0].Width, towerTypes[selTowerType].baseImg.imgs[0].Width) / 2) |
||
921 | { |
||
922 | return; |
||
923 | } |
||
924 | } |
||
925 | cash -= towerTypes[selTowerType].cost; |
||
926 | towers.Add(new tower(selTowerType, e.Location, towerTypes[selTowerType].sound)); |
||
927 | drawBG(); |
||
928 | draw(); |
||
929 | } |
||
930 | } |
||
931 | else |
||
932 | { |
||
933 | for (int i = 0; i < towers.Count; i++) |
||
934 | { |
||
935 | if (getDist(towers[i].loc, e.Location) < Math.Min(towerTypes[towers[i].type].baseImg.imgs[0].Width, towerTypes[towers[i].type].baseImg.imgs[0].Width) / 2) |
||
936 | { |
||
937 | cash += (int)(towerTypes[towers[i].type].cost / 2); |
||
938 | towers.RemoveAt(i); |
||
939 | drawBG(); |
||
940 | draw(); |
||
941 | return; |
||
942 | } |
||
943 | } |
||
944 | } |
||
945 | } |
||
946 | |||
947 | float getAngle(Point a, Point b) |
||
948 | { |
||
949 | if (a.X == b.X) |
||
950 | { |
||
951 | if (a.Y < b.Y) |
||
952 | return 90; |
||
953 | else |
||
954 | return 270; |
||
955 | } |
||
956 | else if (a.Y == b.Y) |
||
957 | { |
||
958 | if (a.X < b.X) |
||
959 | return 0; |
||
960 | else |
||
961 | return 180; |
||
962 | } |
||
963 | float output; |
||
964 | output = (float)(Math.Atan((b.Y - a.Y) / (float)(b.X - a.X)) / Math.PI * 180.0f); |
||
965 | if (a.X >= b.X) |
||
966 | output += 180; |
||
967 | if (output > 360) |
||
968 | output -= 360; |
||
969 | return output; |
||
970 | } |
||
971 | |||
972 | private void pictureBox1_Click(object sender, EventArgs e) |
||
973 | { |
||
974 | if (enemies.Count == 0) |
||
975 | newRun(); |
||
976 | } |
||
977 | |||
978 | public void initMove(int num) |
||
979 | { |
||
980 | enemies[num].dX = (float)Math.Cos(enemies[num].angle / 180 * Math.PI) * enemyTypes[enemies[num].type].speed; |
||
981 | enemies[num].dY = (float)Math.Sin(enemies[num].angle / 180 * Math.PI) * enemyTypes[enemies[num].type].speed; |
||
982 | } |
||
983 | |||
984 | public void move(int num) |
||
985 | { |
||
986 | enemies[num].loc.X += enemies[num].dX; |
||
987 | enemies[num].loc.Y += enemies[num].dY; |
||
988 | } |
||
989 | |||
990 | public void reTarget(int num) |
||
991 | { |
||
992 | bool res; |
||
993 | int tempEn; |
||
994 | if (towers[num].target != -1) |
||
995 | { |
||
996 | tempEn = towers[num].target; |
||
997 | towers[num].targets.Clear(); |
||
998 | towers[num].target = tempEn; |
||
999 | } |
||
1000 | else |
||
1001 | towers[num].targets.Clear(); |
||
1002 | for (int i = 0; i < enemies.Count; i++) |
||
1003 | { |
||
1004 | if (towerTypes[towers[num].type].laserType == 2 && towers[num].target != -1) |
||
1005 | res = enemies[i].loc.X >= 0 && getDist(FtoP(enemies[towers[num].targets[towers[num].targets.Count - 1]].loc), FtoP(enemies[i].loc)) <= towerTypes[towers[num].type].range && enemies[i].health > 0; |
||
1006 | else |
||
1007 | res = enemies[i].loc.X >= 0 && getDist(towers[num].loc, FtoP(enemies[i].loc)) <= towerTypes[towers[num].type].range && enemies[i].health > 0; |
||
1008 | if (res) |
||
1009 | { |
||
1010 | if (towerTypes[towers[num].type].laserType == 2) |
||
1011 | { |
||
1012 | if (!towers[num].targets.Contains(i) || rnd.Next(0,2) == 0) |
||
1013 | towers[num].targets.Add(i); |
||
1014 | if (rnd.Next(0, towerTypes[towers[num].type].killNum) == 0) |
||
1015 | return; |
||
1016 | } |
||
1017 | else |
||
1018 | { |
||
1019 | towers[num].target = i; |
||
1020 | return; |
||
1021 | } |
||
1022 | } |
||
1023 | } |
||
1024 | if (towerTypes[towers[num].type].laserType != 2) |
||
1025 | towers[num].target = -1; |
||
1026 | } |
||
1027 | |||
1028 | public void reAngle(int num) |
||
1029 | { |
||
1030 | if (towers[num].target != -1) |
||
1031 | towers[num].angle = (float)getAngle(towers[num].loc, new Point((int)enemies[towers[num].target].loc.X, (int)enemies[towers[num].target].loc.Y)); |
||
1032 | } |
||
1033 | |||
1034 | public void fire(int num, bool fireing) |
||
1035 | { |
||
1036 | towers[num].fireing = fireing; |
||
1037 | // towers[num].s.controls.stop(); |
||
1038 | // if (sound && fireing) |
||
1039 | // { |
||
1040 | // if (towers[num].s.playState != WMPLib.WMPPlayState.wmppsPlaying) |
||
1041 | // towers[num].s.controls.play(); |
||
1042 | // } |
||
1043 | } |
||
1044 | |||
1045 | public Point FtoP(PointF point) |
||
1046 | { |
||
1047 | return new Point((int)point.X, (int)point.Y); |
||
1048 | } |
||
1049 | |||
1050 | public int getDist(Point a, Point b) |
||
1051 | { |
||
1052 | return (int)Math.Sqrt(Math.Abs((a.X - b.X) * (a.X - b.X)) + Math.Abs((a.Y - b.Y) * (a.Y - b.Y))); |
||
1053 | } |
||
1054 | |||
1055 | void IconPress(object sender, EventArgs e) |
||
1056 | { |
||
1057 | PictureBox icon = (PictureBox)sender; |
||
1058 | if (towerTypes[(int)icon.Tag].cost <= cash) |
||
1059 | { |
||
1060 | selTowerType = (int)icon.Tag; |
||
1061 | draw(); |
||
1062 | } |
||
1063 | } |
||
1064 | |||
1065 | void IconEnter(object sender, EventArgs e) |
||
1066 | { |
||
1067 | PictureBox icon = (PictureBox)sender; |
||
1068 | if (towerTypes[(int)icon.Tag].laserType != -1) |
||
1069 | detailText = towerTypes[(int)icon.Tag].name + " - €" + towerTypes[(int)icon.Tag].cost + " - " + laserTypeLookup[towerTypes[(int)icon.Tag].laserType] + "\n" + towerTypes[(int)icon.Tag].details[lang]; |
||
1070 | // else |
||
1071 | // detailText = towerTypes[(int)icon.Tag].name + " - €" + towerTypes[(int)icon.Tag].cost + " - MType\n" + towerTypes[(int)icon.Tag].details; |
||
1072 | draw(); |
||
1073 | } |
||
1074 | |||
1075 | void IconLeave(object sender, EventArgs e) |
||
1076 | { |
||
1077 | detailText = ""; |
||
1078 | draw(); |
||
1079 | } |
||
1080 | |||
1081 | void Form1KeyDown(object sender, KeyEventArgs e) |
||
1082 | { |
||
1083 | switch (e.KeyCode) |
||
1084 | { |
||
1085 | case Keys.Back: |
||
1086 | cash += 1000; |
||
1087 | break; |
||
1088 | case Keys.Space: |
||
1089 | energyBars = !energyBars; |
||
1090 | break; |
||
1091 | case Keys.Enter: |
||
1092 | if (enemies.Count == 0) |
||
1093 | newRun(); |
||
1094 | break; |
||
1095 | case Keys.Tab: |
||
1096 | autoRun = !autoRun; |
||
1097 | if (autoRun) |
||
1098 | goF.BackgroundImage = noImg; |
||
1099 | else |
||
1100 | goF.BackgroundImage = yesImg; |
||
1101 | break; |
||
1102 | case Keys.F8: |
||
1103 | level++; |
||
1104 | if (level >= levels.Length) |
||
1105 | level = 0; |
||
1106 | break; |
||
1107 | case Keys.R: |
||
1108 | rangeRings = !rangeRings; |
||
1109 | drawBG(); |
||
1110 | break; |
||
1111 | case Keys.F4: |
||
1112 | timer1.Enabled = !timer1.Enabled; |
||
1113 | break; |
||
1114 | // case Keys.S: |
||
1115 | // sound = !sound; |
||
1116 | // break; |
||
1117 | default: |
||
1118 | if (e.KeyCode.ToString().Length > 1) |
||
1119 | { |
||
1120 | int res; |
||
1121 | if (int.TryParse(e.KeyCode.ToString().Substring(1, 1), out res)) |
||
1122 | { |
||
1123 | if (res < towerTypes.Count) |
||
1124 | { |
||
1125 | if (cash >= towerTypes[res].cost) |
||
1126 | selTowerType = res; |
||
1127 | } |
||
1128 | } |
||
1129 | } |
||
1130 | break; |
||
1131 | } |
||
1132 | draw(); |
||
1133 | |||
1134 | } |
||
1135 | |||
1136 | void Form1FormClosing(object sender, FormClosingEventArgs e) |
||
1137 | { |
||
1138 | autoRun = false; |
||
1139 | Form2 menu = new Form2(); |
||
1140 | menu.Show(); |
||
1141 | } |
||
1142 | |||
1143 | void Timer1Tick(object sender, EventArgs e) |
||
1144 | { |
||
1145 | this.Text = "Blockade! [" + (fCount * 2) + "FPS]"; |
||
1146 | fCount = 0; |
||
1147 | } |
||
1148 | |||
1149 | Image getBaseImg(int num) |
||
1150 | { |
||
1151 | if (towerTypes[towers[num].type].baseImg.maxRunTime < towers[num].baseTime) |
||
1152 | towers[num].baseTime = 0; |
||
1153 | return towerTypes[towers[num].type].getBaseImg(towers[num].baseTime); |
||
1154 | } |
||
1155 | |||
1156 | Image getTurretImg(int num) |
||
1157 | { |
||
1158 | if (towerTypes[towers[num].type].turretImg.maxRunTime < towers[num].turretTime) |
||
1159 | towers[num].turretTime = 0; |
||
1160 | return towerTypes[towers[num].type].getTurretImg(towers[num].turretTime); |
||
1161 | } |
||
1162 | |||
1163 | Image getEnemyImg(int num) |
||
1164 | { |
||
1165 | if (enemyTypes[enemies[num].type].img.maxRunTime < enemies[num].imgTime) |
||
1166 | enemies[num].imgTime = 0; |
||
1167 | return enemyTypes[enemies[num].type].getImg(enemies[num].imgTime); |
||
1168 | } |
||
1169 | } |
||
1170 | } |