Rev 7 | Details | Compare with Previous | 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 | |||
| 7 | freddie | 380 | public bool extraPretty = false;  | 
        
| 10 | freddie | 381 | public bool showTotalOfEngery = false;  | 
        
| 1 | freddie | 382 | Random rnd = new Random();  | 
        
| 383 | |||
| 384 | public Form1(int language)  | 
        ||
| 385 |         { | 
        ||
| 386 | InitializeComponent();  | 
        ||
| 387 | lang = language;  | 
        ||
| 388 |         } | 
        ||
| 389 | |||
| 390 | void mainLoop()  | 
        ||
| 391 |         { | 
        ||
| 392 | System.Threading.Thread.Sleep(1);  | 
        ||
| 393 | while (enemies.Count > 0)  | 
        ||
| 394 |             { | 
        ||
| 395 |                 fCount++; | 
        ||
| 396 | Application.DoEvents();  | 
        ||
| 397 | enemyLoop();  | 
        ||
| 398 | towerLoop();  | 
        ||
| 399 | missileLoop();  | 
        ||
| 400 | smokeLoop();  | 
        ||
| 401 | Application.DoEvents();  | 
        ||
| 402 | draw();  | 
        ||
| 403 |             } | 
        ||
| 404 | cash += (int)(lives / 2);  | 
        ||
| 405 |             level++; | 
        ||
| 406 | if (autoRun)  | 
        ||
| 407 | newRun();  | 
        ||
| 408 |             else | 
        ||
| 409 |             { | 
        ||
| 410 | smokes.Clear();  | 
        ||
| 411 | draw();  | 
        ||
| 412 |             } | 
        ||
| 413 |         } | 
        ||
| 414 | |||
| 415 | void enemyLoop()  | 
        ||
| 416 |         { | 
        ||
| 417 | for (int i = enemies.Count - 1; i >= 0; i--)  | 
        ||
| 418 |             { | 
        ||
| 419 | enemies[i].incImg();  | 
        ||
| 420 | if (enemies[i].health <= 0)  | 
        ||
| 421 |                 { | 
        ||
| 422 | cash += enemyTypes[enemies[i].type].value;  | 
        ||
| 423 | if (enemyTypes[enemies[i].type].child == -1)  | 
        ||
| 424 |                     { | 
        ||
| 425 | enemies.RemoveAt(i);  | 
        ||
| 426 | for (int j = 0; j < towers.Count; j++)  | 
        ||
| 427 |                         { | 
        ||
| 428 |                                 // loop removed | 
        ||
| 429 | if (towers[j].target > i)  | 
        ||
| 430 | towers[j].target--;  | 
        ||
| 431 | else if (towers[j].target == i)  | 
        ||
| 432 | towers[j].target = -1;  | 
        ||
| 433 |                         } | 
        ||
| 434 |                     } | 
        ||
| 435 |                     else | 
        ||
| 436 |                     { | 
        ||
| 437 | enemies[i].type = enemyTypes[enemies[i].type].child;  | 
        ||
| 438 | enemies[i].health = enemyTypes[enemies[i].type].health;  | 
        ||
| 439 | initMove(i);  | 
        ||
| 440 |                     } | 
        ||
| 441 |                 } | 
        ||
| 442 |                 else | 
        ||
| 443 |                 { | 
        ||
| 444 | move(i);  | 
        ||
| 445 | if (enemyTypes[enemies[i].type].spawn != -1)  | 
        ||
| 446 |                         { | 
        ||
| 447 | if (rnd.NextDouble() < enemyTypes[enemies[i].type].spawnChance)  | 
        ||
| 448 |                                 { | 
        ||
| 449 | 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));  | 
        ||
| 450 | initMove(enemies.Count - 1);  | 
        ||
| 451 |                                 } | 
        ||
| 452 |                         } | 
        ||
| 453 | if (enemies[i].loc.X > 500)  | 
        ||
| 454 |                     { | 
        ||
| 455 |                         lives--; | 
        ||
| 456 | enemies.RemoveAt(i);  | 
        ||
| 457 | for (int j = 0; j < towers.Count; j++)  | 
        ||
| 458 |                         { | 
        ||
| 459 |                                 // loop removed | 
        ||
| 460 | if (towers[j].target > i)  | 
        ||
| 461 | towers[j].target--;  | 
        ||
| 462 | else if (towers[j].target == i)  | 
        ||
| 463 | towers[j].target = -1;  | 
        ||
| 464 |                         } | 
        ||
| 465 |                     } | 
        ||
| 466 |                 } | 
        ||
| 467 |             } | 
        ||
| 468 |         } | 
        ||
| 469 | |||
| 470 | void towerLoop()  | 
        ||
