public override void applyEffect(Tower tower) { if (tower.DefaultDmg != 0) { tower.Dmg = (int)(tower.DefaultDmg * (1 + damageInc)); } tower.Range = (int)(tower.DefaultRange * (1 + rangeInc)); }
// Update the tower and its projectiles public override void Update(GameTime time) { ArrayList keysToRemove = updateEffects(time); removeEffects(keysToRemove); Move(); // For now just move when told to update if (Lost) { game.status.Survived += 1; Die(); } else { // Increments the firing timer until tower can fire //ArrayList keysToRemove = applyEffects(gameTime); //removeEffect(keysToRemove); Reload(time); // If ready to fire... if (attackTimer >= attackRate) { // Update target if current one is dead or out of range if (targeted == null || targeted.Dead || Distance(targeted) > range) targeted = AcquireFirstTarget(); else { Attack(); // If there is a valid target, fire at it attackTimer = 0; } } //UpdateProjectiles(); // update projectiles } }
public override void undoEffect(Tower tower) { tower.Dmg = tower.DefaultDmg; tower.Range = tower.DefaultRange; }
// Update's the user's tower selection private void UpdateSelection() { if (wMouseR.Intersects(game.world.map) && !buildMode) { foreach (Tower t in game.world.towers) { if (wMouseR.Intersects(t.Rectangle)) { selection = t; } } } }
// Respond to all mouse actions and updates mouse variables private void UpdateMouse() { Boolean mouseMoved; // Update mouse mouse = Mouse.GetState(); // update mouse state mouseMoved = (mouse != mouseWas); // if the mouse has moved or not // Update different mouse representations if it has moved if (mouseMoved) { mouseR = new Rectangle(mouse.X, mouse.Y, 1, 1); wMouse = new Vector2(mouse.X / camera.Zoom + camera.ViewArea.Left, mouse.Y / camera.Zoom + camera.ViewArea.Top); wMouseR = new Rectangle((int)wMouse.X, (int)wMouse.Y, 1, 1); if (buildMode) { mouseTile = new Rectangle((int)(wMouse.X / game.world.tile) * game.world.tile, (int)(wMouse.Y / game.world.tile) * game.world.tile, game.world.tile * mTiles, game.world.tile * mTiles); //float bSide = game.world.tile * mTiles; // mouseTile = new Rectangle((int)(wMouse.X - bSide / 2), (int)(wMouse.Y - buildHeight / 2), // (int)bSide, (int)bSide); canBuild = CanBuild(); } } if (mouse.LeftButton == ButtonState.Pressed) { MoveCam(); // check if the player is moving the camera on the minimap if (mouseWas.LeftButton == ButtonState.Released) { if (!game.world.startWaves && !buildMode && startButtonArea.Contains(new Point(mouse.X, mouse.Y))) { game.world.startWaves = true; //game.music.ChangeTrack(); } UpdateSelection(); // check if a new selection is being made CheckButtons(); // check if a button is being pressed CheckBuilding(); // check if a tower is supposed to be built } } else if (mouse.RightButton == ButtonState.Pressed) { // Single mouse right-click if (mouseWas.RightButton == ButtonState.Released) { if (buildMode) { ExitBuildMode(); // leave build mode } else { selection = null; // deselect whatever tower is selected } } } mouseWas = mouse; // save the state the mouse was in this update }
// Respond to all keyboard actions and updates keyboard variables private void UpdateKeyboard() { keyboard = Keyboard.GetState(); // update keyboard state // Checks to see if any keys are pressed or being held down and takes action if (keyboard.GetPressedKeys().Length > 0) { if ((keyboard.IsKeyDown(Keys.PageUp) && keyboardWas.IsKeyDown(Keys.PageUp) == false)) { game.music.Volume += 0.1f; } else if ((keyboard.IsKeyDown(Keys.PageDown) && keyboardWas.IsKeyDown(Keys.PageDown) == false)) { game.music.Volume -= 0.1f; } else if ((keyboard.IsKeyDown(Keys.OemTilde) && keyboardWas.IsKeyDown(Keys.OemTilde) == false)) { debugInfo = !debugInfo; } else if ((keyboard.IsKeyDown(Keys.Delete) && keyboardWas.IsKeyDown(Keys.Delete) == false)) { if (selection != null) { game.status.Money += selection.currentWorth(); game.world.towers.Remove(selection); selection = null; } } else if (keyboard.IsKeyDown(Keys.Escape) && keyboardWas.IsKeyDown(Keys.Escape) == false) { if (buildMode) { ExitBuildMode(); } drawMenu = !drawMenu; displayControls = false; if (drawMenu) { game.world.paused = true; } else { game.world.paused = false; } } else if ((keyboard.IsKeyDown(Keys.Space) && keyboardWas.IsKeyDown(Keys.Space) == false)) { ExpandMinimap(); } else if ((keyboard.IsKeyDown(Keys.LeftAlt) && keyboardWas.IsKeyDown(Keys.LeftAlt) == false)) { game.world.dTowerLVLS = !game.world.dTowerLVLS; } else if ((keyboard.IsKeyDown(Keys.P) && keyboardWas.IsKeyDown(Keys.P) == false)) { if(!drawMenu) game.world.paused = !game.world.paused; } else if(keyboard.IsKeyDown(Keys.OemComma) && keyboardWas.IsKeyDown(Keys.OemComma)==false) { if (game.status.GraphicsQuality >= .1) { game.status.GraphicsQuality =(float)Math.Round(game.status.GraphicsQuality-.1f,1); Console.WriteLine("Graphics decreased by .1 to " + game.status.GraphicsQuality); } } else if(keyboard.IsKeyDown(Keys.OemPeriod) && keyboardWas.IsKeyDown(Keys.OemPeriod)==false) { if (game.status.GraphicsQuality <= .9) { game.status.GraphicsQuality = (float)Math.Round(game.status.GraphicsQuality + .1f, 1); Console.WriteLine("Graphics increased by .1 to " + game.status.GraphicsQuality); } } else if (keyboard.IsKeyDown(Keys.S) && keyboardWas.IsKeyDown(Keys.S) == false) { game.status.Sound = !game.status.Sound; Console.WriteLine("Sound Toggled " + game.status.Sound); } else if (keyboard.IsKeyDown(Keys.T) && keyboardWas.IsKeyDown(Keys.T) == false) { drawPaths = !drawPaths; } // Adjust camera position if (keyboard.IsKeyDown(Keys.Down)) { camera.Move(new Vector2(0, scrollValue)); } else if (keyboard.IsKeyDown(Keys.Up)) { camera.Move(new Vector2(0, -scrollValue)); } if (keyboard.IsKeyDown(Keys.Left)) { camera.Move(new Vector2(-scrollValue, 0)); } else if (keyboard.IsKeyDown(Keys.Right)) { camera.Move(new Vector2(scrollValue, 0)); } if (keyboard.IsKeyDown(Keys.OemPlus)) { camera.ZoomIn(zoomValue); } else if (keyboard.IsKeyDown(Keys.OemMinus)) { camera.ZoomOut(zoomValue); } } keyboardWas = keyboard; // save the state the keyboard was in this update }
// TEST METHOD private void TowerType(String buildType) { Rectangle empty = new Rectangle(0, 0, 0, 0); switch (buildType) { case("Rocket"): toBeBuilt = new RocketTower(game.world, empty); break; case("MG"): toBeBuilt = new MGTower(game.world, empty); break; case("Pulse"): toBeBuilt = new PulseTower(game.world, empty); break; case("Flame"): toBeBuilt = new FlameTower(game.world, empty); break; case("Artillery"): toBeBuilt = new ArtilleryTower(game.world, empty); break; case ("Concussion"): toBeBuilt = new ConcussionTower(game.world, empty); break; case ("Command"): toBeBuilt = new CommandCenter(game.world, empty); break; case ("Rifle"): toBeBuilt = new RifleTower(game.world, empty); break; case ("Gamma"): toBeBuilt = new GammaRayTower(game.world, empty); break; default: toBeBuilt = null; break; } }
// Exits out of build mode private void ExitBuildMode() { mouseTile = new Rectangle(-1, -1, 0, 0); buildType = null; toBeBuilt = null; buildMode = false; // Release all tower buttons that may be down foreach (Button b in buttonsDirect) { b.Release(); } foreach (Button b in buttonsSplash) { b.Release(); } foreach (Button b in buttonsUtility) { b.Release(); } }
public abstract void undoEffect(Tower tower);
public abstract void applyEffect(Tower tower);
protected float Distance(Tower target) { // Standard distance formula return (float)(Math.Sqrt(Math.Pow(target.Center.X - position.X, 2) + Math.Pow(target.Center.Y - position.Y, 2))); }
protected float Distance(Tower tower) { // Standard distance formula return (tower.Center - center).Length(); }