コード例 #1
0
ファイル: ComputerAI.cs プロジェクト: Telos8840/TestGame
        public override void Update(GameTime gameTime)
        {
            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            switch (status)
            {
            case State.Waiting:
            {
                if (waypoints.Count > 0 && automove == true)
                {
                    //if (DistanceToDestination < 1f)
                    //{
                    //position = waypoints.Peek();
                    //Console.WriteLine(waypoints.Count);
                    //position = waypoints.Dequeue();

                    if (position.X < destination.X)
                    {
                        status = State.MoveRight;
                    }
                    else if (position.X == destination.X)
                    {
                    }
                    else
                    {
                        status = State.MoveLeft;
                    }

                    if (position.Y < destination.Y)
                    {
                        status = State.MoveDown;
                    }
                    else if (position.Y == destination.Y)
                    {
                    }
                    else
                    {
                        status = State.MoveUp;
                    }

                    if (position.X == destination.X && position.Y == destination.Y)
                    {
                        destination = waypoints.Dequeue();
                    }
                }
                else
                {
                    automove = false;
                }
                break;
            }

            case State.MoveRight:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X + 48) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        //status = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 2;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveDown:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y + 48) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        //status = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 0;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveUp:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y - 1) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        curFrame   = 0;
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 3;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveLeft:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X - 1) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        //status = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 1;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }
            }
            Console.WriteLine(status);



            if (position.X == 624 && position.Y == 144)
            {
                sceneManager.removeScene(sceneManager.getScene());
                position = new Vector2(32 * 3, 32 * 3);
            }

            //base.Update(gameTime);
        }
コード例 #2
0
        public override void Update(GameTime gametime)
        {
            var newState = Keyboard.GetState();

            timer += (float)gametime.ElapsedGameTime.TotalMilliseconds;
            //Console.WriteLine(status);
            switch (status)
            {
            case State.Waiting:
            {
                if (newState.IsKeyDown(Keys.Right))
                {
                    status = State.MoveRight;
                }
                else if (newState.IsKeyDown(Keys.Left))
                {
                    status = State.MoveLeft;
                }
                else if (newState.IsKeyDown(Keys.Up))
                {
                    status = State.MoveUp;
                }
                else if (newState.IsKeyDown(Keys.Down))
                {
                    status = State.MoveDown;
                }
                else if (automove)
                {
                    if (position.X < destination.X)
                    {
                        status = State.MoveRight;
                    }
                    else if (position.X == destination.X)
                    {
                    }
                    else
                    {
                        status = State.MoveLeft;
                    }

                    if (position.Y < destination.Y)
                    {
                        status = State.MoveDown;
                    }
                    else if (position.Y == destination.Y)
                    {
                    }
                    else
                    {
                        status = State.MoveUp;
                    }

                    if (position.X == destination.X && position.Y == destination.Y)
                    {
                        automove = false;
                    }
                }
                break;
            }

            case State.MoveRight:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X + 48) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 2;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveDown:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y + 48) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 0;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveUp:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y - 1) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        curFrame   = 0;
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 3;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveLeft:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X - 1) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 1;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }
            }
            oldState = newState;

            newMouseState = Mouse.GetState().LeftButton;

            if (Mouse.GetState().LeftButton == ButtonState.Released && oldMouseState == ButtonState.Pressed)
            {
                move(new Vector2((Mouse.GetState().X / 48) % 16, (Mouse.GetState().Y / 48) % 16));
            }

            oldMouseState = newMouseState;

            if (position.X == 624 && position.Y == 144)
            {
                sceneManager.removeScene(sceneManager.currentScene);
                position = new Vector2(32 * 3, 32 * 3);
            }
        }
コード例 #3
0
ファイル: Human.cs プロジェクト: Telos8840/TestGame
        public override void Update(GameTime gametime)
        {
            var newState = Keyboard.GetState();

            timer += (float)gametime.ElapsedGameTime.TotalMilliseconds;
            //Console.WriteLine(status);
            switch (status)
            {
            case State.Waiting:
            {
                if (newState.IsKeyDown(Keys.Right))
                {
                    status = State.MoveRight;
                }
                else if (newState.IsKeyDown(Keys.Left))
                {
                    status = State.MoveLeft;
                }
                else if (newState.IsKeyDown(Keys.Up))
                {
                    status = State.MoveUp;
                }
                else if (newState.IsKeyDown(Keys.Down))
                {
                    status = State.MoveDown;
                }

                break;
            }

            case State.MoveRight:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X + 48) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 2;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveDown:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y + 48) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 0;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveUp:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y - 1) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        curFrame   = 0;
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 3;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveLeft:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X - 1) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 1;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }
            }
            oldState = newState;


            if (position.X == 624 && position.Y == 144)
            {
                sceneManager.removeScene(sceneManager.getScene());
                position = new Vector2(32 * 3, 32 * 3);
            }

            //if (newState.IsKeyDown(Keys.A))
            //  poop.Draw(position);
        }
