public Player(SpriteSheet spriteSheet, float x, float y, String startingAnimationName) : base(spriteSheet, x, y, startingAnimationName) { FacingDirection = Direction.RIGHT; AirGroundState = AirGroundState.AIR; previousAirGroundState = AirGroundState; PlayerState = PlayerState.STANDING; previousPlayerState = PlayerState; LevelState = LevelState.RUNNING; }
public override void Initialize() { base.Initialize(); facingDirection = startFacingDirection; if (facingDirection == Direction.RIGHT) { currentAnimationName = "WALK_RIGHT"; } else if (facingDirection == Direction.LEFT) { currentAnimationName = "WALK_LEFT"; } airGroundState = AirGroundState.GROUND; }
public override void OnEndCollisionCheckY(bool hasCollided, Direction direction) { // if bug is colliding with the ground, change its air ground state to GROUND // if it is not colliding with the ground, it means that it's currently in the air, so its air ground state is changed to AIR if (direction == Direction.DOWN) { if (hasCollided) { airGroundState = AirGroundState.GROUND; } else { airGroundState = AirGroundState.AIR; } } }
public override void Update() { //Debug.WriteLine("X: " + GetX() + " Y: " + GetY()); KeyboardState keyboardState = Keyboard.GetState(); moveAmountX = 0; moveAmountY = 0; // if player is currently playing through level (has not won or lost) if (LevelState == LevelState.RUNNING) { ApplyGravity(); // update player's state and current actions, which includes things like determining how much it should move each frame and if its walking or jumping do { previousPlayerState = PlayerState; HandlePlayerState(keyboardState); } while (previousPlayerState != PlayerState); previousAirGroundState = AirGroundState; // update player's animation base.Update(); // move player with respect to map collisions based on how much player needs to move this frame base.MoveYHandleCollision(moveAmountY); base.MoveXHandleCollision(moveAmountX); UpdateLockedKeys(keyboardState); } // if player has beaten level else if (LevelState == LevelState.LEVEL_COMPLETED) { UpdateLevelCompleted(); } // if player has lost level else if (LevelState == LevelState.PLAYER_DEAD) { UpdatePlayerDead(); } }
public override void Initialize() { base.Initialize(); dinosaurState = DinosaurState.WALK; previousDinosaurState = dinosaurState; facingDirection = startFacingDirection; if (facingDirection == Direction.RIGHT) { currentAnimationName = "WALK_RIGHT"; } else if (facingDirection == Direction.LEFT) { currentAnimationName = "WALK_LEFT"; } airGroundState = AirGroundState.GROUND; // every 2 seconds, the fireball will be shot out shootTimer.SetWaitTime(2000); }
//Also we need to start the context with initial state. //I use contructor class to specify the initial state public Aircraft(AirGroundState _initialState) { this.airGndState = _initialState; }