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); }
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); }