Ejemplo n.º 1
0
/*! This is the constructor for this class. It sets the stamina, effort and
    recovery on the supplied values.
    \param dSta new stamina value (default 4000.0)
    \param dEff new effort value (default 1.0)
    \param dRec new recovery value (default 1.0)*/
Stamina::Stamina( double dSta, double dEff, double dRec , double dCap)
{
  setStamina ( dSta );
  setEffort  ( dEff );
  setRecovery( dRec );
  setCapacity( dCap );
}
Ejemplo n.º 2
0
bool Player::useItem(bool* myKey)
{	
	Item* ptr = inventory.useItem();

	if(ptr == NULL)
	{
		return false;
	}
	
	if(info.getTimer() > 0.5)
	{
		if(myKey[KEY_L] && health < 100 && ptr->getItemID() == Item::H_POTION)
		{
			if(inventory.removeItem(this->position))
			{
				ptr->setActive(false);
			}
			setHealth(getHealth() + 10);
			if(getHealth() >= 100)
			{
				health = 100;
			}
			my_sfx_man->play_yummy();
			info.setTimer(0);
		}

		else if(myKey[KEY_L] && stamina < 100 && ptr->getItemID() == Item::S_POTION)
		{
			if(inventory.removeItem(this->position))
			{
				ptr->setActive(false);
			}
			setStamina(getStamina() + 20);
			if(getStamina() >= 100)
			{
				stamina = 100;
			}
			my_sfx_man->play_yummy();
			info.setTimer(0);
		}
	}
	return false;
}
Ejemplo n.º 3
0
void Player::Update(double dt, bool* myKey)
{
	Vector3 Pos;

	// Counts from 0
	info.setTimer(info.getTimer() + dt);

	/* if invisible, staminia */
	if(invisible)
	{
		setStamina(getStamina() - INVISIBILITY_PRICE * dt);	
	}

	/* if throw coin */
	if(throwingCoin)
	{
		throwingCoin = false;
		setStamina(getStamina() - COIN_PRICE);
	}

	/* If not enough staminia, invisible 0 */
	if(getStamina() <= 0)
	{
		setStamina(0);

		if(invisible)
		{
			switchInvisibleState();
		}
	}

	/* update inventory */
	inventory.Update(dt, myKey);

	/* Use item */
	useItem(myKey);

	//cout << animationList[UP]->startRow << " " << animationList[DOWN]->startRow << endl;
	//setState(IDLE);
	if(myKey[KEY_W])
	{
		UpOrDown = false;
		checkUD = false;
		if(vel.y < PLAYER_SPEED)
		{
			vel.y += 0.5;
			Pos.y = vel.y;
		}
		else
		{
			vel.y = PLAYER_SPEED;
			Pos.y = vel.y;
		}

		//Movement / physics
		//translateObject(0, 4, 0);
		//Animation
		setState(UP);
		if (animationList[UP]->ended == true)
		{
			animationList[UP]->Reset();
		}

		//Sound
		sf_walk = true;
	}

	else if(myKey[KEY_S])
	{
		UpOrDown = true;
		checkUD = true;
		if(vel.y > -PLAYER_SPEED)
		{
			vel.y -= 0.5;
			Pos.y = vel.y;
		}
		else
		{
			vel.y = -PLAYER_SPEED;
			Pos.y = vel.y;
		}

		setState(DOWN);
		if (animationList[DOWN]->ended == true)
		{
			animationList[DOWN]->Reset();
		}

		sf_walk = true;
	}	


	else if(myKey[KEY_A])
	{
		LeftOrRight = true;
		checkLR = true;
		if(vel.x >= -PLAYER_SPEED)
		{
			vel.x -= 0.5;
			Pos.x = vel.x;
		}
		else
		{
			vel.x = -PLAYER_SPEED;
			Pos.x = vel.x;
		}
		
		setState(LEFT);
		if (animationList[LEFT]->ended == true)
		{
			animationList[LEFT]->Reset();
		}
		sf_walk = true;
	}

	else if(myKey[KEY_D])
	{
		LeftOrRight = false;
		checkLR = false;
		if(vel.x <= PLAYER_SPEED)
		{
			vel.x += 0.5;
			Pos.x = vel.x;
		}
		else
		{
			vel.x = PLAYER_SPEED;
			Pos.x = vel.x;
		}
		
		setState(RIGHT);
		if (animationList[RIGHT]->ended == true)
		{
			animationList[RIGHT]->Reset();
		}
		sf_walk = true;
	}
	
	if(!myKey[KEY_W] && !myKey[KEY_S] && vel.y != 0)
	{
		if(UpOrDown == false && checkUD == false)
		{
			vel.y -= deceleration * dt;
			if(vel.y < 0 && !myKey[KEY_W])
			{
				vel.y = 0;
			}
		}

		if(UpOrDown == true && checkUD == true)
		{
			vel.y += deceleration * dt;
			if(vel.y > 0 && !myKey[KEY_S])
			{
				vel.y = 0;
			}
		}
		Pos.y += vel.y;
	}

	if(!myKey[KEY_A] && !myKey[KEY_D] && vel.x != 0)
	{
		if(LeftOrRight == false && checkLR == false)
		{
			vel.x -= deceleration * dt;
			if(vel.x < 0 && !myKey[KEY_D])
			{
				vel.x= 0;
			}
		}

		if(LeftOrRight == true && checkLR == true)
		{
			vel.x += deceleration * dt;
			if(vel.x > 0 && !myKey[KEY_A])
			{
				vel.x = 0;
			}
		}
		Pos.x += vel.x;
	}

	translateObject(Pos);

	if(!myKey[KEY_W] && !myKey[KEY_A] && !myKey[KEY_S] && !myKey[KEY_D])
	{
		sf_walk = false;
	}

	switch(state)
	{
	case UP:
		{
			if(mesh != animationList[UP])
			{
				setMesh(animationList[UP]);
			}
			animationList[UP]->Update(dt);
			break;
		}
	case DOWN:
		{
			if(mesh != animationList[DOWN])
			{
				setMesh(animationList[DOWN]);
			}
			animationList[DOWN]->Update(dt);
			break;
		}
	case LEFT:
		{
			if(mesh != animationList[LEFT])
			{
				setMesh(animationList[LEFT]);
			}
			animationList[LEFT]->Update(dt);
			break;
		}
	case RIGHT:
		{
			if(mesh != animationList[RIGHT])
			{
				setMesh(animationList[RIGHT]);
			}
			animationList[RIGHT]->Update(dt);
			break;
		}
	case ATTACKUP:
		{
			if(mesh != animationList[ATTACKUP])
			{
				setMesh(animationList[ATTACKUP]);
			}
			animationList[ATTACKUP]->Update(dt);
			break;
		}
	case ATTACKDOWN:
		{
			if(mesh != animationList[ATTACKDOWN])
			{
				setMesh(animationList[ATTACKDOWN]);
			}
			animationList[ATTACKDOWN]->Update(dt);
			break;
		}
	case ATTACKLEFT:
		{
			if(mesh != animationList[ATTACKLEFT])
			{
				setMesh(animationList[ATTACKLEFT]);
			}
			animationList[ATTACKLEFT]->Update(dt);
			break;
		}
	case ATTACKRIGHT:
		{
			if(mesh != animationList[ATTACKRIGHT])
			{
				setMesh(animationList[ATTACKRIGHT]);
			}
			animationList[ATTACKRIGHT]->Update(dt);
			break;
		}
	};

	//Sound
	if (sf_walk == true)
	{
		my_sfx_man->play_plyr_steps();
	}

}