Skip to content

Commit

Permalink
Merge branch 'feature-issue-44' into develop
Browse files Browse the repository at this point in the history
Issue 44 is related to RobotManager support in the different game states.
  • Loading branch information
David-Estevez committed May 12, 2016
2 parents 45f72ca + 66bf39b commit 8eb14b2
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 85 deletions.
5 changes: 5 additions & 0 deletions src/libraries/GameStatesLib/DeadState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ bool rd::DeadState::setup()
audioManager->stopMusic();
audioManager->play("RD_DEAD");

//-- Disable robot controls
robotManager->setEnabled(false);

return true;
}

Expand Down Expand Up @@ -112,6 +115,8 @@ bool rd::DeadState::cleanup()
audioManager->stop();
networkManager->logout(mentalMap->getMyself()); //-- This is kind of weird, but it is supposed to be done like this
networkManager->stop();
robotManager->setEnabled(false);
robotManager->disconnect();
return true;
}
else
Expand Down
57 changes: 56 additions & 1 deletion src/libraries/GameStatesLib/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ bool rd::GameState::setup()
return false;
}

//-- Robot Startup goes here
//-- Robot Startup
robotManager->setEnabled(true);

//-- Show Robot Devastation game screen:
//-- Set info elements on GameScreen
Expand Down Expand Up @@ -103,6 +104,8 @@ bool rd::GameState::cleanup()
audioManager->stop();
networkManager->logout(mentalMap->getMyself()); //-- This is kind of weird, but it is supposed to be done like this
networkManager->stop();
robotManager->setEnabled(false);
robotManager->disconnect();
return true;
}
else
Expand Down Expand Up @@ -142,11 +145,63 @@ bool rd::GameState::onKeyDown(rd::RdKey k)
return true;
}

//-- Movement control
if (k.getValue() == RdKey::KEY_ARROW_LEFT)
{
RD_DEBUG("Left arrow was pressed!\n");
robotManager->turnLeft();
return true;
}
if (k.getValue() == RdKey::KEY_ARROW_RIGHT)
{
RD_DEBUG("Right arrow was pressed!\n");
robotManager->turnRight();
return true;
}
if (k.getValue() == RdKey::KEY_ARROW_UP)
{
RD_DEBUG("Up arrow was pressed!\n");
robotManager->moveForward();
return true;
}
if (k.getValue() == RdKey::KEY_ARROW_DOWN)
{
RD_DEBUG("Down arrow was pressed!\n");
robotManager->moveBackwards();
return true;
}

return false;
}

bool rd::GameState::onKeyUp(rd::RdKey k)
{
//-- Movement control
if (k.getValue() == RdKey::KEY_ARROW_LEFT)
{
RD_DEBUG("Left arrow was released!\n");
robotManager->stopMovement();
return true;
}
if (k.getValue() == RdKey::KEY_ARROW_RIGHT)
{
RD_DEBUG("Right arrow was released!\n");
robotManager->stopMovement();
return true;
}
if (k.getValue() == RdKey::KEY_ARROW_UP)
{
RD_DEBUG("Up arrow was released!\n");
robotManager->stopMovement();
return true;
}
if (k.getValue() == RdKey::KEY_ARROW_DOWN)
{
RD_DEBUG("Down arrow was released!\n");
robotManager->stopMovement();
return true;
}

return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/GameStatesLib/InitState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bool rd::InitState::loop()
{
//-- Log in
networkManager->login(mentalMap->getMyself());
robotManager->connect();
robotManager->setEnabled(false);
logged_in = true;
}

Expand Down
22 changes: 22 additions & 0 deletions src/libraries/RdInputLib/MockupInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ bool rd::MockupInputManager::sendKeyPress(RdKey key)
return true;
}

bool rd::MockupInputManager::sendKeyUp(rd::RdKey key)
{
if (stopped)
return false;

for ( int i = 0; i < (int)listeners.size(); i++)
listeners.at(i)->onKeyUp(key);

return true;
}

bool rd::MockupInputManager::sendKeyDown(rd::RdKey key)
{
if (stopped)
return false;

for ( int i = 0; i < (int)listeners.size(); i++)
listeners.at(i)->onKeyDown(key);

return true;
}

