Exemplo n.º 1
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;
}
Exemplo n.º 2
0
/*! This method returns a TiredNessT enumeration that indicates how tired
    this associated agent with this Stamina value is. */
TiredNessT  Stamina::getTiredNess( double dRecDecThr, double dStaminaMax )
{
  double dStaDiffWithThr = getStamina() - dRecDecThr * dStaminaMax;
//  cerr << getStamina() << " " << dStaminaMax << 
//    " " << dRecDecThr << " " << dStaDiffWithThr << endl;
  if( dStaDiffWithThr < 100 )
    return TIREDNESS_TERRIBLE;
  else if( dStaDiffWithThr < 750 )
    return TIREDNESS_VERY_BAD;
  else if( dStaDiffWithThr < 1500 )
    return TIREDNESS_BAD;
  else if( dStaDiffWithThr < 2250 )
    return TIREDNESS_AVERAGE;

  return TIREDNESS_GOOD;
}
Exemplo n.º 3
0
void Player::throwCoin(double dt, bool throwKey)
{
	if(getStamina() < COIN_PRICE)	//not enough price to throw coin :(
	{
		return;
	}

	/* Set coin list */
	if(throwTimer < throwTime)
		throwTimer += dt;
	else
	{
		if(throwKey)
		{
			/* throwing coin flag to true */
			throwingCoin = true;
			throwTimer = 0.0;
	
			for(int i = 0; i < coinList.size(); ++i)
			{
				/* If not active, activate */
				if(!coinList[i]->getActive())
				{
					if(state == UP || state == IDLE)
						coinList[i]->Activate(position, 0, 1);
					else if(state == LEFT)
						coinList[i]->Activate(position, -1, 0);
					else if(state == RIGHT)
						coinList[i]->Activate(position, 1, 0);
					else if(state == DOWN)
						coinList[i]->Activate(position, 0, -1);
					break;
				}
			}
		}
	}
}
Exemplo n.º 4
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();
	}

}