camera movement fixed

This commit is contained in:
Titus Tscharntke 2011-04-11 23:26:50 +00:00
parent 1acc011ebc
commit 4df5e0266c
2 changed files with 51 additions and 23 deletions

View File

@ -95,7 +95,11 @@ Game::Game(Program *program, const GameSettings *gameSettings):
renderNetworkStatus= false; renderNetworkStatus= false;
speed= sNormal; speed= sNormal;
showFullConsole= false; showFullConsole= false;
cameraKeyboardDirection=camNone;
camLeftButtonDown=false;
camRightButtonDown=false;
camUpButtonDown=false;
camDownButtonDown=false;
Object::setStateCallback(&gui); Object::setStateCallback(&gui);
@ -1301,7 +1305,7 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
else { else {
//main window //main window
//if(Window::isKeyDown() == false) //if(Window::isKeyDown() == false)
if(cameraKeyboardDirection == camNone) if(!camLeftButtonDown && !camRightButtonDown && !camUpButtonDown && !camDownButtonDown)
{ {
if (y < 10) { if (y < 10) {
gameCamera.setMoveZ(-scrollSpeed); gameCamera.setMoveZ(-scrollSpeed);
@ -1436,22 +1440,22 @@ void Game::keyDown(char key) {
//move camera left //move camera left
else if(key == configKeys.getCharKey("CameraModeLeft")) { else if(key == configKeys.getCharKey("CameraModeLeft")) {
gameCamera.setMoveX(-1); gameCamera.setMoveX(-1);
cameraKeyboardDirection=camLeft; camLeftButtonDown=true;
} }
//move camera right //move camera right
else if(key == configKeys.getCharKey("CameraModeRight")) { else if(key == configKeys.getCharKey("CameraModeRight")) {
gameCamera.setMoveX(1); gameCamera.setMoveX(1);
cameraKeyboardDirection=camRight; camRightButtonDown=true;
} }
//move camera up //move camera up
else if(key == configKeys.getCharKey("CameraModeUp")) { else if(key == configKeys.getCharKey("CameraModeUp")) {
gameCamera.setMoveZ(1); gameCamera.setMoveZ(1);
cameraKeyboardDirection=camUp; camUpButtonDown=true;
} }
//move camera down //move camera down
else if(key == configKeys.getCharKey("CameraModeDown")) { else if(key == configKeys.getCharKey("CameraModeDown")) {
gameCamera.setMoveZ(-1); gameCamera.setMoveZ(-1);
cameraKeyboardDirection=camDown; camDownButtonDown=true;
} }
//change camera mode //change camera mode
else if(key == configKeys.getCharKey("FreeCameraMode")) { else if(key == configKeys.getCharKey("FreeCameraMode")) {
@ -1574,22 +1578,26 @@ void Game::keyUp(char key){
key == configKeys.getCharKey("CameraRotateUp")) { key == configKeys.getCharKey("CameraRotateUp")) {
gameCamera.setMoveY(0); gameCamera.setMoveY(0);
} }
else if(key == configKeys.getCharKey("CameraModeUp") && cameraKeyboardDirection == camUp){ else if(key == configKeys.getCharKey("CameraModeUp")){
gameCamera.setMoveZ(0); gameCamera.setMoveZ(0);
cameraKeyboardDirection= camNone; camUpButtonDown= false;
calcCameraMoveZ();
} }
else if(key == configKeys.getCharKey("CameraModeDown") && cameraKeyboardDirection == camDown){ else if(key == configKeys.getCharKey("CameraModeDown")){
gameCamera.setMoveZ(0); gameCamera.setMoveZ(0);
cameraKeyboardDirection= camNone; camDownButtonDown= false;
calcCameraMoveZ();
} }
else if(key == configKeys.getCharKey("CameraModeLeft") && cameraKeyboardDirection == camLeft){ else if(key == configKeys.getCharKey("CameraModeLeft")){
gameCamera.setMoveX(0); gameCamera.setMoveX(0);
cameraKeyboardDirection= camNone; camLeftButtonDown= false;
calcCameraMoveX();
} }
else if(key == configKeys.getCharKey("CameraModeRight") && cameraKeyboardDirection == camRight){ else if(key == configKeys.getCharKey("CameraModeRight")){
gameCamera.setMoveX(0); gameCamera.setMoveX(0);
cameraKeyboardDirection= camNone; camRightButtonDown= false;
calcCameraMoveX();
} }
} }
} }
@ -1604,6 +1612,28 @@ void Game::keyUp(char key){
} }
} }
void Game::calcCameraMoveX(){
//move camera left
if(camLeftButtonDown == true){
gameCamera.setMoveX(-1);
}
//move camera right
else if(camRightButtonDown == true){
gameCamera.setMoveX(1);
}
}
void Game::calcCameraMoveZ(){
//move camera up
if(camUpButtonDown == true){
gameCamera.setMoveZ(1);
}
//move camera down
else if(camDownButtonDown == true){
gameCamera.setMoveZ(-1);
}
}
void Game::keyPress(char c){ void Game::keyPress(char c){
if(gameStarted == false) { if(gameStarted == false) {
return; return;

View File

@ -63,14 +63,6 @@ private:
typedef vector<Ai*> Ais; typedef vector<Ai*> Ais;
typedef vector<AiInterface*> AiInterfaces; typedef vector<AiInterface*> AiInterfaces;
enum CameraKeyboardDirection{
camNone,
camLeft,
camRight,
camUp,
camDown
};
private: private:
//main data //main data
World world; World world;
@ -96,7 +88,11 @@ private:
bool showFullConsole; bool showFullConsole;
bool mouseMoved; bool mouseMoved;
float scrollSpeed; float scrollSpeed;
CameraKeyboardDirection cameraKeyboardDirection; bool camLeftButtonDown;
bool camRightButtonDown;
bool camUpButtonDown;
bool camDownButtonDown;
Speed speed; Speed speed;
GraphicMessageBox mainMessageBox; GraphicMessageBox mainMessageBox;
GraphicMessageBox errorMessageBox; GraphicMessageBox errorMessageBox;
@ -216,6 +212,8 @@ private:
static int ErrorDisplayMessage(const char *msg, bool exitApp); static int ErrorDisplayMessage(const char *msg, bool exitApp);
void ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRole role); void ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRole role);
void calcCameraMoveX();
void calcCameraMoveZ();
}; };
}}//end namespace }}//end namespace