rd::MockupInputManager::MockupInputManager()
{
stopped = true;
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/RdInputLib/MockupInputManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class MockupInputManager : public RdInputManager
public:
//------------------------------ Testing Interface ------------------------------------------------------------//
bool sendKeyPress(RdKey key);
bool sendKeyUp(RdKey key);
bool sendKeyDown(RdKey key);

//------------------------------ Construction & destruction ---------------------------------------------------//
MockupInputManager();
Expand Down
138 changes: 115 additions & 23 deletions src/libraries/RdRobotLib/RdMockupRobotManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace rd
RdMockupRobotManager:: RdMockupRobotManager(const std::string& robotName): RdRobotManager(robotName)
{
connected = false;
enabled = false;
movement_direction = NONE;
camera_movement_direction = CAMERA_NONE;
}
Expand All @@ -27,8 +28,16 @@ bool RdMockupRobotManager::moveForward(int velocity)
{
if (connected)
{
movement_direction = FORWARD;
return true;
if (enabled)
{
movement_direction = FORWARD;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -41,8 +50,16 @@ bool RdMockupRobotManager::moveBackwards(int velocity)
{
if (connected)
{
movement_direction = BACKWARDS;
return true;
if (enabled)
{
movement_direction = BACKWARDS;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -55,8 +72,16 @@ bool RdMockupRobotManager::turnLeft(int velocity)
{
if (connected)
{
movement_direction = LEFT;
return true;
if (enabled)
{
movement_direction = LEFT;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -69,8 +94,16 @@ bool RdMockupRobotManager::turnRight(int velocity)
{
if (connected)
{
movement_direction = RIGHT;
return true;
if (enabled)
{
movement_direction = RIGHT;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -83,8 +116,16 @@ bool RdMockupRobotManager::stopMovement()
{
if (connected)
{
movement_direction = NONE;
return true;
if (enabled)
{
movement_direction = NONE;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -97,8 +138,16 @@ bool RdMockupRobotManager::tiltUp(int velocity)
{
if (connected)
{
camera_movement_direction = CAMERA_UP;
return true;
if (enabled)
{
camera_movement_direction = CAMERA_UP;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -111,8 +160,16 @@ bool RdMockupRobotManager::tiltDown(int velocity)
{
if (connected)
{
camera_movement_direction = CAMERA_DOWN;
return true;
if (enabled)
{
camera_movement_direction = CAMERA_DOWN;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -125,8 +182,16 @@ bool RdMockupRobotManager::panLeft(int velocity)
{
if (connected)
{
camera_movement_direction = CAMERA_LEFT;
return true;
if (enabled)
{
camera_movement_direction = CAMERA_LEFT;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -139,8 +204,16 @@ bool RdMockupRobotManager::panRight(int velocity)
{
if (connected)
{
camera_movement_direction = CAMERA_RIGHT;
return true;
if (enabled)
{
camera_movement_direction = CAMERA_RIGHT;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand All @@ -153,8 +226,16 @@ bool RdMockupRobotManager::stopCameraMovement()
{
if (connected)
{
camera_movement_direction = NONE;
return true;
if (enabled)
{
camera_movement_direction = NONE;
return true;
}
else
{
RD_ERROR("Robot is disabled\n");
return false;
}
}
else
{
Expand Down Expand Up @@ -196,9 +277,15 @@ bool RdMockupRobotManager::test() {
return false;
}

bool RdMockupRobotManager::ping() {
RD_DEBUG("\n");
return false;
void RdMockupRobotManager::setEnabled(bool enabled)
{
this->enabled = enabled;
if (enabled)
{
RD_DEBUG("RdMockupRobotManager enabled\n");
}
else
RD_DEBUG("RdMockupRobotManager disabled\n");
}

void RdMockupRobotManager::onDestroy(){
Expand All @@ -211,6 +298,11 @@ bool RdMockupRobotManager::isConnected()
return connected;
}

bool RdMockupRobotManager::isEnabled()
{
return enabled;
}

bool RdMockupRobotManager::isMoving()
{
return movement_direction!=NONE;
Expand Down
Loading

0 comments on commit 8eb14b2

Please sign in to comment.