本文整理汇总了C++中InputState::getKeyState方法的典型用法代码示例。如果您正苦于以下问题:C++ InputState::getKeyState方法的具体用法?C++ InputState::getKeyState怎么用?C++ InputState::getKeyState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputState
的用法示例。
在下文中一共展示了InputState::getKeyState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Player::Update(float GameTime)
{
InputState state = Input::Instance().getInputState();
//constantes
const math::vec2f run_acc(1400, 0); //aceleracion corriendo
const math::vec2f air_acc(400, 0); //aceleracion corriendo
const math::vec2f fri_acc(1000, 800); //aceleracion de la friccion
const math::vec2f gra_acc(0,-600); //aceleracion de la gravedad
const math::vec2f vel_max(225, 300); //velocidad maxima que adquiere un personaje
const math::vec2f vel_jmp(225, 225); //velocidad que adquiere un personaje al saltar
if (crouched)
{
ensureAnim("Crouch");
}
else
{
if (grounded)
{
if (state.getKeyState(K_LEFT) && !state.getKeyState(K_RIGHT))
{
if (vel.x > 0) ensureAnim("Turn");
else ensureAnim("Walk");
}
else if (state.getKeyState(K_RIGHT) && !state.getKeyState(K_LEFT))
{
if (vel.x < 0) ensureAnim("Turn");
else ensureAnim("Walk");
}
else
{
ensureAnim("Idle");
}
}
else
{
if (onWall) ensureAnim("OnWall");
else ensureAnim("Jump");
}
}
acc = math::vec2f(0,0);
crouched = ((crouched||grounded) && state.getKeyState(K_DOWN)) || (crouched&&!grounded);
if ( state.getKeyState(K_LEFT) ) {
setScaleWidth(-1); //Mirror del sprite
if (grounded) {
if (!crouched) acc -= run_acc;
}
else acc -= air_acc;
}
if ( state.getKeyState(K_RIGHT)) {
setScaleWidth(+1); //Sprite sin mirror
if (grounded) {
if (!crouched) acc += run_acc;
}
else acc += air_acc;
}
//FRICTION
fri = math::vec2f(0,0);
if (grounded)
{
if (crouched) fri.x = fri_acc.x/2;
else fri.x = fri_acc.x;
}
else
{
fri.x = fri_acc.x/8;
}
if (!crouched && onWall)
{
fri.y = fri_acc.y;
}
//Si en el frame anterior estaba tocando el suelo, inicializando
//jumpTimeLeft a mas de 0 permite al jugador saltar durante ese rato
if ( state.getKeyDown(K_JUMP) && (grounded||(onWall&&!crouched)))
{
jumpTimeLeft = 0.35f;
if (onWall && !grounded && !crouched) {
vel.x = vel_jmp.x * -1.0f * float(onWall);
}
}
if (state.getKeyState(K_JUMP) && jumpTimeLeft > 0)
vel.y = vel_jmp.y;
else //A la que deja de pulsarse el boton de saltar cae de inmediato
jumpTimeLeft = 0;
if (jumpTimeLeft <= 0) acc += gra_acc; //La gravedad afecta mientras no salte
else jumpTimeLeft -= GameTime; //Se le resta el tiempo mientras salta
vel_lim = vel_max;
grounded = false;
onWall = ONWALL_NO;
TilemapCharacter::Update(GameTime);
}