From daf8f42f7e96f549d0dfd4218aecb84a363ffb0e Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Sun, 10 Apr 2011 21:38:29 +0000 Subject: [PATCH] real camera movement! --- source/glest_game/game/game.cpp | 23 +++++++++++++++++++---- source/glest_game/game/game.h | 9 +++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index b18088b3..b4b45582 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -95,6 +95,7 @@ Game::Game(Program *program, const GameSettings *gameSettings): renderNetworkStatus= false; speed= sNormal; showFullConsole= false; + cameraKeyboardDirection=camNone; Object::setStateCallback(&gui); @@ -1300,6 +1301,7 @@ void Game::mouseMove(int x, int y, const MouseState *ms) { else { //main window //if(Window::isKeyDown() == false) + if(cameraKeyboardDirection == camNone) { if (y < 10) { gameCamera.setMoveZ(-scrollSpeed); @@ -1434,18 +1436,22 @@ void Game::keyDown(char key) { //move camera left else if(key == configKeys.getCharKey("CameraModeLeft")) { gameCamera.setMoveX(-1); + cameraKeyboardDirection=camLeft; } //move camera right else if(key == configKeys.getCharKey("CameraModeRight")) { gameCamera.setMoveX(1); + cameraKeyboardDirection=camRight; } //move camera up else if(key == configKeys.getCharKey("CameraModeUp")) { gameCamera.setMoveZ(1); + cameraKeyboardDirection=camUp; } //move camera down else if(key == configKeys.getCharKey("CameraModeDown")) { gameCamera.setMoveZ(-1); + cameraKeyboardDirection=camDown; } //change camera mode else if(key == configKeys.getCharKey("FreeCameraMode")) { @@ -1568,13 +1574,22 @@ void Game::keyUp(char key){ key == configKeys.getCharKey("CameraRotateUp")) { gameCamera.setMoveY(0); } - else if(key == configKeys.getCharKey("CameraModeUp") || - key == configKeys.getCharKey("CameraModeDown")) { + else if(key == configKeys.getCharKey("CameraModeUp") && cameraKeyboardDirection == camUp){ gameCamera.setMoveZ(0); + cameraKeyboardDirection= camNone; } - else if(key == configKeys.getCharKey("CameraModeLeft") || - key == configKeys.getCharKey("CameraModeRight")) { + else if(key == configKeys.getCharKey("CameraModeDown") && cameraKeyboardDirection == camDown){ + gameCamera.setMoveZ(0); + cameraKeyboardDirection= camNone; + } + + else if(key == configKeys.getCharKey("CameraModeLeft") && cameraKeyboardDirection == camLeft){ gameCamera.setMoveX(0); + cameraKeyboardDirection= camNone; + } + else if(key == configKeys.getCharKey("CameraModeRight") && cameraKeyboardDirection == camRight){ + gameCamera.setMoveX(0); + cameraKeyboardDirection= camNone; } } } diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 6efc5784..95994ea6 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -63,6 +63,14 @@ private: typedef vector Ais; typedef vector AiInterfaces; + enum CameraKeyboardDirection{ + camNone, + camLeft, + camRight, + camUp, + camDown + }; + private: //main data World world; @@ -88,6 +96,7 @@ private: bool showFullConsole; bool mouseMoved; float scrollSpeed; + CameraKeyboardDirection cameraKeyboardDirection; Speed speed; GraphicMessageBox mainMessageBox; GraphicMessageBox errorMessageBox;