| 471 |         { | 
        ||
| 472 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 473 |             { | 
        ||
| 474 | towers[i].incImgs();  | 
        ||
| 475 | if (towers[i].glow > 0)  | 
        ||
| 476 | towers[i].glow--;  | 
        ||
| 477 | if (towers[i].delayTime != 0)  | 
        ||
| 478 | towers[i].delayTime--;  | 
        ||
| 479 | |||
| 480 | if (towers[i].target == -1 || getDist(towers[i].loc, FtoP(enemies[towers[i].target].loc)) > towerTypes[towers[i].type].range)  | 
        ||
| 481 |                 { | 
        ||
| 482 | towers[i].target = -1;  | 
        ||
| 483 | reTarget(i);  | 
        ||
| 484 |                 } | 
        ||
| 485 | else if (towerTypes[towers[i].type].req != 0 && towers[i].energy >= towerTypes[towers[i].type].req)  | 
        ||
| 486 |                 { | 
        ||
| 487 | if (towerTypes[towers[i].type].laserType == 2)  | 
        ||
| 488 | reTarget(i);  | 
        ||
| 489 | fire(i, true);  | 
        ||
| 490 |                 } | 
        ||
| 491 | reAngle(i);  | 
        ||
| 492 | if (towers[i].fireing && towers[i].target != -1 && towers[i].energy >= towerTypes[towers[i].type].useRate)  | 
        ||
| 493 |                 { | 
        ||
| 494 | //                              towers[i].s.controls.play(); | 
        ||
| 495 | if (towerTypes[towers[i].type].laserColour == null)  | 
        ||
| 496 |                     { | 
        ||
| 497 |                     } | 
        ||
| 498 | else if (towers[i].delayTime == 0)  | 
        ||
| 499 |                     { | 
        ||
| 500 | towers[i].energy -= towerTypes[towers[i].type].useRate;  | 
        ||
| 501 | int smokeSpreadWidth = (int)(getEnemyImg(towers[i].target).Width / 3);  | 
        ||
| 502 | int smokeSpreadHeight = (int)(getEnemyImg(towers[i].target).Height / 3);  | 
        ||
| 503 | int num = rnd.Next(1, (int)(towerTypes[towers[i].type].useRate / 100 + 2));  | 
        ||
| 504 | switch (towerTypes[towers[i].type].laserType)  | 
        ||
| 505 |                         { | 
        ||
| 506 | case (0):  | 
        ||
| 507 |                                 { | 
        ||
| 508 | enemies[towers[i].target].health -= towerTypes[towers[i].type].damage;  | 
        ||
| 509 | for (int j = 0; j < (int)(num * smokeMul + rnd.NextDouble() * 1.5 + 0.5); j++)  | 
        ||
| 510 | 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));  | 
        ||
| 511 | break;  | 
        ||
| 512 |                                 } | 
        ||
| 513 | case (1):  | 
        ||
| 514 |                                 { | 
        ||
| 515 | enemies[towers[i].target].health -= towerTypes[towers[i].type].damage;  | 
        ||
| 516 | for (int j = 0; j < (int)(num * smokeMul + rnd.NextDouble() * 1.5 + 0.5); j++)  | 
        ||
| 517 | 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));  | 
        ||
| 518 | break;  | 
        ||
| 519 |                                 } | 
        ||
| 520 | case (2):  | 
        ||
| 521 |                                 { | 
        ||
| 522 | for (int r = 0; r < towers[i].targets.Count; r++)  | 
        ||
| 523 |                                         { | 
        ||
| 524 | enemies[towers[i].targets[r]].health -= towerTypes[towers[i].type].damage / (float)towers[i].targets.Count;  | 
        ||
| 525 | for (int j = 0; j < (int)(num * smokeMul + rnd.NextDouble() * 1.5 / (float)towers[i].targets.Count + 0.5); j++)  | 
        ||
| 526 | 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));  | 
        ||
| 527 |                                         } | 
        ||
| 528 | break;  | 
        ||
| 529 |                                 } | 
        ||
| 530 |                         } | 
        ||
| 531 | towers[i].glow = towerTypes[towers[i].type].useRate;  | 
        ||
| 532 | towers[i].delayTime += towerTypes[towers[i].type].delay;  | 
        ||
| 533 |                     } | 
        ||
| 534 |                 } | 
        ||
| 535 |                 else | 
        ||
| 536 |                 { | 
        ||
| 537 | fire(i, false);  | 
        ||
| 538 | towers[i].energy += towerTypes[towers[i].type].gainRate - rnd.Next(0, (int)Math.Ceiling((towerTypes[towers[i].type].gainRate / 5)));  | 
        ||
| 539 | if (towers[i].energy >= towerTypes[towers[i].type].maxEnergy && towers[i].target != -1)  | 
        ||
| 540 |                         { | 
        ||
| 541 | towers[i].energy = towerTypes[towers[i].type].maxEnergy;  | 
        ||
| 542 |                     } | 
        ||
| 543 |                 } | 
        ||
| 544 | if (towers[i].energy > towerTypes[towers[i].type].maxEnergy)  | 
        ||
| 545 | towers[i].energy = towerTypes[towers[i].type].maxEnergy;  | 
        ||
| 546 |             } | 
        ||
| 547 |         } | 
        ||
| 548 | |||
| 549 | void missileLoop()  | 
        ||
| 550 |         { | 
        ||
| 551 | |||
| 552 |         } | 
        ||
| 553 | |||
| 554 | void smokeLoop()  | 
        ||
| 555 |         { | 
        ||
| 556 | for (int i = smokes.Count - 1; i >= 0 ; i--)  | 
        ||
| 557 |             { | 
        ||
| 558 | smokes[i].time--;  | 
        ||
| 559 | if (smokes[i].time <= 0)  | 
        ||
| 560 | smokes.RemoveAt(i);  | 
        ||
| 561 |             } | 
        ||
| 562 |         } | 
        ||
| 563 | |||
| 564 | void newRun()  | 
        ||
| 565 |         { | 
        ||
| 566 | if (level >= levels.Length)  | 
        ||
| 567 |             { | 
        ||
| 568 | level = 0;  | 
        ||
| 569 | for (int i = 0; i < enemyTypes.Count; i++)  | 
        ||
| 570 |                 { | 
        ||
| 571 | enemyTypes[i].health *= 1.2f;  | 
        ||
| 572 |                 } | 
        ||
| 573 |             } | 
        ||
| 574 | string[] data = levels[level].Split(',');  | 
        ||
| 575 |             PointF start; | 
        ||
| 576 |             Point end; | 
        ||
| 577 | for (int i = 0; i < data.Length; i++)  | 
        ||
| 578 |             { | 
        ||
| 579 | start = new PointF(rnd.Next(-150, -55), rnd.Next(40, 360));  | 
        ||
| 580 | end = new Point(500, rnd.Next(40, 360));  | 
        ||
| 581 | enemies.Add(new enemy(int.Parse(data[i]), enemyTypes[int.Parse(data[i])].health, (float)getAngle(FtoP(start), end), start));  | 
        ||
| 582 | initMove(enemies.Count - 1);  | 
        ||
| 583 | enemies[enemies.Count - 1].imgTime = rnd.Next(enemyTypes[enemies[enemies.Count - 1].type].img.maxRunTime);  | 
        ||
| 584 |             } | 
        ||
| 585 | mainLoop();  | 
        ||
| 586 |         } | 
        ||
| 587 | |||
| 588 | private void Form1_Load(object sender, EventArgs e)  | 
        ||