コード例 #4
0
ファイル: ComputerAI.cs プロジェクト: jafework/CS461
        public override void Update(GameTime gameTime)
        {
            //Console.WriteLine(status);
            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            switch (status)
            {
            case State.Waiting:
            {
                if (position.X == destination.X && position.Y != destination.Y)
                {
                    if (destination.Y > position.Y)
                    {
                        direction = 0;         //down
                        status    = State.MoveDown;
                        //Console.WriteLine("What is here!");
                        //position = destination;
                        walking    = true;
                        keepmoving = true;
                    }
                    else
                    {
                        direction = 3;         //up
                        status    = State.MoveUp;
                        //position = destination;
                        walking    = true;
                        keepmoving = true;
                    }
                }
                else if (position.Y == destination.Y && position.X != destination.X)
                {
                    if (destination.X > position.X)
                    {
                        direction = 2;         //right
                        status    = State.MoveRight;
                        //position = destination;
                        walking    = true;
                        keepmoving = true;
                    }
                    else
                    {
                        direction = 1;         //left
                        status    = State.MoveLeft;
                        //position = destination;
                        walking    = true;
                        keepmoving = true;
                    }
                }
                else if (position.X == destination.X && position.Y == destination.Y)
                {
                    if (waypoints.Count > 0)
                    {
                        destination = waypoints.Dequeue();
                    }
                    status = State.Waiting;
                }
                break;
            }

            case State.MoveRight:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X + 48) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 2;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveDown:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y + 48) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y += 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 0;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveUp:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y - 1) / 48) % 16), (int)((position.X / 48) % 16)] == 0 && keepmoving)
                    {
                        position.Y -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.Y % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        curFrame   = 0;
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 3;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

            case State.MoveLeft:
            {
                if (walking)
                {
                    if (movedata[(int)(((position.Y) / 48) % 16), (int)(((position.X - 1) / 48) % 16)] == 0 && keepmoving)
                    {
                        position.X -= 4;
                        keepmoving  = true;
                        if (timer > 100f)
                        {
                            curFrame++;
                            timer = 0f;
                        }
                        if (curFrame == 4)
                        {
                            curFrame = 0;
                        }
                        if ((int)position.X % 48 == 0)
                        {
                            keepmoving = false;
                            walking    = false;
                            status     = State.Waiting;
                        }
                    }
                    else
                    {
                        keepmoving = false;
                        walking    = false;
                        status     = State.Waiting;
                    }
                }
                else
                {
                    curFrame   = 0;
                    direction  = 1;
                    walking    = true;
                    keepmoving = true;
                }
                break;
            }

                //case State.MoveRight:
                //    {
                //        if (walking)
                //        {
                //            if (keepmoving)
                //            {
                //                position.X += 4;
                //                if (timer > 100f)
                //                {
                //                    curFrame++;
                //                    timer = 0f;
                //                }
                //                if (curFrame == 4)
                //                {
                //                    curFrame = 0;
                //                }

                //                //keepmoving = false;
                //                //walking = false;
                //                status = State.Waiting;

                //            }
                //        }
                //        break;
                //    }
                //case State.MoveDown:
                //    {
                //        if (walking)
                //        {
                //            if (keepmoving)
                //            {
                //                position.Y += 4;
                //                if (timer > 100f)
                //                {
                //                    curFrame++;
                //                    timer = 0f;
                //                }
                //                if (curFrame == 4)
                //                {
                //                    curFrame = 0;
                //                }

                //                //keepmoving = false;
                //                //walking = false;
                //                //Console.WriteLine("8TESSSSSSSST");
                //                status = State.Waiting;

                //            }
                //        }
                //        break;
                //    }
                //case State.MoveUp:
                //    {
                //        if (walking)
                //        {
                //            if (keepmoving)
                //            {
                //                position.Y -= 4;
                //                keepmoving = true;
                //                if (timer > 100f)
                //                {
                //                    curFrame++;
                //                    timer = 0f;
                //                }
                //                if (curFrame == 4)
                //                {
                //                    curFrame = 0;
                //                }

                //                //keepmoving = false;
                //                //walking = false;
                //                status = State.Waiting;

                //            }
                //        }
                //        break;
                //    }
                //case State.MoveLeft:
                //    {
                //        if (walking)
                //        {
                //            if (keepmoving)
                //            {
                //                position.X -= 4;
                //                keepmoving = true;
                //                if (timer > 100f)
                //                {
                //                    curFrame++;
                //                    timer = 0f;
                //                }
                //                if (curFrame == 4)
                //                {
                //                    curFrame = 0;
                //                }

                //                //keepmoving = false;
                //                //walking = false;
                //                status = State.Waiting;
                //            }

                //        }
                //        break;
                //    }
            }



            //if (waypoints.Count > 0)
            //{
            //    destination = waypoints.Dequeue();
            //    if (DistanceToDestination < 1f)
            //    {
            //        destination = waypoints.Peek();
            //        Console.WriteLine(waypoints.Count);
            //        destination = waypoints.Dequeue();
            //    }

            //    else
            //    {
            //        Vector2 newDirection = waypoints.Peek() - destination;
            //        newDirection.Normalize();

            //        velocity = Vector2.Multiply(newDirection, speed);

            //        destination = newDirection;
            //        destination += velocity;
            //    }
            //}

            if (position.X == 624 && position.Y == 144)
            {
                sceneManager.removeScene(sceneManager.currentScene);
                destination = new Vector2(32 * 3, 32 * 3);
            }
        }