public Explosion(GameManager gameManager, EnemySpawner es, EnemyMissile hostile, Vector2f spawnHere, Building hitBuilding, int setType) { gm = gameManager; ExplosionLocation = spawnHere; ExplosionLocationTopLeft = new Vector2f(ExplosionLocation.X - Expl_size / 2f, ExplosionLocation.Y - Expl_size / 2f); enemySpawner = es; type = setType; //Prevent out of range exception, in case the building is already destroyed try { nukeTown = gm.GetBuildings()[gm.GetBuildings().IndexOf(hitBuilding)]; } catch (Exception e) { Console.WriteLine("==============================================="); Console.WriteLine(string.Format("Error: {0}", e)); Console.WriteLine(string.Format("Count: {0}, attemping to access {1}", gm.GetBuildings().Count, gm.GetBuildings().IndexOf(hitBuilding))); Console.WriteLine("==============================================="); gm.error_reason = e; Registers.gameState = GameState.Error; } rec_explosion.X = spawnHere.X; rec_explosion.Y = spawnHere.Y; }
public override void Paint() { if (Registers.gameState == GameState.Running) { GAME_ENGINE.SetColor(200, 50, 0); drawHere = Utils.Lerp2D(origin, dest, curTime / 2); GAME_ENGINE.FillRectangle(drawHere.X, drawHere.Y, 5, 5); GAME_ENGINE.DrawLine(origin, new Vector2f(drawHere.X + 2.5f, drawHere.Y + 2.5f), 5f); //Explode when ,missile has reached its destination if (Utils.Distance(drawHere, dest) <= 1) { if (targetID <= gameManager.GetBuildings().Count - 1) { explM = new Explosion(gameManager, enemySpawner, this, drawHere, gameManager.GetBuildings()[targetID], 0); } Console.WriteLine(string.Format("Explosions #{0}", gameManager.explosions.Count)); enemySpawner.EMissileDetonate(this); Dispose(); } curTime += GAME_ENGINE.GetDeltaTime() / 2.5f; //Destroy missile when out of screen if (Utils.Distance(drawHere, new Vector2f(Alignment.X.Left, Alignment.Y.Up)) <= 0 && Utils.Distance(drawHere, new Vector2f(Alignment.X.Right, Alignment.Y.Down)) <= 0) { enemySpawner.EMissileDetonate(this); Dispose(); } } }
public override void Paint() { if (Registers.gameState == GameState.Running) { //Type = 0, friendly missile //Type = 1, enemy missile if (type == 0) { GAME_ENGINE.SetColor(rda.Next(0, 255), rda.Next(0, 255), rda.Next(0, 255)); GAME_ENGINE.FillEllipse(rec_explosion); } else { #if (DEBUG) GAME_ENGINE.DrawBitmap(explosion_bmp, ExplosionLocationTopLeft); #endif } duration -= GAME_ENGINE.GetDeltaTime() * 2.4f; if (nukeTown != null && nuked == false) { List <Building> checkBuildings = gm.GetBuildings(); for (int i = 0; i < 6; i++) { if (i == 5) { Console.WriteLine(string.Format("Size: {0}", checkBuildings.Count)); i = 5; } if (checkBuildings[i] == null) { continue; } if (Utils.Distance(new Vector2f(checkBuildings[i].GetX() + checkBuildings[i].GetWidth() * 0.5f, checkBuildings[i].GetY() + checkBuildings[i].GetHeight()), ExplosionLocation) < 40f) { Console.WriteLine(string.Format("Building hit! {0}", i)); nukeTown.Nuke(); nuked = true; break; } } } if (type == 0) { ExplosionCollision(); } if (duration <= 0f) { Dispose(); } } }
public void EMissileDetonate(EnemyMissile detEMissile) { detEMissile.explM = new Explosion(gameManager, this, detEMissile, detEMissile.GetLocation(), gameManager.GetBuildings()[detEMissile.targetID], 0); Console.WriteLine("Demontated missile"); if (emissiles.Contains(detEMissile)) { detEMissile.Dispose(); emissiles.Remove(detEMissile); } return; }