Ejemplo n.º 1
0
        public override void Update()
        {
            Room = Room.Engine.CurrentRoom;
            if (!Room.LightList.Contains(Light))
            {
                Room.LightList.Add(Light);
            }
            Light.Position = Position;
            //AI CODE HERE
            PlayerObject Player = (PlayerObject)Room.FindObject("obj_player");

            if (IsAggro)
            {
                if (Player != null)
                {
                    float TargetX = Player.Position.X + PlatformerMath.RandNumGen.Next(32);
                    float TargetY = Player.Position.Y + PlatformerMath.RandNumGen.Next(32);
                    if (Position.X > TargetX)
                    {
                        Velocity.X = -(MaxVelocity.X);
                    }
                    else
                    {
                        Velocity.X = MaxVelocity.X;
                    }
                    if (Position.Y > TargetY)
                    {
                        Velocity.Y = -(MaxVelocity.Y);
                    }
                    else
                    {
                        Velocity.Y = MaxVelocity.Y;
                    }
                    if (Room.FindCollision(new Rectangle((Position + Sprite.Offset).ToPoint(), Sprite.Size.ToPoint()), "obj_player") != null)
                    {
                        Player.Damage(2);
                    }
                }
                else
                {
                    Velocity.X = 0;
                    Velocity.Y = 0;
                }

                if (Velocity.X > MinDirectionChangeSpeed)
                {
                    Sprite.SpriteEffect = SpriteEffects.None;
                }
                else if (Velocity.X < -MinDirectionChangeSpeed)
                {
                    Sprite.SpriteEffect = SpriteEffects.FlipHorizontally;
                }
                Sprite.Change(RunImage);
            }
            else
            {
                if (Player != null)
                {
                    Position = Player.Position + new Vector2(-2048, -2048);
                }
            }
            Position += Velocity;
        }
Ejemplo n.º 2
0
        public override void Update()
        {
            float moveSpeed = AirSpeed;

            if (Room.FindCollision(new Rectangle((Position + Sprite.Offset + new Vector2(0, 8)).ToPoint(), Sprite.Size.ToPoint()), "obj_block") != null)
            {
                Grounded  = true;
                moveSpeed = GroundSpeed;
                if (Math.Abs(Velocity.X) > GroundFriction)
                {
                    Velocity.X -= Math.Sign(Velocity.X) * GroundFriction;
                }
                else
                {
                    Velocity.X = 0;
                }
            }
            else
            {
                Grounded = false;
            }

            //AI CODE HERE
            PlayerObject Player = (PlayerObject)Room.FindObject("obj_player");

            if (Player != null)
            {
                float TargetX = Player.Position.X;
                float TargetY = Player.Position.Y;
                if (Position.X > TargetX)
                {
                    Velocity.X = -(MaxVelocity.X);
                }
                else
                {
                    Velocity.X = MaxVelocity.X;
                }
                if (Position.Y > TargetY)
                {
                    Velocity.Y = -(MaxVelocity.Y);
                }
                else
                {
                    Velocity.Y = MaxVelocity.Y;
                }
                if (MeleeCooldown == 0 && Room.FindCollision(new Rectangle((Position + Sprite.Offset).ToPoint(), Sprite.Size.ToPoint()), "obj_player") != null)
                {
                    MeleeCooldown = MaxMeleeCooldown;
                    Player.Damage(2);
                }
            }
            else
            {
                Velocity.X = 0;
            }



            if (Velocity.X > MinDirectionChangeSpeed)
            {
                Sprite.SpriteEffect = SpriteEffects.None;
            }
            else if (Velocity.X < -MinDirectionChangeSpeed)
            {
                Sprite.SpriteEffect = SpriteEffects.FlipHorizontally;
            }
            Sprite.Change(RunImage);


            if (Position.X > Room.Width)
            {
                Room.GameObjectList.Remove(this); //might not work
            }
            if (MeleeCooldown > 0)
            {
                MeleeCooldown--;
            }

            base.Update();
        }