Game/Source/Player.cpp
// Load the player's state
Load the player's state
Load the player ' s state
bool Player::LoadState(pugi::xml_node& playerNode)
{
	savedPos.x = playerNode.child("position").attribute("position_x").as_float();
	savedPos.y = playerNode.child("position").attribute("position_y").as_float();
	velocity.x = playerNode.child("velocity").attribute("velocity_x").as_float();
	velocity.y = playerNode.child("velocity").attribute("velocity_y").as_float();
	st = playerNode.child("state").attribute("player_state").as_int();
	switch (st)
	{
	case PlayerState::IDLE:
		if (state == GOD_MODE)
		{
			godMode = false;
		}
		state = IDLE;
		currentAnimation->Reset();
		currentAnimation = idleAnim;
		break;
	case PlayerState::MOVE:
		if (state == GOD_MODE)
		{
			godMode = false;
		}
		state = MOVE;
		currentAnimation->Reset();
		currentAnimation = walkAnim;
		break;
	case PlayerState::JUMP:
		if (state == GOD_MODE)
		{
			godMode = false;
		}
		state = JUMP;
		currentAnimation->Reset();
		if (velocity.y <= 0.0f)
		{
			currentAnimation = jumpAnim;
			currentAnimation->Reset();
		}
		else
		{
			currentAnimation = fallAnim;
			currentAnimation->Reset();
		}
		break;
	case PlayerState::GOD_MODE:
		state = GOD_MODE;
		break;
	}
	currentAnimation->SetCurrentFrame(playerNode.child("state").attribute("current_frame").as_int());
	horizontalDirection = playerNode.child("state").attribute("horizontal_direction").as_int();
	return true;
}
bool Player :: LoadState ( pugi :: xml_node & playerNode ) { savedPos . x = playerNode . child ( " " ) . attribute ( " " ) . as_float ( ) ; savedPos . y = playerNode . child ( " " ) . attribute ( " " ) . as_float ( ) ; velocity . x = playerNode . child ( " " ) . attribute ( " " ) . as_float ( ) ; velocity . y = playerNode . child ( " " ) . attribute ( " " ) . as_float ( ) ; st = playerNode . child ( " " ) . attribute ( " " ) . as_int ( ) ; switch ( st ) { case PlayerState :: IDLE : if ( state == GOD_MODE ) { godMode = false ; } state = IDLE ; currentAnimation -> Reset ( ) ; currentAnimation = idleAnim ; break ; case PlayerState :: MOVE : if ( state == GOD_MODE ) { godMode = false ; } state = MOVE ; currentAnimation -> Reset ( ) ; currentAnimation = walkAnim ; break ; case PlayerState :: JUMP : if ( state == GOD_MODE ) { godMode = false ; } state = JUMP ; currentAnimation -> Reset ( ) ; if ( velocity . y <= 0.0f ) { currentAnimation = jumpAnim ; currentAnimation -> Reset ( ) ; } else { currentAnimation = fallAnim ; currentAnimation -> Reset ( ) ; } break ; case PlayerState :: GOD_MODE : state = GOD_MODE ; break ; } currentAnimation -> SetCurrentFrame ( playerNode . child ( " " ) . attribute ( " " ) . as_int ( ) ) ; horizontalDirection = playerNode . child ( " " ) . attribute ( " " ) . as_int ( ) ; return true ; }
Load the player's state
Load the player ' s state
// Load position // Load velocity // Load state