本文整理汇总了C++中gdl::Input::getKey方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::getKey方法的具体用法?C++ Input::getKey怎么用?C++ Input::getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gdl::Input
的用法示例。
在下文中一共展示了Input::getKey方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
// Ici le cube bougera avec les fleches du clavier
virtual void update(gdl::Clock const &clock, gdl::Input &input)
{
glm::vec3 pos = glm::vec3(0, 0, 0);
float delta = static_cast<float>(clock.getElapsed()) * _speed;
// On multiplie par le temps ecoule depuis la derniere image pour que la vitesse ne depende pas de la puissance de l'ordinateur
if (input.getKey(SDLK_UP))
{
pos.x = 1;
_rotation.y = -90;
translate(pos * delta);
}
if (input.getKey(SDLK_DOWN))
{
pos.x = -1;
_rotation.y = 90;
translate(pos * delta);
}
if (input.getKey(SDLK_LEFT))
{
pos.z = -1;
_rotation.y = 180;
translate(pos * delta);
}
if (input.getKey(SDLK_RIGHT))
{
pos.z = 1;
_rotation.y = 0;
translate(pos * delta);
}
}
示例2: dropBomb
void Player::update(gdl::Clock const& clock,
gdl::Input& input)
{
_timeReload -= clock.getElapsed();
if (_timeReload <= 0.0f)
{
_bombCount = ((_bombCount < _maxBombCount) ? _maxBombCount : _bombCount);
_timeReload = 1.5f;
}
if (input.getKey(_controls[DROPBOMB], false))
dropBomb(clock);
for (int i = TOP; i != NONE; i++)
{
if (input.getKey(_controls[static_cast<e_dir>(i)], false))
{
moveTo(static_cast<e_dir>(i), clock);
return ;
}
}
if (_hasToStop == true)
{
_model->setCurrentSubAnim("end", false);
_hasToStop = false;
}
checkPlayerDeath();
}
示例3: return
bool Event::eventInGame(std::vector<AObject *> & players,
gdl::Input & input, gdl::Clock & clock, int _nb_player)
{
for (unsigned int i = 0; i < players.size(); i++)
{
if ((i < 2 && _nb_player == 2) || (i < 1 && _nb_player == 1))
{
if (!players[i]->isDead() &&
(input.getKey(static_cast<Player *>(players[i])->_event.getTop())
|| input.getKey(static_cast<Player *>(players[i])->_event.getBot())
|| input.getKey(static_cast<Player *>(players[i])->_event.getRight())
|| input.getKey(static_cast<Player *>(players[i])->_event.getLeft())))
if ((static_cast<Bomber *>(players[i]->getObject()))->launchWalkAnim() == false)
return (false);
if (!players[i]->isDead())
static_cast<Player *>(players[i])->checkEvent(input, clock);
}
else
{
if (!players[i]->isDead())
if (!static_cast<Player *>(players[i])->handleActionIa(clock))
return (false);
}
}
return (true);
}
示例4: update
virtual void update(gdl::Clock const &clock, gdl::Input &input)
{
if (input.getKey(SDLK_UP))
translate(glm::vec3(0, 0, 1) * static_cast<float>(clock.getElapsed()) * _speed);
if (input.getKey(SDLK_DOWN))
translate(glm::vec3(0, 0, -1) * static_cast<float>(clock.getElapsed()) * _speed);
if (input.getKey(SDLK_LEFT))
translate(glm::vec3(-1, 0, 0) * static_cast<float>(clock.getElapsed()) * _speed);
if (input.getKey(SDLK_RIGHT))
translate(glm::vec3(1, 0, 0) * static_cast<float>(clock.getElapsed()) * _speed);
}
示例5: if
void Menu::PlayMenu(gdl::Input &input)
{
if (input.getKey(SDLK_UP))
{
_cursor == 5 ? _cursor = 8 : _cursor--;
usleep(100000);
}
else if (input.getKey(SDLK_DOWN))
{
_cursor <= 7 ? _cursor++ : _cursor = 5;
usleep(100000);
}
if (_cursor == 5)
{
if (input.getKey(SDLK_RIGHT))
_nbr_players = 2;
else if (input.getKey(SDLK_LEFT))
_nbr_players = 1;
}
if (_cursor == 6)
{
int nbmax = _size_x / 3;
if (input.getKey(SDLK_RIGHT))
{
_nbr_enemies >= nbmax ? _nbr_enemies = 1 : _nbr_enemies += 1;
usleep(100000);
}
else if (input.getKey(SDLK_LEFT))
{
_nbr_enemies >= 2 ? _nbr_enemies -= 1 : _nbr_enemies = nbmax;
usleep(100000);
}
}
if (_cursor == 7)
{
if (input.getKey(SDLK_RIGHT))
{
_size_x >= 100 ? _size_x = 10 : _size_x += 1;
_size_y >= 100 ? _size_y = 10 : _size_y += 1;
usleep(100000);
}
else if (input.getKey(SDLK_LEFT))
{
_size_x > 10 ? _size_x -= 1 : _size_x = 100;
_size_y > 10 ? _size_y -= 1 : _size_y = 100;
usleep(100000);
}
if (_nbr_enemies > static_cast<int>(_size_x / 3))
_nbr_enemies = _size_x/3;
}
if (_cursor == 8 &&
getMapY() != 0 &&
getMapX() != 0 &&
getNbrEnemies() != 0 &&
getNbrPlayers() != 0 &&
input.getKey(SDLK_RETURN))
_cursor = 11;
}
示例6: return
int Intro::GameIntro::update(gdl::Clock const& clock, gdl::Input &input)
{
_introtime -= clock.getElapsed();
if (_cam->getLookAt().y - clock.getElapsed() * 10 > 0)
_cam->getLookAt().y -= clock.getElapsed() * 10;
_cam->getCameraDiff().z += clock.getElapsed() * 5;
if (_introtime <= 0 || input.getKey(SDLK_SPACE))
return (0);
return (4);
}
示例7: usleep
void Menu::OptionMenu(gdl::Input &input)
{
if (_cursor == 9 && input.getKey(SDLK_SPACE))
{
_cursor = 1;
_sound = true;
_menu_type = COMMON_MENU;
}
if (input.getKey(SDLK_RIGHT) || input.getKey(SDLK_LEFT))
{
_cursor == 9 ? _cursor = 10: _cursor = 9;
usleep(100000);
}
if (_cursor == 10 && input.getKey(SDLK_SPACE))
{
_cursor = 1;
_sound = false;
_menu_type = COMMON_MENU;
}
}
示例8: moveCam
void FreeCam::moveCam(gdl::Input & input, float delta)
{
if (input.getKey(SDLK_UP) || input.getKey(SDLK_z))
translate(_target * (_speed * delta));
if (input.getKey(SDLK_DOWN) || input.getKey(SDLK_s))
translate(-_target * (_speed * delta));
if (input.getKey(SDLK_LEFT) || input.getKey(SDLK_q))
translate(_left * (_speed * delta));
if (input.getKey(SDLK_RIGHT) || input.getKey(SDLK_d))
translate(-_left * (_speed * delta));
_forward = _pos + _target;
}
示例9: if
void Pause::update(gdl::Clock const & clock, gdl::Input & input)
{
(void)clock;
(void)input;
if (input.getKey(SDLK_s))
{
_cMode != mode::pause::QUIT ? _cMode += 1 : _cMode = mode::pause::RESUME;
_ping.play();
usleep(100000);
}
else if (input.getKey(SDLK_z))
{
_cMode != mode::pause::RESUME ? _cMode -= 1 : _cMode = mode::pause::QUIT;
_ping.play();
usleep(100000);
}
else if (input.getKey(SDLK_RETURN, true))
{
_mode = _cMode;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}
示例10: if
bool Event::checkEvent(gdl::Input & input,
gdl::Clock & clock,
std::vector<AObject *> & players,
Pause & pause,
Menu & menu,
int _nb_players)
{
// EVENT IN GAME
if (!pause.isPaused() && !menu.isMenu() && pause.isLoading() == 0)
{
if (!eventInGame(players, input, clock, _nb_players))
return (false);
}
// EVENT IN PAUSE
else if (pause.isPaused() || pause.isLoading() == 3)
{
if (!pause.update(input, clock))
return (false);
if (pause.isLoading() == 0)
{
if (pause.isMenu())
menu.setMenu(true);
if (!pause.isPaused())
desactivePause(players, pause);
}
}
// EVENT IN MENU
else
if (!menu.update(input, clock))
return (false);
if (input.getInput(SDL_QUIT))
return (false);
if (input.getKey(SDLK_ESCAPE, true))
{
if (pause.isPaused())
desactivePause(players, pause);
else if (!menu.isMenu())
activePause(players, pause);
}
return (true);
}
示例11: update
void Marvin::update(gdl::Clock const &clock,
gdl::Input & input)
{
this->saveCurrentState();
for (std::vector<inputStructure>::iterator it = _inputs.begin(); it != _inputs.end(); ++it) {
//Replace getKeyDown which is not implemented yet
if (input.getKey(it -> value)) {
if (it -> isPressed == false) {
it -> isPressed = true;
(this->*it -> functionPressed)(clock);
}
// Call the method pointer
(this->*it -> function)(clock);
} else if (it -> isPressed) { //Replace getKeyUp which is not implemented yet
it -> isPressed = false;
(this->*it -> functionReleased)(clock);
}
}
}
示例12: round
bool Human::update(gdl::AShader &s, const gdl::Clock &c, gdl::Input &i, const std::vector<Block *> &list, const std::vector<Block *> &wall, std::vector<Bonus *> &listBonus)
{
glm::mat4 transformation;
transformation = glm::lookAt(glm::vec3(this->_position.x, this->_position.y - 3, 5), glm::vec3(this->_position.x, this->_position.y, this->_position.z), glm::vec3(0, 1, 0));
s.setUniform("view", transformation);
if (this->_number == 0)
{
if (i.getKey(SDLK_DOWN))
{
double x = round(this->_position.x);
double y = round(this->_position.y - 0.5);
for (double i = 0; i < list.size(); ++i)
{
if (x == round(list[i]->getPos().x) && y == round(list[i]->getPos().y) && this->_position.z == list[i]->getPos().z)
return (true);
}
for (double i = 0; i < wall.size(); ++i)
{
if (x == round(wall[i]->getPos().x) && y == round(wall[i]->getPos().y) && this->_position.z == wall[i]->getPos().z)
return (true);
}
for (double i = 0; i < listBonus.size(); i++)
{
if (x == round(listBonus[i]->getPos().x) && y == round(listBonus[i]->getPos().y))
{
this->pickUpBonus(listBonus, i);
}
}
switch (this->_dir)
{
case Player::UP:
this->rotate(glm::vec3(0, -1, 0), 180);
break;
case Player::LEFT:
this->rotate(glm::vec3(0, -1, 0), 270);
break;
case Player::RIGHT:
this->rotate(glm::vec3(0, -1, 0), 90);
break;
}
this->_dir = Player::DOWN;
this->translate(glm::vec3(0, -1, 0) * static_cast<float>(c.getElapsed()) * this->speed);
}
if (i.getKey(SDLK_UP))
{
double x = round(this->_position.x);
double y = round(this->_position.y + 0.5);
for (double i = 0; i < list.size(); ++i)
{
if (x == round(list[i]->getPos().x) && y == round(list[i]->getPos().y) && this->_position.z == list[i]->getPos().z)
return (true);
}
for (double i = 0; i < wall.size(); ++i)
{
if (x == round(wall[i]->getPos().x) && y == round(wall[i]->getPos().y) && this->_position.z == wall[i]->getPos().z)
return (true);
}
for (double i = 0; i < listBonus.size(); i++)
if (x == round(listBonus[i]->getPos().x) && y == round(listBonus[i]->getPos().y))
this->pickUpBonus(listBonus, i);
switch (this->_dir)
{
case Player::DOWN:
this->rotate(glm::vec3(0, -1, 0), 180);
break;
case Player::LEFT:
this->rotate(glm::vec3(0, -1, 0), 90);
break;
case Player::RIGHT:
this->rotate(glm::vec3(0, -1, 0), 270);
break;
}
this->_dir = Player::UP;
this->translate(glm::vec3(0, 1, 0) * static_cast<float>(c.getElapsed()) * this->speed);
}
if (i.getKey(SDLK_RIGHT))
{
double x = round(this->_position.x + 0.5);
double y = round(this->_position.y);
for (double i = 0; i < list.size(); ++i)
{
if (x == round(list[i]->getPos().x) && y == round(list[i]->getPos().y) && this->_position.z == list[i]->getPos().z)
return (true);
}
for (double i = 0; i < wall.size(); ++i)
{
if (x == round(wall[i]->getPos().x) && y == round(wall[i]->getPos().y) && this->_position.z == wall[i]->getPos().z)
return (true);
}
for (double i = 0; i < listBonus.size(); i++)
if (x == round(listBonus[i]->getPos().x) && y == round(listBonus[i]->getPos().y))
this->pickUpBonus(listBonus, i);
switch (this->_dir)
{
case Player::UP:
this->rotate(glm::vec3(0, -1, 0), 90);
break;
//.........这里部分代码省略.........
示例13: update
bool OptionMenu::update(gdl::Clock const& clock, gdl::Input& input)
{
glm::vec3 tmp;
if (input.getKey(SDLK_RIGHT))
{
if (_cursorPos == 0)
{
if (_son.getVolumeFx() <= 126 && _son.isMute() == false)
{
OptionMenu::soundfxhandler(1);
tmp = _cursorFx->getPosition();
tmp.x = tmp.x + getXPercent(1);
_cursorFx->setPosX(tmp);
}
}
else if (_cursorPos == 1)
{
if (_son.getVolumeMusic() <= 126 && _son.isMute() == false)
{
OptionMenu::soundmusichandler(1);
tmp = _cursorMusic->getPosition();
tmp.x = tmp.x + getXPercent(1);
_cursorMusic->setPosX(tmp);
}
}
}
if (input.getKey(SDLK_LEFT))
{
if (_cursorPos == 0)
{
if (_son.getVolumeFx() >= 2 && _son.isMute() == false)
{
OptionMenu::soundfxhandler(-1);
tmp = _cursorFx->getPosition();
tmp.x = tmp.x - getXPercent(1);
_cursorFx->setPosX(tmp);
}
}
else if (_cursorPos == 1)
{
if (_son.getVolumeMusic() >= 2 && _son.isMute() == false)
{
OptionMenu::soundmusichandler(-1);
tmp = _cursorMusic->getPosition();
tmp.x = tmp.x - getXPercent(1);
_cursorMusic->setPosX(tmp);
}
}
}
if (input.getKey(SDLK_UP) && !_btnUp)
{
_son.playFx("button");
_cursorPos--;
_btnUp = true;
if (_cursorPos < 0)
_cursorPos = 3;
}
if (!input.getKey(SDLK_UP) && _btnUp)
_btnUp = false;
if (input.getKey(SDLK_DOWN) && !_btnDown)
{
_son.playFx("button");
_btnDown = true;
_cursorPos++;
if (_cursorPos == 4)
_cursorPos = 0;
}
if (!input.getKey(SDLK_DOWN) && _btnDown)
_btnDown = false;
if (input.getKey(SDLK_SPACE) && !_btnSpace)
{
std::map<AWidget* , ButtonHandler>::iterator it;
_son.playFx("button");
_btnSpace = true;
it = _mapButton.begin();
while (it != _mapButton.end())
{
if (it->first->getCur() == _cursorPos)
(this->*(it->second))(SDLK_SPACE);
it++;
}
}
if (!input.getKey(SDLK_SPACE) && _btnSpace)
_btnSpace = false;
return true;
}