| 589 |         { | 
        ||
| 590 | initAll();  | 
        ||
| 591 |         } | 
        ||
| 592 | |||
| 593 | public void initAll()  | 
        ||
| 594 |         { | 
        ||
| 595 | |||
| 596 |                 // handels | 
        ||
| 597 | |||
| 598 | System.IO.StreamReader reader;  | 
        ||
| 599 | string r;  | 
        ||
| 600 | string[] lines;  | 
        ||
| 601 | |||
| 602 |                 // textLookUps | 
        ||
| 603 | |||
| 604 | reader = new System.IO.StreamReader(@"data/gameTexts.dat", Encoding.UTF8);  | 
        ||
| 605 | lines = reader.ReadToEnd().Split('\n');  | 
        ||
| 606 | |||
| 607 | laserType0 = lines[0].Split(':');  | 
        ||
| 608 | laserType1 = lines[1].Split(':');  | 
        ||
| 609 | laserType2 = lines[2].Split(':');  | 
        ||
| 610 | cashA = lines[3].Split(':');  | 
        ||
| 611 | livesA = lines[4].Split(':');  | 
        ||
| 612 | levelA = lines[5].Split(':');  | 
        ||
| 613 | |||
| 614 | laserTypeLookup = new String[3];  | 
        ||
| 615 | laserTypeLookup[0] = laserType0[lang];  | 
        ||
| 616 | laserTypeLookup[1] = laserType1[lang];  | 
        ||
| 617 | laserTypeLookup[2] = laserType2[lang];  | 
        ||
| 618 | |||
| 619 |             // init start vars | 
        ||
| 620 | |||
| 621 | reader = new System.IO.StreamReader(@"data/start.dat", Encoding.UTF8);  | 
        ||
| 622 | r = reader.ReadToEnd();  | 
        ||
| 623 | reader.Close();  | 
        ||
| 624 | string[] data = r.Split(',');  | 
        ||
| 625 | cash = int.Parse(data[0]);  | 
        ||
| 626 | lives = int.Parse(data[1]);  | 
        ||
| 627 | bgImg = Image.FromFile(@"data/" + data[2]);  | 
        ||
| 628 | beamF.Image = Image.FromFile(@"data/" + data[3]);  | 
        ||
| 629 | smokeMul = float.Parse(data[4]);  | 
        ||
| 630 | controlBGColour = Color.FromName(data[5]);  | 
        ||
| 631 | controlFGColour = Color.FromName(data[6]);  | 
        ||
| 632 | |||
| 633 |             // basic UI stuff | 
        ||
| 634 | |||
| 635 | this.Text = "Blockade!";  | 
        ||
| 636 | yesImg = Image.FromFile(@"data/yesImg.png");  | 
        ||
| 637 | noImg = Image.FromFile(@"data/noImg.png");  | 
        ||
| 638 | selImg = Image.FromFile(@"data/selImg.png");  | 
        ||
| 639 | goF.BackColor = controlBGColour;  | 
        ||
| 640 | goF.BackgroundImage = yesImg;  | 
        ||
| 641 | goF.Image = Image.FromFile(@"data/go.png");  | 
        ||
| 642 | cashF.BackColor = controlBGColour;  | 
        ||
| 643 | livesF.BackColor = controlBGColour;  | 
        ||
| 644 | levelF.BackColor = controlBGColour;  | 
        ||
| 645 | cashF.ForeColor = controlFGColour;  | 
        ||
| 646 | livesF.ForeColor = controlFGColour;  | 
        ||
| 647 | levelF.ForeColor = controlFGColour;  | 
        ||
| 648 | |||
| 649 | |||
| 650 |             // load ingame object types | 
        ||
| 651 | |||
| 652 | reader = new System.IO.StreamReader(@"data/enemies.dat", Encoding.UTF8);  | 
        ||
| 653 | r = reader.ReadToEnd();  | 
        ||
| 654 | reader.Close();  | 
        ||
| 655 | lines = r.Split('\n');  | 
        ||
| 656 | for (int i = 0; i < lines.Length; i++)  | 
        ||
| 657 |             { | 
        ||
| 658 | if (lines[i].Length != 0 && lines[i].Substring(0,1) != "#")  | 
        ||
| 659 | enemyTypes.Add(new enemyType(lines[i].Split(',')));  | 
        ||
| 660 |             } | 
        ||
| 661 | |||
| 662 | reader = new System.IO.StreamReader(@"data/missiles.dat", Encoding.UTF8);  | 
        ||
| 663 | r = reader.ReadToEnd();  | 
        ||
| 664 | reader.Close();  | 
        ||
| 665 | lines = r.Split('\n');  | 
        ||
| 666 | for (int i = 0; i < lines.Length; i++)  | 
        ||
| 667 |             { | 
        ||
| 668 | if (lines[i].Length != 0 && lines[i].Substring(0,1) != "#")  | 
        ||
| 669 | missileTypes.Add(new missileType(lines[i].Split(',')));  | 
        ||
| 670 |             } | 
        ||
| 671 | |||
| 672 | reader = new System.IO.StreamReader(@"data/towers.dat", Encoding.UTF8);  | 
        ||
| 673 | r = reader.ReadToEnd();  | 
        ||
| 674 | reader.Close();  | 
        ||
| 675 | lines = r.Split('\n');  | 
        ||
| 676 | for (int i = 0; i < lines.Length; i++)  | 
        ||
| 677 |             { | 
        ||
| 678 | if (lines[i].Length != 0 && lines[i].Substring(0, 1) != "#")  | 
        ||
| 679 | towerTypes.Add(new towerType(lines[i].Split(',')));  | 
        ||
| 680 |             } | 
        ||
| 681 | |||
| 682 |             // load levels | 
        ||
| 683 | |||
| 684 | reader = new System.IO.StreamReader(@"data/levels.dat");  | 
        ||
| 685 | r = reader.ReadToEnd();  | 
        ||
| 686 | reader.Close();  | 
        ||
| 687 | levels = r.Split('\n');  | 
        ||
| 688 | |||
| 689 |             // set up Icons | 
        ||
| 690 | |||
| 691 | Point iconLoc = new Point();  | 
        ||
| 692 | |||
| 693 | for (int i = 0; i < towerTypes.Count; i++)  | 
        ||
| 694 |             { | 
        ||
| 695 | icons.Add(new PictureBox());  | 
        ||
| 696 | icons[i].BackColor = controlBGColour;  | 
        ||
| 697 | icons[i].SizeMode = PictureBoxSizeMode.Zoom;  | 
        ||
| 698 | icons[i].Image = towerTypes[i].turretImg.imgs[0];  | 
        ||
| 699 | iconLoc.X = 150 + (int)Math.Floor(i / 2.0) * 48;  | 
        ||
| 700 | icons[i].Visible = true;  | 
        ||
| 701 | icons[i].Click += new EventHandler(IconPress);  | 
        ||
| 702 | if ((float)Math.Floor(i / 2.0) != (float)(i / 2.0))  | 
        ||
| 703 | iconLoc.Y = 454;  | 
        ||
| 704 |                 else | 
        ||
| 705 | iconLoc.Y = 408;  | 
        ||
| 706 | icons[i].Location = iconLoc;  | 
        ||
| 707 | icons[i].Tag = i;  | 
        ||
| 708 | icons[i].Size = new Size(40, 40);  | 
        ||
| 709 | icons[i].MouseHover += new EventHandler(IconEnter);  | 
        ||
| 710 | icons[i].MouseLeave += new EventHandler(IconLeave);  | 
        ||
| 711 | Controls.Add(icons[i]);  | 
        ||
| 712 | icons[i].BringToFront();  | 
        ||
| 713 | icons[i].Refresh();  | 
        ||
| 714 |             } | 
        ||
| 715 | |||
| 716 |             // close reader | 
        ||
| 717 | |||
| 718 | reader.Close();  | 
        ||
| 719 | |||
| 720 |             // Draw everything... | 
        ||
| 721 | |||
| 722 | drawBG();  | 
        ||
| 723 | draw();  | 
        ||
| 724 | |||
| 725 |         } | 
        ||
