/// <summary> /// Converts the given degrees to a <see cref="Vector2"/>.<br></br> /// </summary> /// <param name="focus">The point the entity needs to move to.</param> /// <param name="pos">The current position.</param> /// <param name="speed">The speed it should move in.</param> /// <returns>The <see cref="Vector2"/> which the unit has to move to, to reach the focus in given speed.</returns> public static Vector2 RadialMovement(Vector2 focus, Vector2 pos, float speed) { float dist = Globals.GetDistance(pos, focus); if (dist <= speed) { return(focus - pos); } else { return((focus - pos) * speed / dist); } }
public override void ChangePosition() { //if you are not in range of the player, move towards them. if (Globals.GetDistance(Position, Level.Player.Position) >= 201) { Speed = 2; Position += Globals.RadialMovement(Level.Player.Position, Position, Speed); } //if the player closes in, move away from them else if (Globals.GetDistance(Position, Level.Player.Position) < 199) { Position -= Globals.RadialMovement(Level.Player.Position, Position, Speed); if (HitWall()) { Speed = 0; } } }
public Flybuddy(Vector2?position = null, /*Rectangle? sourceRectangle = null,*/ float rotation = 0f, SpriteEffects effects = SpriteEffects.None) : base(angle: 0f, texture: Globals.Content.Load <Texture2D>("Sprites/Enemies/Flysheet"), position: position, sourceRectangle: new Rectangle(0, 0, 256, 256) /*sourceRectangle*/, rotation: rotation, effects: effects) { // Calculate its initial angle towards the player. angle = Globals.Vector2ToDegrees(Position - Level.Player.Position); Speed = 250.0f; DistanceToPlayer = Globals.GetDistance(Position, Level.Player.Position); timer = new McTimer(1000); OwnerID = 1; HitValue = 1; isDestroyed = false; Scale = new Vector2(.1f, .1f); // Initialize _shadowSprite. _shadowSprite = new Sprite(texture: _shadow, position: position, origin: new Vector2(0.5f, 1f), scale: Scale, rotation: rotation, layerDepth: 0.9999999f, effects: effects); // Set the animation. CurrentAnimation = new Animation(animationSheet: Globals.Content.Load <Texture2D>("Sprites/Enemies/FLysheet"), frameDimensions: new Vector2(256), frameDuration: TimeSpan.FromSeconds(1f / 60f)); }
public override void Update() { if (!SoundHasPlayed) { Globals.sounds.PlaySoundEffect("Sound6"); SoundHasPlayed = true; } // Unlocking / opening doors. // Top. if ((Level.CurrentRoom.Doors[(byte)Directions.Up] != null && (Position - Level.CurrentRoom.Doors[(byte)Directions.Up].Position).Length() <= (BlastRadius * Tile.Size.X))) { // If the door is closed. if (Level.CurrentRoom.Doors[(byte)Directions.Up].State == DoorState.Closed) { // Open the door. Level.CurrentRoom.Doors[(byte)Directions.Up].Open(); } // Else if the door is hidden and locked. else if (Level.CurrentRoom.Doors[(byte)Directions.Up].Kind == DoorKind.Hidden && Level.CurrentRoom.Doors[(byte)Directions.Up].State == DoorState.Locked) { // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Up].Unlock(true); } } // Right. if ((Level.CurrentRoom.Doors[(byte)Directions.Right] != null && (Position - Level.CurrentRoom.Doors[(byte)Directions.Right].Position).Length() <= (BlastRadius * Tile.Size.X))) { // If the door is closed. if (Level.CurrentRoom.Doors[(byte)Directions.Right].State == DoorState.Closed) { // Open the door. Level.CurrentRoom.Doors[(byte)Directions.Right].Open(); } // Else if the door is hidden and locked. else if (Level.CurrentRoom.Doors[(byte)Directions.Right].Kind == DoorKind.Hidden && Level.CurrentRoom.Doors[(byte)Directions.Right].State == DoorState.Locked) { // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Right].Unlock(true); } } // Bottom. if ((Level.CurrentRoom.Doors[(byte)Directions.Down] != null && (Position - Level.CurrentRoom.Doors[(byte)Directions.Down].Position).Length() <= (BlastRadius * Tile.Size.X))) { // If the door is closed. if (Level.CurrentRoom.Doors[(byte)Directions.Down].State == DoorState.Closed) { // Open the door. Level.CurrentRoom.Doors[(byte)Directions.Down].Open(); } // Else if the door is hidden and locked. else if (Level.CurrentRoom.Doors[(byte)Directions.Down].Kind == DoorKind.Hidden && Level.CurrentRoom.Doors[(byte)Directions.Down].State == DoorState.Locked) { // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Down].Unlock(true); } } // Left. if ((Level.CurrentRoom.Doors[(byte)Directions.Left] != null && (Position - Level.CurrentRoom.Doors[(byte)Directions.Left].Position).Length() <= (BlastRadius * Tile.Size.X))) { // If the door is closed. if (Level.CurrentRoom.Doors[(byte)Directions.Left].State == DoorState.Closed) { // Open the door. Level.CurrentRoom.Doors[(byte)Directions.Left].Open(); } // Else if the door is hidden and locked. else if (Level.CurrentRoom.Doors[(byte)Directions.Left].Kind == DoorKind.Hidden && Level.CurrentRoom.Doors[(byte)Directions.Left].State == DoorState.Locked) { // Unlock the door. Level.CurrentRoom.Doors[(byte)Directions.Left].Unlock(true); } } timer.UpdateTimer(); // Deal Damage to any entity, that is not the player //if (Collides(Level.CurrentRoom.Entities) && (OwnerID == 1 || OwnerID == 0)) //{ //bool isColliding = false;//NEW for (int i = 0; i < Level.CurrentRoom.Entities.Count; i++) { //if (Collides(Level.CurrentRoom.Entities[i])//NEW if (Globals.GetDistance(this.Position, Level.CurrentRoom.Entities[i].Position) <= (BlastRadius * Tile.Size.X) && OwnerID == 0 && (Level.CurrentRoom.Entities[i].GetType().IsSubclassOf(typeof(Environment)) || Level.CurrentRoom.Entities[i].GetType().IsSubclassOf(typeof(Enemy)) || Level.CurrentRoom.Entities[i].GetType().Name == "Campfire") && Level.CurrentRoom.Entities[i].damageDealt == false) { //enemies[i].GetHit(HitValue); Level.CurrentRoom.Entities[i].damageDealt = false; Level.CurrentRoom.Entities[i].GetHit(HitValue); Level.CurrentRoom.Entities[i].damageDealt = true; /*Level.CurrentRoom.Remove(this);*/ //isColliding = true; } } //NEW //if (isColliding) //{ // Level.CurrentRoom.Remove(this); //} //} // Deal damage to the player //if (Collides(Level.Player)) if (Globals.GetDistance(this.Position, Level.Player.Position) <= (BlastRadius * Tile.Size.X)) { Level.Player.GetHit(HitValue); } if (timer.Test()) { Level.CurrentRoom.Remove(this); } }