Keyboard events management
This commit is contained in:
parent
1f91a08465
commit
50b1a15589
43
Game.cpp
43
Game.cpp
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
|
|
||||||
#include "Engine/Utils/Perfs.hpp"
|
#include "Engine/Utils/Perfs.hpp"
|
||||||
|
|
||||||
@ -48,12 +48,6 @@ GAME_STATUS Game::Tick() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Event event;
|
|
||||||
while (mMainWindow->pollEvent(event)) {
|
|
||||||
if (event.type == sf::Event::Closed)
|
|
||||||
mMainWindow->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update game stats and internal stuff
|
// Update game stats and internal stuff
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
@ -84,11 +78,46 @@ GAME_STATUS Game::Tick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Update() {
|
void Game::Update() {
|
||||||
|
// Refresh keyboard inputs
|
||||||
|
KeyboardInputsCheck();
|
||||||
|
|
||||||
// Game logic calls should go here...
|
// Game logic calls should go here...
|
||||||
mWorldUI->Update();
|
mWorldUI->Update();
|
||||||
mCockpitUI->Update();
|
mCockpitUI->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::KeyboardInputsCheck() {
|
||||||
|
const float deltaTimeS = mSysTimer.GetDeltaTime() / 1000;
|
||||||
|
|
||||||
|
if (mMainWindow->hasFocus()) {
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Scan::LShift))
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_WALK, 15.0f * deltaTimeS);
|
||||||
|
else
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_WALK, 10.0f * deltaTimeS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Scan::LShift))
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_WALK, -15.0f * deltaTimeS);
|
||||||
|
else
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_WALK, -10.0f * deltaTimeS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_STRAFE, -10.0f * deltaTimeS);
|
||||||
|
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_STRAFE, 10.0f * deltaTimeS);
|
||||||
|
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_FLY, 5.0f * deltaTimeS);
|
||||||
|
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
|
||||||
|
mWorld3D->UpdateCamera(CAMERA_MOVE_FLY, -5.0f * deltaTimeS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Game::Render() {
|
void Game::Render() {
|
||||||
// Clear the draw buffer
|
// Clear the draw buffer
|
||||||
mMainWindow->clear(sf::Color::Black);
|
mMainWindow->clear(sf::Color::Black);
|
||||||
|
2
Game.hpp
2
Game.hpp
@ -36,6 +36,8 @@ private:
|
|||||||
static Game* smInstance;
|
static Game* smInstance;
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
void KeyboardInputsCheck();
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
bool mbDbgModeEnabled;
|
bool mbDbgModeEnabled;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <SFML/Window/Event.hpp>
|
||||||
#include <SFML/Graphics/RenderWindow.hpp>
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
#include <SFML/Window/ContextSettings.hpp>
|
#include <SFML/Window/ContextSettings.hpp>
|
||||||
|
|
||||||
@ -27,6 +28,45 @@ int main(int argc, char** argv) {
|
|||||||
GAME_STATUS status = GAME_INIT;
|
GAME_STATUS status = GAME_INIT;
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
|
sf::Event event;
|
||||||
|
while (mainWindow->pollEvent(event)) {
|
||||||
|
if (event.type == sf::Event::Closed)
|
||||||
|
switch (event.type) {
|
||||||
|
case sf::Event::Closed:
|
||||||
|
mainWindow->close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case sf::Event::Resized:
|
||||||
|
//TODO: Recreate window related resource
|
||||||
|
//event.size.width
|
||||||
|
//event.size.height
|
||||||
|
break;
|
||||||
|
|
||||||
|
//case sf::Event::LostFocus:
|
||||||
|
// pause();
|
||||||
|
// break;
|
||||||
|
|
||||||
|
//if (event.type == sf::Event::GainedFocus)
|
||||||
|
// resume();
|
||||||
|
// break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus only actions
|
||||||
|
if (mainWindow->hasFocus()) {
|
||||||
|
switch (event.type) {
|
||||||
|
case sf::Event::MouseMoved:
|
||||||
|
//if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = arcadeGame.Tick();
|
status = arcadeGame.Tick();
|
||||||
|
|
||||||
if (status == GAME_QUIT)
|
if (status == GAME_QUIT)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user