| 726 | |||
| 727 | public float notZero(float value)  | 
        ||
| 728 |         { | 
        ||
| 729 | if (value == 0)  | 
        ||
| 730 | return 0.01f;  | 
        ||
| 731 |                 else | 
        ||
| 732 | return value;  | 
        ||
| 733 |         } | 
        ||
| 734 | |||
| 735 | public void draw()  | 
        ||
| 736 |         { | 
        ||
| 737 | |||
| 738 | for (int i = 0; i < icons.Count; i++)  | 
        ||
| 739 |                 { | 
        ||
| 740 | if (cash < towerTypes[i].cost)  | 
        ||
| 741 | icons[i].BackgroundImage = noImg;  | 
        ||
| 742 | else if (selTowerType == i)  | 
        ||
| 743 | icons[i].BackgroundImage = selImg;  | 
        ||
| 744 |                         else | 
        ||
| 745 | icons[i].BackgroundImage = yesImg;  | 
        ||
| 746 |                 } | 
        ||
| 747 | |||
| 748 | cashF.Text = cashA[lang] + ": " + cash.ToString();  | 
        ||
| 749 | livesF.Text = lives.ToString() + " " + livesA[lang];  | 
        ||
| 750 | levelF.Text = levelA[lang] + ": " + level.ToString();  | 
        ||
| 751 | |||
| 752 | Bitmap img = new Bitmap(500, 400);  | 
        ||
| 753 | Graphics g = Graphics.FromImage(img);  | 
        ||
| 754 | PointF[] points;  | 
        ||
| 755 | |||
| 756 |             // draw towers | 
        ||
| 757 |             Image baseImg, turretImg; | 
        ||
| 758 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 759 |             { | 
        ||
| 760 | baseImg = getBaseImg(i);  | 
        ||
| 761 | turretImg = getTurretImg(i);  | 
        ||
| 762 | if (towers[i].fireing && towers[i].delayTime == towerTypes[towers[i].type].delay && towerTypes[towers[i].type].laserColour != null && towers[i].target != -1)  | 
        ||
| 763 |                 { | 
        ||
| 764 | switch (towerTypes[towers[i].type].laserType)  | 
        ||
| 765 |                         { | 
        ||
| 766 | case (0):  | 
        ||
| 767 |                                         { | 
        ||
| 768 | g.DrawLine(new Pen(towerTypes[towers[i].type].laserColour, 3), (PointF)towers[i].loc, enemies[towers[i].target].loc);  | 
        ||
| 769 | break;  | 
        ||
| 770 |                                         } | 
        ||
| 771 | case (1):  | 
        ||
| 772 |                         { | 
        ||
| 773 |                                         //laser | 
        ||
| 774 | points = new PointF[getDist(towers[i].loc, FtoP(enemies[towers[i].target].loc)) / 50 + 3];  | 
        ||
| 775 | points[0] = enemies[towers[i].target].loc;  | 
        ||
| 776 | points[points.Length - 1] = towers[i].loc;  | 
        ||
| 777 | for (int j = 1; j < points.Length - 1; j++)  | 
        ||
| 778 | 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));  | 
        ||
| 779 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 3), points);  | 
        ||
| 7 | freddie | 780 | if (extraPretty)  | 
        
| 781 |                                                 { | 
        ||
| 782 | for (int j = 0; j < 3; j++)  | 
        ||
| 783 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 1), rndmisePoints(points, true));  | 
        ||
| 784 |                                                 } | 
        ||
| 1 | freddie | 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);  | 
        ||
| 7 | freddie | 796 | if (extraPretty)  | 
        
| 797 |                                                 { | 
        ||
| 798 | for (int j = 0; j < 3; j++)  | 
        ||
| 799 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 1), rndmisePoints(points, true));  | 
        ||
| 800 |                                                 } | 
        ||
| 1 | freddie | 801 |                                         //furtherLasers | 
        
| 802 | for (int r = 1; r < towers[i].targets.Count; r++)  | 
        ||
