コード例 #1
0
        public override void Update(GameTime gameTime, GameWindow gameWindow, Platforms platforms, ref int shift, Player Player, ContentManager Content)
        {
            UpdateAnimation(gameTime, Content);

            if (Where == WhereIGo.movingLeft)
            {
                if (this.canMoveLeft(gameWindow, platforms, shift))
                {
                    this.position.X -= velocity.X;
                }
                else
                {
                    Where = WhereIGo.movingRight;
                }
            }
            if (Where == WhereIGo.movingRight)
            {
                if (this.canMoveRight(gameWindow, platforms, shift))
                {
                    this.position.X += velocity.X;
                }
                else
                {
                    Where = WhereIGo.movingLeft;
                }
            }
            if (this.stateOfMoving == StateOfMoving.attacking)
            {
                return;
            }
            if (this.canMoveDown(gameWindow, platforms, shift))
            {
                this.position.Y   += velocity.Y;
                this.stateOfMoving = StateOfMoving.falling;
            }
            else
            {
                this.stateOfMoving = StateOfMoving.notfalling;
            }
        }
コード例 #2
0
        public override void Update(GameTime gameTime, GameWindow gameWindow, Platforms platforms, ref int shift, Player Player, ContentManager Content)
        {
            this.UpdateTime(gameTime);
            Rectangle EnemyPlusHisRange = new Rectangle((int)(this.position.X) - Range, (int)(this.position.Y), (int)(this.size.X) + 2 * (int)(Range), (int)(this.size.Y));

            if (!(Math.Abs(Player.position.X - this.position.X) < Range) && Where == WhereIGo.movingLeft)
            {
                if (!(Math.Abs(position.X - Player.position.X) < Epson))
                {
                    if (this.canMoveLeft(gameWindow, platforms, shift))
                    {
                        position.X -= velocity.X;
                    }
                    if (position.X < Player.position.X)
                    {
                        Where = WhereIGo.movingRight;
                    }
                }
            }
            else if (!(Math.Abs(Player.position.X - this.position.X) < Range) && Where == WhereIGo.movingRight)
            {
                if (!(Math.Abs(position.X - Player.position.X) < Epson))
                {
                    if (this.canMoveRight(gameWindow, platforms, shift))
                    {
                        position.X += velocity.X;
                    }
                    if (position.X > Player.position.X)
                    {
                        Where = WhereIGo.movingLeft;
                    }
                }
            }

            if ((Math.Abs(Player.position.Y - this.position.Y) < Range))
            {
                return;
            }
            else if (WhereVertical == WhereIGo.movingDown)
            {
                if (Math.Abs(position.Y - Player.position.Y) < Epson)
                {
                    return;
                }
                if (this.canMoveDown(gameWindow, platforms, shift))
                {
                    position.Y += velocity.Y;
                }
                if (position.Y > Player.position.Y)
                {
                    WhereVertical = WhereIGo.movingUp;
                }
                return;
            }
            else if (WhereVertical == WhereIGo.movingUp)
            {
                if (Math.Abs(position.Y - Player.position.Y) < Epson)
                {
                    return;
                }
                if (this.canMoveUp(gameWindow, platforms, shift))
                {
                    position.Y -= velocity.Y;
                }
                if (position.Y < Player.position.Y)
                {
                    WhereVertical = WhereIGo.movingDown;
                }
                return;
            }
        }