// 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); } }
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(); }
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); }
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); }
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; }
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); }
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; } }
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; }
void Menu::CommonMenu(gdl::Input &input) { if (input.getKey(SDLK_UP)) { _cursor >= 2 ? _cursor-- : _cursor = 4; usleep(100000); } else if (input.getKey(SDLK_DOWN)) { _cursor <= 3 ? _cursor++ : _cursor = 1; usleep(100000); } if (input.getKey(SDLK_RETURN)) { switch (_cursor) { case 1: { _menu_type = PLAY_MENU; break; } case 2: { _menu_type = LOAD_MENU; break; } case 3: { _menu_type = OPTION_MENU; _sound ? _cursor = 9 : _cursor = 10; break; } case 4: { _menu_type = QUIT_MENU; break; } } } }
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); } }
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); }
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); } } }
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; case Player::LEFT: this->rotate(glm::vec3(0, -1, 0), 180); break; case Player::DOWN: this->rotate(glm::vec3(0, -1, 0), 270); break; } this->_dir = Player::RIGHT; this->translate(glm::vec3(1, 0, 0) * static_cast<float>(c.getElapsed()) * this->speed); } if (i.getKey(SDLK_LEFT)) { 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::RIGHT: this->rotate(glm::vec3(0, -1, 0), 180); break; case Player::UP: this->rotate(glm::vec3(0, -1, 0), 270); break; case Player::DOWN: this->rotate(glm::vec3(0, -1, 0), 90); break; } this->_dir = Player::LEFT; this->translate(glm::vec3(-1, 0, 0) * static_cast<float>(c.getElapsed()) * this->speed); } } if (this->_number == 1) { if (i.getKey(SDLK_s)) { 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_z)) { 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_d)) { 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; case Player::LEFT: this->rotate(glm::vec3(0, -1, 0), 180); break; case Player::DOWN: this->rotate(glm::vec3(0, -1, 0), 270); break; } this->_dir = Player::RIGHT; this->translate(glm::vec3(1, 0, 0) * static_cast<float>(c.getElapsed()) * this->speed); } if (i.getKey(SDLK_q)) { 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::RIGHT: this->rotate(glm::vec3(0, -1, 0), 180); break; case Player::UP: this->rotate(glm::vec3(0, -1, 0), 270); break; case Player::DOWN: this->rotate(glm::vec3(0, -1, 0), 90); break; } this->_dir = Player::LEFT; this->translate(glm::vec3(-1, 0, 0) * static_cast<float>(c.getElapsed()) * this->speed); } } 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); return (true); }
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; }