| 803 |                                         { | 
        ||
| 804 | points = new PointF[getDist(towers[i].loc, FtoP(enemies[towers[i].targets[r]].loc)) / 50 + 3];  | 
        ||
| 805 | points[0] = enemies[towers[i].targets[r]].loc;  | 
        ||
| 806 | points[points.Length - 1] = enemies[towers[i].targets[r - 1]].loc;  | 
        ||
| 807 | for (int j = 1; j < points.Length - 1; j++)  | 
        ||
| 808 | 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));  | 
        ||
| 809 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 3), points);  | 
        ||
| 7 | freddie | 810 | if (extraPretty)  | 
        
| 811 |                                                         { | 
        ||
| 812 | for (int j = 0; j < 3; j++)  | 
        ||
| 813 | g.DrawLines(new Pen(towerTypes[towers[i].type].laserColour, 1), rndmisePoints(points, true));  | 
        ||
| 814 |                                                         } | 
        ||
| 1 | freddie | 815 |                                         } | 
        
| 816 | break;  | 
        ||
| 817 |                         } | 
        ||
| 818 |                         } | 
        ||
| 819 |                 } | 
        ||
| 820 | |||
| 821 | g.TranslateTransform(towers[i].loc.X, towers[i].loc.Y);  | 
        ||
| 822 | if (energyBars)  | 
        ||
| 823 |                 { | 
        ||
| 824 | if (towers[i].fireing)  | 
        ||
| 825 | 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);  | 
        ||
| 826 | else if (towers[i].energy < towerTypes[towers[i].type].req)  | 
        ||
| 827 | 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);  | 
        ||
| 828 |                         else | 
        ||
| 829 | 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);  | 
        ||
| 830 |                 } | 
        ||
| 831 | g.RotateTransform(towers[i].angle);  | 
        ||
| 832 | g.DrawImage(turretImg, (int)(-turretImg.Width / 2), (int)(-turretImg.Height / 2));  | 
        ||
| 833 | g.ResetTransform();  | 
        ||
| 834 |             } | 
        ||
| 835 | |||
| 836 |             // draw enemies | 
        ||
| 837 | for (int i = 0; i < enemies.Count; i++)  | 
        ||
| 838 |             { | 
        ||
| 839 | g.TranslateTransform(enemies[i].loc.X, enemies[i].loc.Y);  | 
        ||
| 840 | g.RotateTransform(enemies[i].angle);  | 
        ||
| 841 | g.DrawImage(getEnemyImg(i), (int)(-getEnemyImg(i).Width / 2), (int)(-getEnemyImg(i).Height / 2));  | 
        ||
| 842 | g.ResetTransform();  | 
        ||
| 843 |             } | 
        ||
| 844 | |||
| 845 |             //draw smoke | 
        ||
| 846 | for (int i = 0; i < smokes.Count; i++)  | 
        ||
| 847 |             { | 
        ||
| 848 | 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);  | 
        ||
| 849 |             } | 
        ||
| 850 | |||
| 851 |             //draw energy flux!! | 
        ||
| 852 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 853 |             { | 
        ||
| 854 | if (towers[i].fireing && towers[i].delayTime == towerTypes[towers[i].type].delay && towerTypes[towers[i].type].laserColour != null && towers[i].target != -1)  | 
        ||
| 855 |                 { | 
        ||
| 856 | 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);  | 
        ||
| 857 |                 } | 
        ||
| 858 |             } | 
        ||
| 859 | |||
| 860 | Font font1 = new Font(FontFamily.GenericMonospace, 10, FontStyle.Regular, GraphicsUnit.Pixel);  | 
        ||
| 861 | |||
| 862 | StringFormat sf = new StringFormat();  | 
        ||
| 863 | sf.Alignment = StringAlignment.Center;  | 
        ||
| 864 | |||
| 10 | freddie | 865 |             // Texts | 
        
| 1 | freddie | 866 | if (lives <= 0)  | 
        
| 867 | g.DrawString("You Loose!\nHAHAHA!", new Font(FontFamily.GenericMonospace, 40, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(controlFGColour), 250, 200, sf);  | 
        ||
| 868 | |||
| 869 | if (detailText != "" && enemies.Count == 0)  | 
        ||
| 870 | g.DrawString(textWrap(font1, detailText, 450), font1, new SolidBrush(controlFGColour), 250, 400 - TextRenderer.MeasureText(textWrap(font1, detailText, 450), font1).Height, sf);  | 
        ||
| 871 | |||
| 10 | freddie | 872 | if (showTotalOfEngery)  | 
        
| 873 | g.DrawString(energyTotal().ToString(), font1, new SolidBrush(controlFGColour), 10, 10);  | 
        ||
| 874 | |||
| 875 |             // Finals | 
        ||
| 1 | freddie | 876 | view.Image = (Image)img.Clone();  | 
        
| 877 | g.Dispose();  | 
        ||
| 878 | img.Dispose();  | 
        ||
| 879 | |||
| 880 | cashF.Refresh();  | 
        ||
| 881 | livesF.Refresh();  | 
        ||
| 882 | levelF.Refresh();  | 
        ||
| 883 | view.Refresh();  | 
        ||
| 884 | |||
| 885 |         } | 
        ||
| 886 | |||
| 7 | freddie | 887 | public PointF[] rndmisePoints(PointF[] oldPoints, bool ignoreStartAndEnd)  | 
        
| 888 |         { | 
        ||
| 889 | PointF[] newPoints = oldPoints;  | 
        ||
| 890 | if (ignoreStartAndEnd)  | 
        ||
| 891 |                 { | 
        ||
| 892 | for (int i = 1; i < newPoints.Length - 1; i++)  | 
        ||
| 893 | newPoints[i] = new PointF(oldPoints[i].X + (float)rnd.Next(-5, 6), oldPoints[i].Y + (float)rnd.Next(-5, 6));  | 
        ||
| 894 |                 } | 
        ||
| 895 |                 else | 
        ||
| 896 |                 { | 
        ||
| 897 | for (int i = 0; i < newPoints.Length; i++)  | 
        ||
| 898 | newPoints[i] = new PointF(oldPoints[i].X + (float)rnd.Next(-5, 6), oldPoints[i].Y + (float)rnd.Next(-5, 6));  | 
        ||
| 899 |                 } | 
        ||
| 900 | return newPoints;  | 
        ||
| 901 |         } | 
        ||
