/// <summary> /// Restarts the level to its standard configurations /// </summary> public void RestartLevel() { Avatar.Instance().Revive(); current.Reset(); Avatar.Instance().kinetics.position = current.firstPosition; }
/// <summary> /// Draws the Current level to the screen, including radar. /// </summary> /// <param name="batch">Microsoft Sprite Batch</param> public void Draw(SpriteBatch batch) { batch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, TreasureHunter.Cam.View()); current.Draw(batch); batch.End(); TreasureHunter.graphics.GraphicsDevice.SetRenderTarget(null); TreasureHunter.graphics.GraphicsDevice.SetRenderTarget(renderTarget2); TreasureHunter.graphics.GraphicsDevice.Clear(Color.Transparent); radar.CurrentTechnique = radar.Techniques["Technique1"]; TreasureHunter.graphics.GraphicsDevice.Textures[0] = blankTarget; TreasureHunter.graphics.GraphicsDevice.Textures[1] = current.radar.map; Vector2 temp = Vector2.Zero; temp.X = Avatar.Instance().kinetics.boundingBox.X + Avatar.Instance().kinetics.boundingBox.Width / 2; temp.Y = Avatar.Instance().kinetics.boundingBox.Y + Avatar.Instance().kinetics.boundingBox.Height / 2; temp = temp / new Vector2(current.ScaledWidth(), current.ScaledHeight()); Vector2 temp2 = Vector2.Zero; temp2.X = current.treasure.kinetics.position.X; temp2.Y = current.treasure.kinetics.position.Y; temp2 = temp2 / new Vector2(current.ScaledWidth(), current.ScaledHeight()); radar.Parameters["AvatarPosition"].SetValue(temp); radar.Parameters["TreasurePosition"].SetValue(temp2); float tempradiate = (float)Math.Sin(radiate); switch (current.treasure.color) { case 0: radar.Parameters["GemColor"].SetValue(new Vector4(0, 0, 1, tempradiate)); break; case 1: radar.Parameters["GemColor"].SetValue(new Vector4(0, 1, 0, tempradiate)); break; case 2: radar.Parameters["GemColor"].SetValue(new Vector4(1, .657f, 0, tempradiate)); break; } batch.Begin(SpriteSortMode.Immediate, null, null, null, null, radar); batch.Draw(blankTarget, Vector2.Zero, Color.White); batch.End(); radiate += .1f; TreasureHunter.graphics.GraphicsDevice.SetRenderTarget(null); batch.Begin(); batch.Draw(renderTarget, Vector2.Zero, Color.White); batch.End(); batch.Begin(); batch.Draw(renderTarget2, new Rectangle(TreasureHunter.graphics.PreferredBackBufferWidth - 200, TreasureHunter.graphics.PreferredBackBufferHeight - 200, 200, 200), Color.White); batch.End(); }
/// <summary> /// Algorithm that chooses the next Maze Block that is nearest to the player. /// </summary> /// <returns>Maze Block that is nearest to the player</returns> MazeBlock ChooseClosestToPlayer() { MazeBlock temp = null; float distance = 10000; if (currentBlock.Up != null) { if (currentBlock.Up.Walkable) { float tempDistance = Vector2.Distance(currentBlock.Up.kinetics.position, Avatar.Instance().kinetics.position); if (tempDistance < distance) { distance = tempDistance; temp = currentBlock.Up; } } } if (currentBlock.Down != null) { if (currentBlock.Down.Walkable) { float tempDistance = Vector2.Distance(currentBlock.Down.kinetics.position, Avatar.Instance().kinetics.position); if (tempDistance < distance) { distance = tempDistance; temp = currentBlock.Down; } } } if (currentBlock.Left != null) { if (currentBlock.Left.Walkable) { float tempDistance = Vector2.Distance(currentBlock.Left.kinetics.position, Avatar.Instance().kinetics.position); if (tempDistance < distance) { distance = tempDistance; temp = currentBlock.Left; } } } if (currentBlock.Right != null) { if (currentBlock.Right.Walkable) { float tempDistance = Vector2.Distance(currentBlock.Right.kinetics.position, Avatar.Instance().kinetics.position); if (tempDistance < distance) { distance = tempDistance; temp = currentBlock.Right; } } } return(temp); }
/// <summary> /// Method for resolving collisions with given Item /// </summary> /// <param name="Item">Item that has collided with this</param> public override void CollisionResolution(GameObject Item) { if (Item.GetType() == typeof(MazeBlock)) { return; } if (Item.GetType() == typeof(Avatar)) { if (!Walkable) { float margin = (float)Math.Ceiling(Avatar.Instance().speed) + 1; //Down if (Item.kinetics.boundingBox.Bottom >= kinetics.boundingBox.Top && Item.kinetics.boundingBox.Bottom <= kinetics.boundingBox.Top + margin) { if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed) { MazeBlock target = Down; if (target.Walkable == true) { Item.kinetics.position.X = target.kinetics.position.X + 10; Item.kinetics.position.Y = target.kinetics.position.Y - 25; Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y; Avatar.Instance().Teleported(); } } else { float offset = Item.kinetics.boundingBox.Top - Item.kinetics.position.Y; Item.kinetics.position.Y = kinetics.boundingBox.Top - Item.kinetics.boundingBox.Height - Item.kinetics.BoundingBoxOffset.Y; Item.kinetics.boundingBox.Y = (int)(Item.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y); } return; } //Left if (Item.kinetics.boundingBox.Right >= kinetics.boundingBox.Left && Item.kinetics.boundingBox.Right <= kinetics.boundingBox.Left + margin) { if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed) { MazeBlock target = Right; if (target.Walkable == true) { Item.kinetics.position.X = target.kinetics.position.X + 10; Item.kinetics.position.Y = target.kinetics.position.Y - 25; Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y; Avatar.Instance().Teleported(); } } else { Item.kinetics.position.X = kinetics.boundingBox.Left - Item.kinetics.boundingBox.Width - Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.X = (int)(Item.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X); return; } } if (Item.kinetics.boundingBox.Left <= kinetics.boundingBox.Right && Item.kinetics.boundingBox.Left >= kinetics.boundingBox.Right - margin) { if (Item.kinetics.boundingBox.Top <= kinetics.boundingBox.Bottom && Item.kinetics.boundingBox.Top >= kinetics.boundingBox.Bottom - margin) { if (Right != null) { if (!Right.Walkable) { if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed) { MazeBlock target = Up; if (target.Walkable == true) { Item.kinetics.position.X = target.kinetics.position.X + 10; Item.kinetics.position.Y = target.kinetics.position.Y - 25; Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y; Avatar.Instance().Teleported(); } } else { float offset = Item.kinetics.boundingBox.Top - Item.kinetics.position.Y; Item.kinetics.position.Y = kinetics.boundingBox.Bottom - Item.kinetics.BoundingBoxOffset.Y; Item.kinetics.boundingBox.Y = (int)(Item.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y); Item.kinetics.velocity.Y = 0; return; } } } } if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed) { MazeBlock target = Left; if (target.Walkable == true) { Item.kinetics.position.X = target.kinetics.position.X + 10; Item.kinetics.position.Y = target.kinetics.position.Y - 25; Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y; Avatar.Instance().Teleported(); } } else { Item.kinetics.position.X = kinetics.boundingBox.Right - Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.X = (int)(Item.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X); } return; } if (Item.kinetics.boundingBox.Top <= kinetics.boundingBox.Bottom && Item.kinetics.boundingBox.Top >= kinetics.boundingBox.Bottom - margin) { if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed) { MazeBlock target = Up; if (target.Walkable == true) { Item.kinetics.position.X = target.kinetics.position.X + 10; Item.kinetics.position.Y = target.kinetics.position.Y - 25; Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X; Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y; Avatar.Instance().Teleported(); } } else { float offset = Item.kinetics.boundingBox.Top - Item.kinetics.position.Y; Item.kinetics.position.Y = kinetics.boundingBox.Bottom - Item.kinetics.BoundingBoxOffset.Y; Item.kinetics.boundingBox.Y = (int)(Item.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y); Item.kinetics.velocity.Y = 0; } return; } } else { if (!discovered) { LevelManager.Instance().Discovered(); color = Color.White; } discovered = true; } } }