@Override
	public void act(float deltaTime) {
		float startX = getX();

      if (forward) {
         stateTime += deltaTime;
         if (getX() < (getStage().getWidth() - getWidth() / 2)) {
            translate(1, 0);
         }
      } else {
         forward = false;
         stateTime += deltaTime;
         if (getX() > 0) {
            translate(-1, 0);
         }
      }		
		
	   jumpAction.act(deltaTime);
		gravityAction.act(deltaTime);
		   
		if (isSelected && Gdx.input.isKeyPressed(Keys.W) && !jumpAction.isJumping()) {
			stateTime = 0;
			jumpAction.jump(forward);
		}

      Obstacles obstacles = ((Level1)getStage()).obstacles;
      if (startX < getX()) {
         // moving to the right
         float maxX = obstacles.getMaxX(this);
         if (getX() > maxX) {
            translate(maxX - getX(), 0);
            forward = false;
         }
      } else {
         // moving to the left
         float minX = obstacles.getMinX(this);
         if (getX() < minX) {
            translate(minX - getX(), 0);
            forward = true;
         }
      }
	}