| 902 | |||
| 1 | freddie | 903 | public string textWrap(Font font, string textN, int width)  | 
        
| 904 |         { | 
        ||
| 905 | string text = textN;  | 
        ||
| 906 | int lastSpace = 1;  | 
        ||
| 907 | for (int i = 1; i < text.Length; i++)  | 
        ||
| 908 |                 { | 
        ||
| 909 | if (text.Substring(i, 1) == " ")  | 
        ||
| 910 | lastSpace = i;  | 
        ||
| 911 | if (TextRenderer.MeasureText(text.Substring(0, i), font).Width > width)  | 
        ||
| 912 | text = text.Substring(0, lastSpace) + "\n" + text.Substring(lastSpace + 1);  | 
        ||
| 913 |                 } | 
        ||
| 914 | return text;  | 
        ||
| 915 |         } | 
        ||
| 916 | |||
| 917 | public void drawBG()  | 
        ||
| 918 |         { | 
        ||
| 919 | |||
| 920 | Bitmap img = new Bitmap(500, 400);  | 
        ||
| 921 | Graphics g = Graphics.FromImage(img);  | 
        ||
| 922 | |||
| 923 | g.DrawImage(bgImg, 0, 0);  | 
        ||
| 924 | |||
| 925 |             Image baseImg; | 
        ||
| 926 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 927 |             { | 
        ||
| 928 | baseImg = getBaseImg(i);  | 
        ||
| 929 | g.TranslateTransform(towers[i].loc.X, towers[i].loc.Y);  | 
        ||
| 930 | g.DrawImage(baseImg, (int)(-baseImg.Width / 2), (int)(-baseImg.Height / 2));  | 
        ||
| 931 | if (rangeRings)  | 
        ||
| 932 | 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);  | 
        ||
| 933 | g.ResetTransform();  | 
        ||
| 934 |             } | 
        ||
| 935 | |||
| 936 | view.BackgroundImage = (Image)img.Clone();  | 
        ||
| 937 | g.Dispose();  | 
        ||
| 938 | img.Dispose();  | 
        ||
| 939 | |||
| 940 |         } | 
        ||
| 941 | |||
| 942 | private void view_MouseClick(object sender, MouseEventArgs e)  | 
        ||
| 943 |         { | 
        ||
| 944 | if (e.Button == MouseButtons.Left)  | 
        ||
| 945 |                    { | 
        ||
| 946 | if (cash >= towerTypes[selTowerType].cost)  | 
        ||
| 947 |                     { | 
        ||
| 948 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 949 |                                 { | 
        ||
| 950 | 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)  | 
        ||
| 951 |                                         { | 
        ||
| 952 | return;  | 
        ||
| 953 |                                         } | 
        ||
| 954 |                                 } | 
        ||
| 955 | cash -= towerTypes[selTowerType].cost;  | 
        ||
| 956 | towers.Add(new tower(selTowerType, e.Location, towerTypes[selTowerType].sound));  | 
        ||
| 957 | drawBG();  | 
        ||
| 958 | draw();  | 
        ||
| 959 |                     } | 
        ||
| 960 |                 } | 
        ||
| 961 |                 else | 
        ||
| 962 |                 { | 
        ||
| 963 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 964 |                         { | 
        ||
| 965 | 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)  | 
        ||
| 966 |                                 { | 
        ||
| 967 | cash += (int)(towerTypes[towers[i].type].cost / 2);  | 
        ||
| 968 | towers.RemoveAt(i);  | 
        ||
| 969 | drawBG();  | 
        ||
| 970 | draw();  | 
        ||
| 971 | return;  | 
        ||
| 972 |                                 } | 
        ||
| 973 |                         } | 
        ||
| 974 |                 } | 
        ||
| 975 |         } | 
        ||
| 976 | |||
| 977 | float getAngle(Point a, Point b)  | 
        ||
| 978 |         { | 
        ||
| 979 | if (a.X == b.X)  | 
        ||
| 980 |             { | 
        ||
| 981 | if (a.Y < b.Y)  | 
        ||
| 982 | return 90;  | 
        ||
| 983 |                 else | 
        ||
| 984 | return 270;  | 
        ||
| 985 |             } | 
        ||
| 986 | else if (a.Y == b.Y)  | 
        ||
| 987 |             { | 
        ||
| 988 | if (a.X < b.X)  | 
        ||
| 989 | return 0;  | 
        ||
| 990 |                 else | 
        ||
| 991 | return 180;  | 
        ||
| 992 |             } | 
        ||
| 993 | float output;  | 
        ||
| 994 | output = (float)(Math.Atan((b.Y - a.Y) / (float)(b.X - a.X)) / Math.PI * 180.0f);  | 
        ||
| 995 | if (a.X >= b.X)  | 
        ||
| 996 | output += 180;  | 
        ||
| 997 | if (output > 360)  | 
        ||
| 998 | output -= 360;  | 
        ||
| 999 | return output;  | 
        ||
| 1000 |         } | 
        ||
| 1001 | |||
| 1002 | private void pictureBox1_Click(object sender, EventArgs e)  | 
        ||
| 1003 |         { | 
        ||
| 1004 | if (enemies.Count == 0)  | 
        ||
| 1005 | newRun();  | 
        ||
| 1006 |         } | 
        ||
| 1007 | |||
| 1008 | public void initMove(int num)  | 
        ||
| 1009 |         { | 
        ||
| 1010 | enemies[num].dX = (float)Math.Cos(enemies[num].angle / 180 * Math.PI) * enemyTypes[enemies[num].type].speed;  | 
        ||
| 1011 | enemies[num].dY = (float)Math.Sin(enemies[num].angle / 180 * Math.PI) * enemyTypes[enemies[num].type].speed;  | 
        ||
| 1012 |         } | 
        ||
| 1013 | |||
| 1014 | public void move(int num)  | 
        ||
