Esempio n. 1
0
        private void TryUpdateBehavior(int midX, int midY)
        {
            // If there is no character in sight, check for a new one:
            if (this.charBeingChased is Character == false)
            {
                int objectId = this.WatchForCharacter(midX, midY);

                if (objectId > 0)
                {
                    this.charBeingChased = (Character)this.actor.room.objects[(byte)LoadOrder.Character][objectId];
                }
            }

            // Prepare Values
            int frame = Systems.timer.Frame;

            // Get distance from Character, if applicable.
            int destX    = this.charBeingChased is Character ? this.charBeingChased.posX + this.charBeingChased.bounds.MidX : midX;
            int destY    = this.charBeingChased is Character ? this.charBeingChased.posY + this.charBeingChased.bounds.MidY : midY;
            int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt;

            // Assign New Chase Action (When Action Time Expires).

            // Flee
            if (this.flee > 0 && distance < this.flee)
            {
                this.quickAct = ChaseAction.Flee;
            }

            // Chase
            else if (this.chase > 0 && distance <= this.chase)
            {
                this.quickAct = ChaseAction.Chase;
            }

            // Return to Start Position
            else if (this.returns)
            {
                if (this.quickAct == ChaseAction.Return || (this.quickAct == ChaseAction.Wait && this.waitEndFrame < frame))
                {
                    this.quickAct = ChaseAction.Return;
                }
                else
                {
                    this.quickAct     = ChaseAction.Wait;
                    this.waitEndFrame = this.waitEndFrame < frame ? frame + this.retDelay : this.waitEndFrame;
                }
            }

            // Standard: Do Nothing
            else
            {
                this.quickAct = ChaseAction.Standard;
            }
        }
Esempio n. 2
0
        public override void RunTick()
        {
            base.RunTick();

            // Get Center Bounds
            int midX = this.posX + this.bounds.MidX;
            int midY = this.posY + this.bounds.MidY;

            // Only change behaviors every 16 frames.
            if (Systems.timer.frame16Modulus == 15)
            {
                this.WatchForCharacter(midX, midY);
            }

            // Check for any attack to make this round.
            if (this.charWatched is Character && this.attack.AttackThisFrame())
            {
                // Get distance from Character, if applicable.
                int destX    = this.charWatched is Character ? this.charWatched.posX + this.charWatched.bounds.MidX - 10 : midX;
                int destY    = this.charWatched is Character ? this.charWatched.posY + this.charWatched.bounds.MidY - 10 : midY;
                int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt;

                if (distance < ViewDistance)
                {
                    FInt rotation = FPRadians.GetRadiansBetweenCoords(midX, midY, destX, destY);
                    this.rotation = (float)rotation.ToDouble();

                    if (this.attCount != 2)
                    {
                        this.ShootBolt(rotation, midX, midY);
                    }

                    if (this.attCount > 1)
                    {
                        this.ShootBolt(rotation + attSpread, midX, midY);
                        this.ShootBolt(rotation - attSpread, midX, midY);
                    }

                    this.room.PlaySound(Systems.sounds.bolt, 0.6f, this.posX + 16, this.posY + 16);
                }
            }
        }
Esempio n. 3
0
        public override void RunTick()
        {
            // Update the rotation to move toward.
            int midX = this.actor.posX + this.actor.bounds.MidX;
            int midY = this.actor.posY + this.actor.bounds.MidY;

            // Only change behaviors every 16 frames.
            if (Systems.timer.frame16Modulus == 7)
            {
                this.TryUpdateBehavior(midX, midY);
            }

            // Get distance from Character, if applicable.
            int destX    = this.charBeingChased is Character ? this.charBeingChased.posX + this.charBeingChased.bounds.MidX : midX;
            int destY    = this.charBeingChased is Character ? this.charBeingChased.posY + this.charBeingChased.bounds.MidY : midY;
            int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt;

            // Stall
            if (this.stall > 0 && distance < this.stall)
            {
                if (this.physics.velocity.X != 0)
                {
                    this.physics.velocity.X *= FInt.Create(0.85);
                }
                if (this.physics.velocity.Y != 0)
                {
                    this.physics.velocity.Y *= FInt.Create(0.85);
                }
                return;
            }

            // Stop Chasing
            if (this.quickAct == ChaseAction.Standard || this.quickAct == ChaseAction.Wait)
            {
                if (this.physics.velocity.X != 0)
                {
                    this.physics.velocity.X *= FInt.Create(0.9);
                }
                if (this.physics.velocity.Y != 0)
                {
                    this.physics.velocity.Y *= FInt.Create(0.9);
                }
                return;
            }

            // Return to Starting Position
            if (this.quickAct == ChaseAction.Return)
            {
                destX = (int)this.startPos.X;
                destY = (int)this.startPos.Y;
            }

            FInt newVelX = FInt.Create(0);
            FInt newVelY = FInt.Create(0);

            // Chase or Flee
            if (this.axis == (byte)FlightChaseAxis.Both)
            {
                if (Math.Abs(midX - destX) < 2 && Math.Abs(midY - destY) <= 2)
                {
                    this.physics.velocity.X *= FInt.Create(0.90);
                    this.physics.velocity.Y *= FInt.Create(0.90);
                    return;
                }

                FInt rotRadian = FPRadians.GetRadiansBetweenCoords(midX, midY, destX, destY);
                newVelX = FPRadians.GetXFromRotation(rotRadian, this.speed);
                newVelY = FPRadians.GetYFromRotation(rotRadian, this.speed);
            }

            // Vertical Movement Only
            else if (this.axis == (byte)FlightChaseAxis.Vertical)
            {
                if (Math.Abs(midY - destY) <= 2)
                {
                    this.physics.velocity.Y *= FInt.Create(0.90); return;
                }
                FInt rotRadian = FPRadians.GetRadiansBetweenCoords(0, midY, 0, destY);
                newVelY = FPRadians.GetYFromRotation(rotRadian, this.speed);
            }

            // Horizontal Movement Only
            else
            {
                if (Math.Abs(midX - destX) <= 2)
                {
                    this.physics.velocity.X *= FInt.Create(0.90); return;
                }
                FInt rotRadian = FPRadians.GetRadiansBetweenCoords(midX, 0, destX, 0);
                newVelX = FPRadians.GetXFromRotation(rotRadian, this.speed);
            }

            // Flee
            if (this.quickAct == ChaseAction.Flee)
            {
                newVelX = newVelX.Inverse;
                newVelY = newVelY.Inverse;
            }

            FInt accel = this.speed * FInt.Create(0.02);

            if (this.physics.velocity.X > newVelX)
            {
                this.physics.velocity.X -= accel;
            }
            else if (this.physics.velocity.X < newVelX)
            {
                this.physics.velocity.X += accel;
            }

            if (this.physics.velocity.Y > newVelY)
            {
                this.physics.velocity.Y -= accel;
            }
            else if (this.physics.velocity.Y < newVelY)
            {
                this.physics.velocity.Y += accel;
            }
        }