/// <summary> /// Returns whether or not the entity is facing the specified entity /// </summary> /// <param name="e">The entity</param> /// <param name="scalar">The scaled distance to check</param> /// <returns>Returns true if the entity is facing the specified entity; otherwise, false</returns> public bool isFacing(Entity e, float scalar) { bool horiz = getHDistance(e) <= getVDistance(e); if (!horiz) { if (e.getLocation().X >= location.X) { return(direction == Direction.East); } else { return(direction == Direction.West); } } else { if (e.getLocation().Y >= location.Y) { return(direction == Direction.South); } else { return(direction == Direction.North); } } }
/// <summary> /// Returns the distance to the specified entity /// </summary> /// <param name="e">The entity</param> /// <returns>Returns the Euclidean distance to the specified entity</returns> public int getDistance(Entity e) { double eLocX = e.getLocation().X + (e.getTexture().Width / 2); double eLocY = e.getLocation().Y + (e.getTexture().Height / 2); double locX = location.X + (texture.Width / 2); double locY = location.Y + (texture.Height / 2); return((int)Math.Sqrt(Math.Pow(eLocX - locX, 2.0D) + Math.Pow(eLocY - locY, 2.0D)) - (e.getTexture().Width / 2) - (texture.Width / 2)); }
/// <summary> /// Sets the entity to face the specified entity /// </summary> /// <param name="e">The entity</param> public void setFacing(Entity e) { if (Math.Abs(e.getLocation().X - location.X) <= texture.Width) { direction = e.getLocation().Y >= location.Y ? Direction.South : Direction.North; } else if (e.getLocation().X < location.X) { direction = Direction.West; } else { direction = Direction.East; } }
public Projectile(Entity owner, Texture2D texture, int velocity, int cooldown, float rotationSpeed, SoundEffect sound) { this.owner = owner; this.texture = texture; this.velocity = velocity; this.cooldown = cooldown; this.rotationSpeed = rotationSpeed; this.sound = sound; this.origin = new Vector2(texture.Width / 2.0F, texture.Height / 2.0F); this.location = new Vector2(owner.getLocation().X + (owner.getTexture().Width - texture.Width) / 2.0F, owner.getLocation().Y + (owner.getTexture().Height - texture.Height) / 2.0F); this.direction = Direction.None; this.bounds = new Rectangle((int) location.X, (int) location.Y, texture.Width, texture.Height); this.rotation = 0.0F; this.active = true; }
public Projectile(Entity owner, Texture2D texture, int velocity, int cooldown, float rotationSpeed, SoundEffect sound) { this.owner = owner; this.texture = texture; this.velocity = velocity; this.cooldown = cooldown; this.rotationSpeed = rotationSpeed; this.sound = sound; this.origin = new Vector2(texture.Width / 2.0F, texture.Height / 2.0F); this.location = new Vector2(owner.getLocation().X + (owner.getTexture().Width - texture.Width) / 2.0F, owner.getLocation().Y + (owner.getTexture().Height - texture.Height) / 2.0F); this.direction = Direction.None; this.bounds = new Rectangle((int)location.X, (int)location.Y, texture.Width, texture.Height); this.rotation = 0.0F; this.active = true; }
/// <summary> /// Returns whether or not the entity is facing the specified entity /// </summary> /// <param name="e">The entity</param> /// <param name="scalar">The scaled distance to check</param> /// <returns>Returns true if the entity is facing the specified entity; otherwise, false</returns> public bool isFacing(Entity e, float scalar) { bool horiz = getHDistance(e) <= getVDistance(e); if (!horiz) { if (e.getLocation().X >= location.X) { return direction == Direction.East; } else { return direction == Direction.West; } } else { if (e.getLocation().Y >= location.Y) { return direction == Direction.South; } else { return direction == Direction.North; } } }
/// <summary> /// Returns the vertical Euclidean distance to the specified entity /// </summary> /// <param name="e"></param> /// <returns></returns> public int getVDistance(Entity e) { double eLocY = e.getLocation().Y + (e.getTexture().Height / 2); double locY = location.Y + (texture.Height / 2); return (int) Math.Sqrt(Math.Pow(eLocY - locY, 2.0D)) - (e.getTexture().Height / 2) - (texture.Height / 2); }
/// <summary> /// Returns the horizontal Euclidean distance to the specified entity /// </summary> /// <param name="e">The entity</param> /// <returns>Returns the horizontal Euclidean distance to the specified entity</returns> public int getHDistance(Entity e) { double eLocX = e.getLocation().X + (e.getTexture().Width / 2); double locX = location.X + (texture.Width / 2); return (int) Math.Sqrt(Math.Pow(eLocX - locX, 2.0D)) - (e.getTexture().Width / 2) - (texture.Width / 2); }
/// <summary> /// Updates the game while in telekinesis /// </summary> /// <param name="time">The GameTime to respect</param> private void updateTelekinesisMove(GameTime time) { playerManager.updateManaDrainRate(); Entity eCollision = collisionManager.getEntityCollision(selectedObject); if (currentKeyState.IsKeyDown(Keys.Up)) { selectedObject.setDirection(Direction.North); selectedObject.setDestination(new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y - velocity)); if (selectedObject.getDestination().Y > 0 && collisionManager.isValid(selectedObject)) { selectedObject.deriveY(-velocity); if (playerManager.getManaDrainRate() == 5) { playerManager.depleteMana(2); } } else { selectedObject.setDestination(selectedObject.getLocation()); if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (currentKeyState.IsKeyDown(Keys.Down)) { selectedObject.setDirection(Direction.South); selectedObject.setDestination(new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y + velocity)); if (selectedObject.getDestination().Y < height - selectedObject.getTexture().Height&& collisionManager.isValid(selectedObject)) { selectedObject.deriveY(velocity); if (playerManager.getManaDrainRate() == 5) { playerManager.depleteMana(2); } } else { selectedObject.setDestination(selectedObject.getLocation()); if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (currentKeyState.IsKeyDown(Keys.Left)) { selectedObject.setDirection(Direction.West); selectedObject.setDestination(new Vector2(selectedObject.getLocation().X - velocity, selectedObject.getLocation().Y)); if (selectedObject.getDestination().X > 0 && collisionManager.isValid(selectedObject)) { selectedObject.deriveX(-velocity); if (playerManager.getManaDrainRate() == 5) { playerManager.depleteMana(2); } } else { selectedObject.setDestination(selectedObject.getLocation()); if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (currentKeyState.IsKeyDown(Keys.Right)) { selectedObject.setDirection(Direction.East); selectedObject.setDestination(new Vector2(selectedObject.getLocation().X + velocity, selectedObject.getLocation().Y)); if (selectedObject.getDestination().X < width - selectedObject.getTexture().Width&& collisionManager.isValid(selectedObject)) { selectedObject.deriveX(velocity); if (playerManager.getManaDrainRate() == 5) { playerManager.depleteMana(2); } } else { selectedObject.setDestination(selectedObject.getLocation()); if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else { selectedObject.setDestination(selectedObject.getLocation()); } if ((moving || (lastKeyState.IsKeyDown(Keys.Space) && currentKeyState.IsKeyDown(Keys.Space))) && playerManager.getMana() > 0) { moving = true; if (selectedObject.getDirection() == Direction.North) { selectedObject.setDestination(new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y - velocity)); if (selectedObject.getDestination().Y > 0 && collisionManager.isValid(selectedObject)) { selectedObject.deriveY(-velocity); } else { moving = false; } } else if (selectedObject.getDirection() == Direction.South) { selectedObject.setDestination(new Vector2(selectedObject.getLocation().X, selectedObject.getLocation().Y + velocity)); if (selectedObject.getDestination().Y < height - selectedObject.getTexture().Height&& collisionManager.isValid(selectedObject)) { selectedObject.deriveY(velocity); } else { moving = false; } } else if (selectedObject.getDirection() == Direction.West) { selectedObject.setDestination(new Vector2(selectedObject.getLocation().X - velocity, selectedObject.getLocation().Y)); if (selectedObject.getDestination().X > 0 && collisionManager.isValid(selectedObject)) { selectedObject.deriveX(-velocity); } else { moving = false; } } else { selectedObject.setDestination(new Vector2(selectedObject.getLocation().X + velocity, selectedObject.getLocation().Y)); if (selectedObject.getDestination().X < width - selectedObject.getTexture().Width&& collisionManager.isValid(selectedObject)) { selectedObject.deriveX(velocity); } else { moving = false; } } if (playerManager.getManaDrainRate() == 5) { playerManager.depleteMana(1); } if (!moving) { selectedObject.setDestination(selectedObject.getLocation()); if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } gameState = GameState.Normal; selectedObject.setSelected(false); selectedObject = null; level.setMode(0); } } else if ((lastKeyState.IsKeyDown(Keys.Q) && currentKeyState.IsKeyUp(Keys.Q)) || playerManager.getMana() == 0) { moving = false; gameState = GameState.Normal; selectedObject.setSelected(false); selectedObject = null; level.setMode(0); } }
private void updateNormal(GameTime time) { if (!(collisionManager.getObjectCollision(player, true) is PlayerLimitationField)) { playerManager.setManaLimit(true); playerManager.setHealthLimit(true); } if (playerManager.getHealthCooldown() == 35 && playerManager.getHealthLimit() && playerManager.getManaLimit()) { playerManager.regenerateHealth(); playerManager.regenerateMana(); } foreach (Npc n in level.getNpcs()) { NpcDefinition def = n.getDefinition(); if (def.getHints().Length > 0 && def.isShowing()) { def.update(false); } } GameObject gCollision = collisionManager.getObjectCollision(player, true); if (gCollision != null && gCollision is Token) { Token t = (Token)gCollision; level.takeCollectible(t); playerManager.incrementExperience(t.getExp()); playerManager.levelMana(t.getManaIncrementationValue()); PauseMenu pause = (PauseMenu)level.getScreen("Pause"); pause.setExperience(pause.getExperience() + t.getExp()); dropText = "+ " + t.getExp() + " EXP"; t.playEffect(); } else if (gCollision != null && gCollision is Key) { Key k = (Key)gCollision; level.takeCollectible(k); k.setUnlocked(true); level.unlockDoors(); k.playEffect(); } else if (gCollision != null && gCollision is Door) { Door d = (Door)gCollision; if (d.isUnlocked()) { int next = (game.getLevelIndex()) + (d.continues() ? 1 : -1); if (next == 7) { gameState = GameState.Outro; finished = true; return; } Song current = level.getSong(); level.setActive(false); game.setLevel(next); prevLevel = level; level = game.getLevel(next); PauseMenu pause = (PauseMenu)level.getScreen("Pause"); pause.setLevel(next); if (current != level.getSong()) { MediaPlayer.Stop(); MediaPlayer.Play(level.getSong()); if (d.continues()) { game.getLevel(next - 2).setLooped(false); prevLevel.setLooped(false); } else { level.setLooped(false); prevLevel.setLooped(false); } level.setLooped(true); } game.setLevel(level); deathManager = new DeathManager(this); setDeathManager(deathManager); collisionManager.getLevel().setActive(false); level.setInputManager(this); collisionManager.setLevel(level); level.setActive(true); if (d.continues()) { player.setLocation(level.getPlayerOrigin()); } else { player.setLocation(level.getPlayerReentryPoint()); } playerManager.getKeyBox().update(this); } else if (game.getLevelIndex() == 0) { Numberpad num = (Numberpad)level.getScreen("Numberpad"); if (!num.isSolved()) { if (gameState == GameState.Normal) { if (showPuzzle) { gameState = GameState.Puzzle; level.setActive(false); } } } else { d.setUnlocked(true); } } } else if (gCollision != null && gCollision is Pit) { Pit p = (Pit)gCollision; p.update(this); if (p is Laser) { Laser laser = (Laser)p; if (laser.isActivated()) { p.playEffect(); } } else { p.playEffect(); } if (p is PlayerLimitationField) { PlayerLimitationField plf = (PlayerLimitationField)p; plf.update(this); plf.playEffect(); } } if (lastKeyState.IsKeyDown(Keys.M) && currentKeyState.IsKeyUp(Keys.M)) { if (gameState == GameState.Normal) { gameState = GameState.PauseMenu; level.setActive(false); } else { gameState = GameState.Normal; level.setActive(true); } } else if (lastKeyState.IsKeyDown(Keys.E) && currentKeyState.IsKeyUp(Keys.E)) { if (mindRead.validate()) { playerManager.depleteMana(mindRead.getManaCost()); foreach (Npc n in level.getNpcs()) { if (player.getDistance(n) <= 200) { NpcDefinition def = n.getDefinition(); if (def.getHints().Length > 0) { def.update(true); } } } } } if (playerManager.getManaLimit()) { mindRead.activate(level); SlowTime slowmo = (SlowTime)playerManager.getPowers()[0]; if (lastKeyState.IsKeyDown(Keys.A) && currentKeyState.IsKeyUp(Keys.A)) { if (slowmo.validate()) { playerManager.depleteMana(slowmo.getManaCost()); } } slowmo.activate(level); Dash dash = (Dash)playerManager.getPowers()[1]; if (lastKeyState.IsKeyDown(Keys.W) && currentKeyState.IsKeyUp(Keys.W)) { if (dash.validate()) { playerManager.depleteMana(dash.getManaCost()); } } dash.activate(level); Confuse confuse = (Confuse)playerManager.getPowers()[2]; if (lastKeyState.IsKeyDown(Keys.S) && currentKeyState.IsKeyUp(Keys.S)) { if (confuse.validate()) { playerManager.depleteMana(confuse.getManaCost()); } } confuse.activate(level); } Entity eCollision = collisionManager.getEntityCollision(player); if (currentKeyState.IsKeyDown(Keys.Up)) { showPuzzle = true; player.setDirection(Direction.North); player.updateMovement(); player.setDestination(new Vector2(player.getLocation().X, player.getLocation().Y - velocity)); if (player.getDestination().Y >= 0 && collisionManager.isValid(player, false)) { player.deriveY(-velocity); } else { if (!(collisionManager.getObjectCollision(player, false) is Door)) { player.setDestination(player.getLocation()); } if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (lastKeyState.IsKeyDown(Keys.Up) && currentKeyState.IsKeyUp(Keys.Up)) { stagnant = true; } else if (currentKeyState.IsKeyDown(Keys.Down)) { showPuzzle = true; player.setDirection(Direction.South); player.updateMovement(); player.setDestination(new Vector2(player.getLocation().X, player.getLocation().Y + velocity)); if (player.getDestination().Y <= height - player.getTexture().Height&& collisionManager.isValid(player, false)) { player.deriveY(velocity); } else { if (!(collisionManager.getObjectCollision(player, false) is Door)) { player.setDestination(player.getLocation()); } if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (lastKeyState.IsKeyDown(Keys.Down) && currentKeyState.IsKeyUp(Keys.Down)) { stagnant = true; } else if (currentKeyState.IsKeyDown(Keys.Left)) { showPuzzle = true; player.setDirection(Direction.West); player.updateMovement(); player.setDestination(new Vector2(player.getLocation().X - velocity, player.getLocation().Y)); if (player.getDestination().X >= 0 && collisionManager.isValid(player, false)) { player.deriveX(-velocity); } else { if (!(collisionManager.getObjectCollision(player, false) is Door)) { player.setDestination(player.getLocation()); } if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (lastKeyState.IsKeyDown(Keys.Left) && currentKeyState.IsKeyUp(Keys.Left)) { stagnant = true; } else if (currentKeyState.IsKeyDown(Keys.Right)) { showPuzzle = true; player.setDirection(Direction.East); player.updateMovement(); player.setDestination(new Vector2(player.getLocation().X + velocity, player.getLocation().Y)); if (player.getDestination().X <= width - 64 && collisionManager.isValid(player, false)) { player.deriveX(velocity); } else { if (!(collisionManager.getObjectCollision(player, false) is Door)) { player.setDestination(player.getLocation()); } if (eCollision != null) { eCollision.setDestination(eCollision.getLocation()); } } } else if (lastKeyState.IsKeyDown(Keys.Right) && currentKeyState.IsKeyUp(Keys.Right)) { stagnant = true; } else { player.setDestination(player.getLocation()); } if (currentKeyState.IsKeyDown(Keys.Space) && playerManager.getManaLimit()) { double ms = time.TotalGameTime.TotalMilliseconds; if ((player.getLastFired() == -1 || ms - player.getLastFired() >= player.getProjectile().getCooldown()) && playerManager.getMana() >= 5) { level.addProjectile(player.createProjectile(ms)); playerManager.depleteMana(5); } } if (lastKeyState.IsKeyDown(Keys.Q) && currentKeyState.IsKeyUp(Keys.Q)) { gameState = GameState.TelekinesisSelect; level.setMode(1); } }