| 1015 |         { | 
        ||
| 1016 | enemies[num].loc.X += enemies[num].dX;  | 
        ||
| 1017 | enemies[num].loc.Y += enemies[num].dY;  | 
        ||
| 1018 |         } | 
        ||
| 1019 | |||
| 1020 | public void reTarget(int num)  | 
        ||
| 1021 |         { | 
        ||
| 1022 | bool res;  | 
        ||
| 1023 | int tempEn;  | 
        ||
| 1024 | if (towers[num].target != -1)  | 
        ||
| 1025 |                 { | 
        ||
| 1026 | tempEn = towers[num].target;  | 
        ||
| 1027 | towers[num].targets.Clear();  | 
        ||
| 1028 | towers[num].target = tempEn;  | 
        ||
| 1029 |                 } | 
        ||
| 1030 |                 else | 
        ||
| 1031 | towers[num].targets.Clear();  | 
        ||
| 10 | freddie | 1032 | int start = rnd.Next(0, enemies.Count - 1);  | 
        
| 1033 | int i;  | 
        ||
| 1034 | for (int inc = 0; inc < enemies.Count; inc++)  | 
        ||
| 1 | freddie | 1035 |             { | 
        
| 10 | freddie | 1036 | i = inc + start;  | 
        
| 1037 | if (i >= enemies.Count)  | 
        ||
| 1038 | i -= enemies.Count;  | 
        ||
| 1 | freddie | 1039 | if (towerTypes[towers[num].type].laserType == 2 && towers[num].target != -1)  | 
        
| 1040 | 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;  | 
        ||
| 1041 |                 else | 
        ||
| 1042 | res = enemies[i].loc.X >= 0 && getDist(towers[num].loc, FtoP(enemies[i].loc)) <= towerTypes[towers[num].type].range && enemies[i].health > 0;  | 
        ||
| 1043 | if (res)  | 
        ||
| 1044 |                 { | 
        ||
| 1045 | if (towerTypes[towers[num].type].laserType == 2)  | 
        ||
| 1046 |                         { | 
        ||
| 1047 | if (!towers[num].targets.Contains(i) || rnd.Next(0,2) == 0)  | 
        ||
| 1048 | towers[num].targets.Add(i);  | 
        ||
| 1049 | if (rnd.Next(0, towerTypes[towers[num].type].killNum) == 0)  | 
        ||
| 1050 | return;  | 
        ||
| 1051 |                         } | 
        ||
| 1052 |                         else | 
        ||
| 1053 |                         { | 
        ||
| 1054 | towers[num].target = i;  | 
        ||
| 1055 | return;  | 
        ||
| 1056 |                         } | 
        ||
| 1057 |                 } | 
        ||
| 1058 |             } | 
        ||
| 10 | freddie | 1059 |                 // no target found | 
        
| 1 | freddie | 1060 | if (towerTypes[towers[num].type].laserType != 2)  | 
        
| 1061 | towers[num].target = -1;  | 
        ||
| 1062 |         } | 
        ||
| 1063 | |||
| 1064 | public void reAngle(int num)  | 
        ||
| 1065 |         { | 
        ||
| 1066 | if (towers[num].target != -1)  | 
        ||
| 1067 | towers[num].angle = (float)getAngle(towers[num].loc, new Point((int)enemies[towers[num].target].loc.X, (int)enemies[towers[num].target].loc.Y));  | 
        ||
| 1068 |         } | 
        ||
| 1069 | |||
| 1070 | public void fire(int num, bool fireing)  | 
        ||
| 1071 |         { | 
        ||
| 1072 | towers[num].fireing = fireing;  | 
        ||
| 1073 | //              towers[num].s.controls.stop(); | 
        ||
| 1074 | //              if (sound && fireing) | 
        ||
| 1075 | //              { | 
        ||
| 1076 | //                      if (towers[num].s.playState != WMPLib.WMPPlayState.wmppsPlaying) | 
        ||
| 1077 | //                              towers[num].s.controls.play(); | 
        ||
| 1078 | //              } | 
        ||
| 1079 |         } | 
        ||
| 1080 | |||
| 1081 | public Point FtoP(PointF point)  | 
        ||
| 1082 |         { | 
        ||
| 1083 | return new Point((int)point.X, (int)point.Y);  | 
        ||
| 1084 |         } | 
        ||
| 1085 | |||
| 1086 | public int getDist(Point a, Point b)  | 
        ||
| 1087 |         { | 
        ||
| 1088 | return (int)Math.Sqrt(Math.Abs((a.X - b.X) * (a.X - b.X)) + Math.Abs((a.Y - b.Y) * (a.Y - b.Y)));  | 
        ||
| 1089 |         } | 
        ||
| 1090 | |||
| 1091 | void IconPress(object sender, EventArgs e)  | 
        ||
| 1092 |         { | 
        ||
| 1093 | PictureBox icon = (PictureBox)sender;  | 
        ||
| 1094 | if (towerTypes[(int)icon.Tag].cost <= cash)  | 
        ||
| 1095 |                 { | 
        ||
| 1096 | selTowerType = (int)icon.Tag;  | 
        ||
| 1097 | draw();  | 
        ||
| 1098 |                 } | 
        ||
| 1099 |         } | 
        ||
| 1100 | |||
| 1101 | void IconEnter(object sender, EventArgs e)  | 
        ||
| 1102 |         { | 
        ||
| 1103 | PictureBox icon = (PictureBox)sender;  | 
        ||
| 1104 | if (towerTypes[(int)icon.Tag].laserType != -1)  | 
        ||
| 1105 | detailText = towerTypes[(int)icon.Tag].name + " - €" + towerTypes[(int)icon.Tag].cost + " - " + laserTypeLookup[towerTypes[(int)icon.Tag].laserType] + "\n" + towerTypes[(int)icon.Tag].details[lang];  | 
        ||
| 1106 | //              else | 
        ||
| 1107 | //                      detailText = towerTypes[(int)icon.Tag].name + " - €" + towerTypes[(int)icon.Tag].cost + " - MType\n" + towerTypes[(int)icon.Tag].details; | 
        ||
| 1108 | draw();  | 
        ||
| 1109 |         } | 
        ||
