using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Sprint3_actual.StateFiles; using System; using System.Collections.Generic; using System.Text; using Sprint3_actual.SoundManagement; namespace Sprint3_actual.ActiveItems { public class Boomerang : IActiveItem { private ILink link; private Game1 game; private Texture2D texture; private Vector2 ItemPos; private Vector2 ItemSpeed; private int RemoveCounter; public Rectangle itemRectangle { get; set; } private int SpriteHeight; private int SpriteWidth; private bool Removed, Collided; private AItemSprites ItemSprite; private const int shift4 = 4; private const int shift28 = 28; private const int shift36 = 36; public Boomerang(ILink link, Game1 game) { this.link = link; this.game = game; texture = game.PlayerTexture; Removed = true; SpriteHeight = 24; SpriteWidth = 24; } public void ActiveItemDown() { if (Removed) { ItemPos = link.Position(); ItemPos.X += shift4; ItemPos.Y += shift36; ItemSpeed = new Vector2(0, 5); Removed = false; Collided = false; ItemSprite = new BoomerangSprite(this, texture); RemoveCounter = 0; game.currentRoom.LinkItems.Add(this); } } public void ActiveItemLeft() { if (Removed) { ItemPos = link.Position(); ItemPos.X -= shift28; ItemPos.Y += shift4; ItemSpeed = new Vector2(-5, 0); Removed = false; Collided = false; ItemSprite = new BoomerangSprite(this, texture); RemoveCounter = 0; game.currentRoom.LinkItems.Add(this); } } public void ActiveItemRight() { if (Removed) { ItemPos = link.Position(); ItemPos.X += shift36; ItemPos.Y += shift4; ItemSpeed = new Vector2(5, 0); Removed = false; Collided = false; ItemSprite = new BoomerangSprite(this, texture); RemoveCounter = 0; game.currentRoom.LinkItems.Add(this); } } public void ActiveItemUp() { if (Removed) { ItemPos = link.Position(); ItemPos.X += shift4; ItemPos.Y -= shift28; ItemSpeed = new Vector2(0, -5); Removed = false; Collided = false; ItemSprite = new BoomerangSprite(this, texture); RemoveCounter = 0; game.currentRoom.LinkItems.Add(this); } } public float Collide() { if (!Collided) { ItemSpeed *= -1; Collided = true; } return 0.5f; } public void Draw() { if (!Removed) ItemSprite.draw(); } public bool IsRemoved() { return Removed; } public Rectangle PositionRectangle() { return itemRectangle; } public void Update() { if (!Removed) { RemoveCounter++; ItemSprite.update(GlobalVars.gameTime); Vector2 TowardLink = link.Position() + new Vector2(4,4) - ItemPos; if (TowardLink.Length() < 8) { Removed = true; itemRectangle = Rectangle.Empty; } if (TowardLink.Length() > 0) { TowardLink.Normalize(); TowardLink *= 5; } if (!Collided) { ItemPos += ItemSpeed; } else { ItemPos += TowardLink; } if (RemoveCounter > 30) { Collided = true; } itemRectangle = new Rectangle((int)ItemPos.X, (int)ItemPos.Y, SpriteWidth, SpriteHeight); } } public void Remove() { Removed = true; } public void ItemSound() { SoundEngine.Instance.playBoomerang(); } } }