git repos / saland

commit e2fac1ee

sago007 · 2018-12-21 15:00
e2fac1ee209feb6b6130db51ed34df9e24008f8b patch · browse files
parent f3711c9d1838ea151d383fbc99aa3ae5722bd37d

Start moving player controls to variables instead of being hardcoded.

Changed files

M src/saland/Game.cpp before
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index eabf009..dd133b5 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -43,6 +43,16 @@ https://github.com/sago007/saland
int32 velocityIterations = 6;
int32 positionIterations = 2;
+struct PlayerControls {
+ SDL_Scancode move_up = SDL_SCANCODE_UP;
+ SDL_Scancode move_down = SDL_SCANCODE_DOWN;
+ SDL_Scancode move_left = SDL_SCANCODE_LEFT;
+ SDL_Scancode move_right = SDL_SCANCODE_RIGHT;
+};
+
+PlayerControls playerControls;
+
+
typedef std::pair<float,float> SpawnPoint;
/**
@@ -285,16 +295,16 @@ void Game::Update() {
float deltaX = 0.0f;
float deltaY = 0.0f;
if (!data->c) {
- if (state[SDL_SCANCODE_DOWN]) {
+ if (state[playerControls.move_down]) {
deltaY += 1.0f;
}
- if (state[SDL_SCANCODE_UP]) {
+ if (state[playerControls.move_up]) {
deltaY -= 1.0f;
}
- if (state[SDL_SCANCODE_RIGHT]) {
+ if (state[playerControls.move_right]) {
deltaX += 1.0f;
}
- if (state[SDL_SCANCODE_LEFT]) {
+ if (state[playerControls.move_left]) {
deltaX -= 1.0f;
}
}