| 1110 | |||
| 1111 | void IconLeave(object sender, EventArgs e)  | 
        ||
| 1112 |         { | 
        ||
| 1113 | detailText = "";  | 
        ||
| 1114 | draw();  | 
        ||
| 1115 |         } | 
        ||
| 1116 | |||
| 1117 | void Form1KeyDown(object sender, KeyEventArgs e)  | 
        ||
| 1118 |         { | 
        ||
| 1119 | switch (e.KeyCode)  | 
        ||
| 1120 |                 { | 
        ||
| 1121 | case Keys.Back:  | 
        ||
| 1122 | cash += 1000;  | 
        ||
| 1123 | break;  | 
        ||
| 1124 | case Keys.Space:  | 
        ||
| 1125 | energyBars = !energyBars;  | 
        ||
| 1126 | break;  | 
        ||
| 1127 | case Keys.Enter:  | 
        ||
| 1128 | if (enemies.Count == 0)  | 
        ||
| 1129 | newRun();  | 
        ||
| 1130 | break;  | 
        ||
| 1131 | case Keys.Tab:  | 
        ||
| 1132 | autoRun = !autoRun;  | 
        ||
| 1133 | if (autoRun)  | 
        ||
| 1134 | goF.BackgroundImage = noImg;  | 
        ||
| 1135 |                                 else | 
        ||
| 1136 | goF.BackgroundImage = yesImg;  | 
        ||
| 1137 | break;  | 
        ||
| 1138 | case Keys.F8:  | 
        ||
| 1139 |                                 level++; | 
        ||
| 1140 | if (level >= levels.Length)  | 
        ||
| 1141 | level = 0;  | 
        ||
| 1142 | break;  | 
        ||
| 1143 | case Keys.R:  | 
        ||
| 1144 | rangeRings = !rangeRings;  | 
        ||
| 1145 | drawBG();  | 
        ||
| 1146 | break;  | 
        ||
| 1147 | case Keys.F4:  | 
        ||
| 1148 | timer1.Enabled = !timer1.Enabled;  | 
        ||
| 1149 | break;  | 
        ||
| 7 | freddie | 1150 | case Keys.E:  | 
        
| 1151 | extraPretty = !extraPretty;  | 
        ||
| 1152 | break;  | 
        ||
| 10 | freddie | 1153 | case Keys.T:  | 
        
| 1154 | showTotalOfEngery = !showTotalOfEngery;  | 
        ||
| 1155 | break;  | 
        ||
| 1 | freddie | 1156 | //                      case Keys.S: | 
        
| 1157 | //                              sound = !sound; | 
        ||
| 1158 | //                              break; | 
        ||
| 1159 | default:  | 
        ||
| 1160 | if (e.KeyCode.ToString().Length > 1)  | 
        ||
| 1161 |                                 { | 
        ||
| 1162 | int res;  | 
        ||
| 1163 | if (int.TryParse(e.KeyCode.ToString().Substring(1, 1), out res))  | 
        ||
| 1164 |                                         { | 
        ||
| 1165 | if (res < towerTypes.Count)  | 
        ||
| 1166 |                                                 { | 
        ||
| 1167 | if (cash >= towerTypes[res].cost)  | 
        ||
| 1168 | selTowerType = res;  | 
        ||
| 1169 |                                                 } | 
        ||
| 1170 |                                         } | 
        ||
| 1171 |                                 } | 
        ||
| 1172 | break;  | 
        ||
| 1173 |                 } | 
        ||
| 1174 | draw();  | 
        ||
| 1175 | |||
| 1176 |         } | 
        ||
| 1177 | |||
| 1178 | void Form1FormClosing(object sender, FormClosingEventArgs e)  | 
        ||
| 1179 |         { | 
        ||
| 1180 | autoRun = false;  | 
        ||
| 1181 | Form2 menu = new Form2();  | 
        ||
| 1182 | menu.Show();  | 
        ||
| 1183 |         } | 
        ||
| 1184 | |||
| 1185 | void Timer1Tick(object sender, EventArgs e)  | 
        ||
| 1186 |         { | 
        ||
| 1187 | this.Text = "Blockade! [" + (fCount * 2) + "FPS]";  | 
        ||
| 1188 | fCount = 0;  | 
        ||
| 1189 |         } | 
        ||
| 1190 | |||
| 1191 | Image getBaseImg(int num)  | 
        ||
| 1192 |         { | 
        ||
| 1193 | if (towerTypes[towers[num].type].baseImg.maxRunTime < towers[num].baseTime)  | 
        ||
| 1194 | towers[num].baseTime = 0;  | 
        ||
| 1195 | return towerTypes[towers[num].type].getBaseImg(towers[num].baseTime);  | 
        ||
| 1196 |         } | 
        ||
| 1197 | |||
| 1198 | Image getTurretImg(int num)  | 
        ||
| 1199 |         { | 
        ||
| 1200 | if (towerTypes[towers[num].type].turretImg.maxRunTime < towers[num].turretTime)  | 
        ||
| 1201 | towers[num].turretTime = 0;  | 
        ||
| 1202 | return towerTypes[towers[num].type].getTurretImg(towers[num].turretTime);  | 
        ||
| 1203 |         } | 
        ||
| 1204 | |||
| 1205 | Image getEnemyImg(int num)  | 
        ||
| 1206 |         { | 
        ||
| 1207 | if (enemyTypes[enemies[num].type].img.maxRunTime < enemies[num].imgTime)  | 
        ||
| 1208 | enemies[num].imgTime = 0;  | 
        ||
| 1209 | return enemyTypes[enemies[num].type].getImg(enemies[num].imgTime);  | 
        ||
| 1210 |         } | 
        ||
| 10 | freddie | 1211 | |
| 1212 | public double energyTotal()  | 
        ||
| 1213 |         { | 
        ||
| 1214 | double output = 0.0;  | 
        ||
| 1215 | for (int i = 0; i < towers.Count; i++)  | 
        ||
| 1216 | output += towers[i].energy;  | 
        ||
| 1217 | return output;  | 
        ||
| 1218 |         } | 
        ||
| 1 | freddie | 1219 |     } | 
        
| 1220 | } |