using Sprint3_actual.StateFiles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Sprint3_actual.ActiveItems { class SwordBeam : IActiveItem { private ILink link; private Game1 game; private Texture2D texture; public int ItemX; public int ItemY; public Rectangle itemRectangle { get; set; } private int SpriteHeight; private int SpriteWidth; private bool hasCollided; private bool Removed; private enum Direction { Up, Down, Left, Right } private Direction direction; private AItemSprites ItemSprite; public SwordBeam(Link link, Game1 game) { this.link = link; texture = game.PlayerTexture; Removed = true; hasCollided = false; this.game = game; } public void ActiveItemDown() { if (Removed) { Vector2 pos = link.Position(); ItemX = (int)pos.X + 16; ItemY = (int)pos.Y; direction = Direction.Down; SpriteHeight = 48; SpriteWidth = 21; Removed = false; hasCollided = false; ItemSprite = new DownSwBeamSprite(this, texture); game.currentRoom.LinkItems.Add(this); } } public void ActiveItemLeft() { if (Removed) { Vector2 pos = link.Position(); ItemX = (int)pos.X + 6; ItemY = (int)pos.Y + 20; direction = Direction.Left; SpriteHeight = 21; SpriteWidth = 48; Removed = false; hasCollided = false; ItemSprite = new LeftSwBeamSprite(this, texture); game.currentRoom.LinkItems.Add(this); } } public void ActiveItemRight() { if (Removed) { Vector2 pos = link.Position(); ItemX = (int)pos.X; ItemY = (int)pos.Y + 20; direction = Direction.Right; SpriteHeight = 21; SpriteWidth = 48; Removed = false; hasCollided = false; ItemSprite = new RightSwBeamSprite(this, texture); game.currentRoom.LinkItems.Add(this); } } public void ActiveItemUp() { if (Removed) { Vector2 pos = link.Position(); ItemX = (int)pos.X + 14; ItemY = (int)pos.Y; direction = Direction.Up; SpriteHeight = 48; SpriteWidth = 21; Removed = false; hasCollided = false; ItemSprite = new UpSwBeamSprite(this, texture); game.currentRoom.LinkItems.Add(this); } } public Rectangle PositionRectangle() { return itemRectangle; } public float Collide() { hasCollided = true; return 0.5f; } public bool HasCollided() { return hasCollided; } public void Draw() { if (!Removed) ItemSprite.draw(); } public bool IsRemoved() { return Removed; } public void Update() { if (!Removed) { if (!hasCollided) { if (direction == Direction.Up) { ItemY -= (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * 0.5); } else if (direction == Direction.Down) { ItemY += (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * 0.5); } else if (direction == Direction.Left) { ItemX -= (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * 0.5); } else { ItemX += (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * 0.5); } itemRectangle = new Rectangle(ItemX, ItemY, SpriteWidth, SpriteHeight); } } if (hasCollided) { Removed = true; hasCollided = false; itemRectangle = Rectangle.Empty; } } public void Remove() { Removed = true; } public void ItemSound() { //NO-OP: Sound Engine is already loaded in the states, probably needs changed but it is what it is for now } } }