Changed how key states are handled.
This commit is contained in:
parent
3614ff4892
commit
9a54c033c0
14
game/keyboardState.hh
Normal file
14
game/keyboardState.hh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct KeyboardState {
|
||||||
|
bool wPressed;
|
||||||
|
bool aPressed;
|
||||||
|
bool sPressed;
|
||||||
|
bool dPressed;
|
||||||
|
bool kPressed;
|
||||||
|
bool lPressed;
|
||||||
|
bool f1Pressed;
|
||||||
|
bool f2Pressed;
|
||||||
|
bool f3Pressed;
|
||||||
|
bool f4Pressed;
|
||||||
|
};
|
@ -70,8 +70,8 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed,bool kPressed, bool lPressed,
|
void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,
|
||||||
bool f1Pressed, bool f2Pressed, bool f3Pressed, bool f4Pressed) {
|
KeyboardState* keyboardState) {
|
||||||
|
|
||||||
// Ignore first two mouse updates, because they are incorrect
|
// Ignore first two mouse updates, because they are incorrect
|
||||||
// DON'T try to move this functionallity elsewhere
|
// DON'T try to move this functionallity elsewhere
|
||||||
@ -98,36 +98,36 @@ void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseD
|
|||||||
camera.setPosition(physics.getCameraPosition());
|
camera.setPosition(physics.getCameraPosition());
|
||||||
camera.setDirection(physics.getCameraToPlayer());
|
camera.setDirection(physics.getCameraToPlayer());
|
||||||
|
|
||||||
if(wPressed){
|
if(keyboardState->wPressed){
|
||||||
physics.rollForward(camera.getVector(),strength/runs);
|
physics.rollForward(camera.getVector(),strength/runs);
|
||||||
}
|
}
|
||||||
if(aPressed) {
|
if(keyboardState->aPressed) {
|
||||||
physics.rollLeft(camera.getVector(),strength/runs);
|
physics.rollLeft(camera.getVector(),strength/runs);
|
||||||
}
|
}
|
||||||
if(sPressed) {
|
if(keyboardState->sPressed) {
|
||||||
physics.rollBack(camera.getVector(),strength/runs);
|
physics.rollBack(camera.getVector(),strength/runs);
|
||||||
}
|
}
|
||||||
if(dPressed){
|
if(keyboardState->dPressed){
|
||||||
physics.rollRight(camera.getVector(),strength/runs);
|
physics.rollRight(camera.getVector(),strength/runs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(f1Pressed) {
|
if(keyboardState->f1Pressed) {
|
||||||
physics.forcePlayer(glm::vec3(17.5, 21.0, 87.0));
|
physics.forcePlayer(glm::vec3(17.5, 21.0, 87.0));
|
||||||
}
|
}
|
||||||
if(f2Pressed) {
|
if(keyboardState->f2Pressed) {
|
||||||
physics.forcePlayer(glm::vec3(-78.5, 21.75, 4.5));
|
physics.forcePlayer(glm::vec3(-78.5, 21.75, 4.5));
|
||||||
}
|
}
|
||||||
if(f3Pressed) {
|
if(keyboardState->f3Pressed) {
|
||||||
physics.forcePlayer(glm::vec3(-169.5, 21.5, 58.5));
|
physics.forcePlayer(glm::vec3(-169.5, 21.5, 58.5));
|
||||||
}
|
}
|
||||||
if(f4Pressed) {
|
if(keyboardState->f4Pressed) {
|
||||||
physics.forcePlayer(glm::vec3(-180.5, 21.75, 58.5));
|
physics.forcePlayer(glm::vec3(-180.5, 21.75, 58.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(kPressed)
|
if(keyboardState->kPressed)
|
||||||
camera.setIsPhysicsCamera(true);
|
camera.setIsPhysicsCamera(true);
|
||||||
if(lPressed)
|
if(keyboardState->lPressed)
|
||||||
camera.setIsPhysicsCamera(false);
|
camera.setIsPhysicsCamera(false);
|
||||||
|
|
||||||
cameraCenter->setPosition(physics.getPos(0));
|
cameraCenter->setPosition(physics.getPos(0));
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "physics.hh"
|
#include "physics.hh"
|
||||||
#include "trigger.hh"
|
#include "trigger.hh"
|
||||||
#include "skydome.hh"
|
#include "skydome.hh"
|
||||||
|
#include "keyboardState.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
@ -25,8 +26,8 @@ class Level {
|
|||||||
Level();
|
Level();
|
||||||
~Level();
|
~Level();
|
||||||
void load();
|
void load();
|
||||||
void update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed, bool kPressed, bool lPressed,
|
void update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,
|
||||||
bool f1Pressed, bool f2Pressed, bool f3Pressed, bool f4Pressed );
|
KeyboardState* keyboardState);
|
||||||
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
||||||
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs=0);
|
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs=0);
|
||||||
glm::vec3 getAmbientLight();
|
glm::vec3 getAmbientLight();
|
||||||
|
43
game/main.cc
43
game/main.cc
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "keyboardState.hh"
|
||||||
|
|
||||||
static void resizeCallback(GLFWwindow* window, int newWidth, int newHeight)
|
static void resizeCallback(GLFWwindow* window, int newWidth, int newHeight)
|
||||||
{
|
{
|
||||||
@ -144,6 +145,8 @@ int main( int argc, char *argv[] )
|
|||||||
double showNextFPS = startTimeInSeconds + FPSdelay;
|
double showNextFPS = startTimeInSeconds + FPSdelay;
|
||||||
|
|
||||||
double lastUpdate=0.0f;
|
double lastUpdate=0.0f;
|
||||||
|
|
||||||
|
KeyboardState keyboardState;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
@ -160,28 +163,38 @@ int main( int argc, char *argv[] )
|
|||||||
if (app.isGameStarted()) {
|
if (app.isGameStarted()) {
|
||||||
static float gameStart = now;
|
static float gameStart = now;
|
||||||
if (app.isLocked() && app.getIgnoredMouseUpdates() == 0) {
|
if (app.isLocked() && app.getIgnoredMouseUpdates() == 0) {
|
||||||
int stateW = glfwGetKey(window, GLFW_KEY_W);
|
keyboardState.wPressed = glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS;
|
||||||
int stateA = glfwGetKey(window, GLFW_KEY_A);
|
keyboardState.aPressed = glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS;
|
||||||
int stateS = glfwGetKey(window, GLFW_KEY_S);
|
keyboardState.sPressed = glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS;
|
||||||
int stateD = glfwGetKey(window, GLFW_KEY_D);
|
keyboardState.dPressed = glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS;
|
||||||
int stateK = glfwGetKey(window, GLFW_KEY_K);
|
keyboardState.lPressed = glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS;
|
||||||
int stateL = glfwGetKey(window, GLFW_KEY_L);
|
keyboardState.kPressed = glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS;
|
||||||
int stateF1 = glfwGetKey(window, GLFW_KEY_F1);
|
keyboardState.f1Pressed = glfwGetKey(window, GLFW_KEY_F1) == GLFW_PRESS;
|
||||||
int stateF2 = glfwGetKey(window, GLFW_KEY_F2);
|
keyboardState.f2Pressed = glfwGetKey(window, GLFW_KEY_F2) == GLFW_PRESS;
|
||||||
int stateF3 = glfwGetKey(window, GLFW_KEY_F3);
|
keyboardState.f3Pressed = glfwGetKey(window, GLFW_KEY_F3) == GLFW_PRESS;
|
||||||
int stateF4 = glfwGetKey(window, GLFW_KEY_F4);
|
keyboardState.f4Pressed = glfwGetKey(window, GLFW_KEY_F4) == GLFW_PRESS;
|
||||||
|
|
||||||
double xpos, ypos;
|
double xpos, ypos;
|
||||||
glfwGetCursorPos(window, &xpos, &ypos);
|
glfwGetCursorPos(window, &xpos, &ypos);
|
||||||
glfwSetCursorPos(window, ((double)app.getGraphics()->getWindowSize().x)/2.0, ((double)app.getGraphics()->getWindowSize().y)/2.0);
|
glfwSetCursorPos(window, ((double)app.getGraphics()->getWindowSize().x)/2.0, ((double)app.getGraphics()->getWindowSize().y)/2.0);
|
||||||
app.getLevel()->update(now - lastUpdate, now - gameStart,
|
app.getLevel()->update(now - lastUpdate, now - gameStart,
|
||||||
glm::vec2((float)ypos-app.getGraphics()->getWindowSize().y/2,
|
glm::vec2((float)ypos-app.getGraphics()->getWindowSize().y/2,
|
||||||
(float)xpos-app.getGraphics()->getWindowSize().x/2),
|
(float)xpos-app.getGraphics()->getWindowSize().x/2),
|
||||||
stateW == GLFW_PRESS,stateA == GLFW_PRESS,stateS == GLFW_PRESS,stateD == GLFW_PRESS,stateK == GLFW_PRESS,stateL == GLFW_PRESS, stateF1 == GLFW_PRESS,
|
&keyboardState);
|
||||||
stateF2 == GLFW_PRESS, stateF3 == GLFW_PRESS, stateF4 == GLFW_PRESS);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
app.getLevel()->update(now - lastUpdate, now-gameStart, glm::vec2(0.0f, 0.0f), false, false, false, false,false,false,false,false,false,false);
|
keyboardState.wPressed = false;
|
||||||
|
keyboardState.aPressed = false;
|
||||||
|
keyboardState.sPressed = false;
|
||||||
|
keyboardState.dPressed = false;
|
||||||
|
keyboardState.lPressed = false;
|
||||||
|
keyboardState.kPressed = false;
|
||||||
|
keyboardState.f1Pressed = false;
|
||||||
|
keyboardState.f2Pressed = false;
|
||||||
|
keyboardState.f3Pressed = false;
|
||||||
|
keyboardState.f4Pressed = false;
|
||||||
|
app.getLevel()->update(now - lastUpdate, now-gameStart, glm::vec2(0.0f, 0.0f),
|
||||||
|
&keyboardState);
|
||||||
if (app.isLocked()) {
|
if (app.isLocked()) {
|
||||||
app.ignoredOneMouseUpdate();
|
app.ignoredOneMouseUpdate();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user