cameraTimerOn = false;
gameOver = false;
cameraRotProgress = 0;
- nextWave.tv_sec = 0;
+
if (gameServer != "offline")
{
{
restoreCamera = true;
if (!localPlayer->dead)
- processAction("idle", localPlayer);
+ processAction("idle", localPlayer, false);
}
// set idle animation immediately if stopped walking
!mKeyboard->isKeyDown(OIS::KC_DOWN) &&
!mKeyboard->isKeyDown(OIS::KC_LEFT) &&
!mKeyboard->isKeyDown(OIS::KC_RIGHT))
- processAction("idle", localPlayer);
+ processAction("idle", localPlayer, false);
}
{
mToggle = 0.1;
if (localPlayer->anState->getAnimationName() != "walk" || !localPlayer->anState->getEnabled())
- canWalk = processAction("walk", localPlayer);
+ canWalk = processAction("walk", localPlayer, false);
transVector.z += mMove;
}
{
mToggle = 0.1;
if (localPlayer->anState->getAnimationName() != "walk" || !localPlayer->anState->getEnabled())
- canWalk = processAction("walk", localPlayer);
+ canWalk = processAction("walk", localPlayer, false);
transVector.z -= mMove;
}
{
mToggle = 0.1;
if (localPlayer->anState->getAnimationName() != "walk" || !localPlayer->anState->getEnabled())
- canWalk = processAction("walk", localPlayer);
+ canWalk = processAction("walk", localPlayer, false);
mRotate += DEGREES_PER_SECOND;
}
{
mToggle = 0.1;
if (localPlayer->anState->getAnimationName() != "walk" || !localPlayer->anState->getEnabled())
- canWalk = processAction("walk", localPlayer);
+ canWalk = processAction("walk", localPlayer, false);
mRotate -= DEGREES_PER_SECOND;
}
{
mToggle = 0.1;
if (mKeyboard->isKeyDown(OIS::KC_W))
- processAction("wave", localPlayer);
+ processAction("wave", localPlayer, true);
else if (mKeyboard->isKeyDown(OIS::KC_N)) //nod
- processAction("nod", localPlayer);
+ processAction("nod", localPlayer, false);
else if (mKeyboard->isKeyDown(OIS::KC_P)) // punch
- processAction("punch", localPlayer);
+ processAction("punch", localPlayer, true);
else if (mKeyboard->isKeyDown(OIS::KC_3)) // headshake
- processAction("headshake", localPlayer);
+ processAction("headshake", localPlayer, false);
else if (mKeyboard->isKeyDown(OIS::KC_4)) // headshake
- processAction("rock", localPlayer);
+ processAction("rock", localPlayer, false);
else if (mKeyboard->isKeyDown(OIS::KC_5)) // headshake
- processAction("paper", localPlayer);
+ processAction("paper", localPlayer, false);
else if (mKeyboard->isKeyDown(OIS::KC_6)) // headshake
- processAction("scissors", localPlayer);
+ processAction("scissors", localPlayer, false);
else if (mKeyboard->isKeyDown(OIS::KC_H)) // handshake
{
- processAction("handshake", localPlayer);
+ processAction("handshake", localPlayer, false);
mToggle = 0.5;
}
else if (mKeyboard->isKeyDown(OIS::KC_R))
{
- processAction("rockpaperscissors", localPlayer);
+ processAction("rockpaperscissors", localPlayer, true);
mToggle = 0.9;
}
/*
return true;
}
//-------------------------------------------------------------------------------------
-bool Game::processAction(const String &an, class Player* player)
+bool Game::processAction(const String &an, class Player* player, bool scoreAction)
{
- String curAnimation = player->anState->getAnimationName();
-
- /*if (curAnimation == an && !player->anState->getLoop())
- return false;*/
- /*if ((player == localPlayer && !player->anState->getLoop() && !player->anState->hasEnded()) || localPlayer->cameraChanged)
- return false;*/
-
+
if (player == localPlayer && localPlayer->cameraChanged)
{
cout << "local player and camera changed\n";
}
-
+ if (player == localPlayer && localPlayer->stepsLeft > 0 && scoreAction)
+ {
+ msgBoard->setCaption("Go " + StringConverter::toString(localPlayer->stepsLeft) +
+ " steps away from last action location to perform next action");
+ gettimeofday(&msgTime, NULL);
+ return true;
+ }
if (an == "handshake")
{
adjustCamera = true;
}
if (player == localPlayer)
- updateActionInfo(an);
+ updateActionInfo(an, current->id);
return true;
}
}
}
- for (current = localPlayer; current != NULL; current = current->next)
- {
- if (current != player && predictionHandler->HandshakePosition(player, current) == 2)
- {
- if (player == localPlayer)
- {
- msgBoard->setCaption("Go " +
- StringConverter::toString(current->stepsLeft) +
- " steps away from the player to perform next action");
- gettimeofday(&msgTime, NULL);
- return true;
- }
- }
- }
-
for (current = localPlayer; current != NULL; current = current->next)
{
// requestor is local player and can see another player
adjustCamera = true;
}
if (player == localPlayer)
- updateActionInfo(an);
+ updateActionInfo(an, current->id);
return true;
}
}
- for (current = localPlayer; current != NULL; current = current->next)
- {
- if (current != player && predictionHandler->RockPaperScissorsPosition(player, current) == 2)
- {
- if (player == localPlayer)
- {
- msgBoard->setCaption("Go " +
- StringConverter::toString(current->stepsLeft) +
- " steps away from the player to perform next action");
- gettimeofday(&msgTime, NULL);
- return true;
- }
- }
- }
-
-
for (current = localPlayer; current != NULL; current = current->next)
{
// requestor is local player and can see another player
adjustCamera = true;
}
if (player == localPlayer)
- updateActionInfo(an);
+ updateActionInfo(an, current->id);
return true;
}
}
- for (current = localPlayer; current != NULL; current = current->next)
- {
-
- if (current != player && predictionHandler->PunchPosition(player, current) == 2)
- {
- if (player == localPlayer)
- {
- msgBoard->setCaption("Go " +
- StringConverter::toString(current->stepsLeft) +
- " steps away from the player to perform next action");
- gettimeofday(&msgTime, NULL);
- return true;
- }
- }
- }
-
for (current = localPlayer; current != NULL; current = current->next)
{
// requestor is local player and can see another player
}
else if (an == "wave")
{
- if (!canWave())
- {
- if (player == localPlayer)
- {
- msgBoard->setCaption("You cannot wave more often than once in 3 seconds!");
- gettimeofday(&msgTime, NULL);
- }
- return true;
- }
-
player->playAnimation("wave");
- struct timeval now;
- gettimeofday(&now, NULL);
- struct timeval delay;
- delay.tv_sec = 3;
- delay.tv_usec = 0;
- timeradd(&now, &delay, &nextWave);
-
+
int i;
Player *current;
msgBoard->setCaption("Player " + StringConverter::toString(current->id) + " waved at you");
registerScore(player, current, WAVE);
if (player == localPlayer)
- updateActionInfo(an);
+ updateActionInfo(an, current->id);
return true;
}
}
{
player->playAnimation(an);
if (player == localPlayer)
- updateActionInfo(an);
+ updateActionInfo(an, -1);
}
}
//-------------------------------------------------------------------------------------
-void Game::processActionByPlayerID(const String &an, int id)
+void Game::processActionByPlayerID(const String &an, int id, bool scoreAction)
{
Player *current;
for (current = localPlayer->next; current != NULL; current = current->next)
{
if (current->id == id)
{
- processAction(an, current);
+ processAction(an, current, scoreAction);
break;
}
}
}
//-------------------------------------------------------------------------------------
-void Game::updateActionInfo(const String &an)
+void Game::updateActionInfo(const String &an, int otherplayer)
{
int animation_id;
if (an == "idle")
pthread_mutex_lock(&an_mutex);
animation = animation_id;
+ otherPlayer = otherplayer;
pthread_mutex_unlock(&an_mutex);
pthread_cond_signal(&time2send);
}
memcpy(&sendbuffer[size],(void*)&animation, sizeof(int));
if (animation == 7 || animation == 8 || animation == 5)
animation = 0;
+
// cout << "sent animation " << send << "\n\n\n\n\n\n";
+ size += sizeof(int);
+ memcpy(&sendbuffer[size],(void*)&otherPlayer, sizeof(int));
pthread_mutex_unlock(&an_mutex);
size += sizeof(int);
client->sendMessage(sendbuffer, size);
}
memcpy(&tp,&recvbuffer[sizeread], sizeof(struct timeval));
- sizeread += sizeof(struct timeval);
- memcpy(&pos, &recvbuffer[sizeread], sizeof(Vector3));
- //cout << pos << "\n";
- sizeread += sizeof(Vector3);
+ sizeread += sizeof(struct timeval);
+ int x,z;
+ memcpy(&x,&recvbuffer[sizeread], sizeof(int));
+ sizeread += sizeof(int);
+ memcpy(&z,&recvbuffer[sizeread], sizeof(int));
+ sizeread += sizeof(int);
+ pos.x = x;
+ pos.y = 100.5;
+ pos.z = z;
memcpy(&orient, &recvbuffer[sizeread], sizeof(Quaternion));
//cout << orient << "\n";
sizeread += sizeof(Quaternion);
sizeread += sizeof(int);
//cout << an << "\n";
- class update newUpd;
- newUpd.id = pid;
- newUpd.pos = pos;
- newUpd.orient = orient;
- newUpd.timestamp = tp;
- newUpd.an = an;
+ class update newUpd;
+ newUpd.id = pid;
+ newUpd.pos = pos;
+ newUpd.orient = orient;
+ newUpd.timestamp = tp;
+ newUpd.an = an;
- struct timeval now;
- gettimeofday(&now, NULL);
- struct timeval delay;
- delay.tv_sec = delay_ms/1000;
- delay.tv_usec = (delay_ms % 1000) *1000;
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ struct timeval delay;
+ delay.tv_sec = delay_ms/1000;
+ delay.tv_usec = (delay_ms % 1000) *1000;
/* cout << "now secs before: " << now.tv_sec << "\n";
cout << "now usecs before: " << now.tv_usec << "\n";
cout << delay.tv_usec << ": delay microseconds\n";*/
- timeradd(&now, &delay, &newUpd.delayed);
+ timeradd(&now, &delay, &newUpd.delayed);
/* cout << "delayed secs after: " << newUpd.delayed.tv_sec << "\n";
cout << "delayed usecs after: " << newUpd.delayed.tv_usec << "\n";*/
- pthread_mutex_lock(&updatesqueue_mutex);
- updates.push_back(newUpd);
- pthread_mutex_unlock(&updatesqueue_mutex);
- pthread_cond_signal(&delay_start);
+ pthread_mutex_lock(&updatesqueue_mutex);
+ updates.push_back(newUpd);
+ pthread_mutex_unlock(&updatesqueue_mutex);
+ pthread_cond_signal(&delay_start);
- }
+ }
}
}
return true;
}
//-------------------------------------------------------------------------------------
-bool Game::canWave()
-{
- if (nextWave.tv_sec == 0)
- return true;
- struct timeval now;
- gettimeofday(&now, NULL);
- if (timercmp(&nextWave, &now, >))
- return false;
- else
- return true;
-}
+
void Game::setPlayerStateUpdate()
{
pthread_mutex_lock(&players_mutex);
{
case 1:
// cout << "idle\n";
- processActionByPlayerID("idle", newUpdate.id);
+ processActionByPlayerID("idle", newUpdate.id, false);
break;
case 2:
// cout << "walk\n";
- processActionByPlayerID("walk", newUpdate.id);
+ processActionByPlayerID("walk", newUpdate.id, false);
break;
case 3:
cout << "wave\n";
- processActionByPlayerID("wave", newUpdate.id);
+ processActionByPlayerID("wave", newUpdate.id, true);
break;
case 4:
cout << "nod\n";
- processActionByPlayerID("nod", newUpdate.id);
+ processActionByPlayerID("nod", newUpdate.id, false);
break;
case 5:
cout << "punch\n";
- processActionByPlayerID("punch", newUpdate.id);
+ processActionByPlayerID("punch", newUpdate.id, true);
break;
case 6:
cout << "headshake\n";
- processActionByPlayerID("headshake", newUpdate.id);
+ processActionByPlayerID("headshake", newUpdate.id, false);
break;
case 7:
cout << "handshake\n";
- processActionByPlayerID("handshake", newUpdate.id);
+ processActionByPlayerID("handshake", newUpdate.id, true);
break;
case 8:
cout << "rps\n";
- processActionByPlayerID("rockpaperscissors", newUpdate.id);
+ processActionByPlayerID("rockpaperscissors", newUpdate.id, true);
default:
break;
void Game::printStepsLeft()
{
- std::string caption = "Steps left:";
-
- Player *current;
- for (current = localPlayer->next; current != NULL; current = current->next)
- {
- if (current->stepsLeft > 0)
- {
- Real distance = localPlayer->playerNode->_getDerivedPosition().distance(
- current->playerNode->_getDerivedPosition());
- if (distance < STEPS)
- if (distance < current->stepsLeft)
- current->stepsLeft = STEPS - distance;
- else
- current->stepsLeft = 0;
- if (current->stepsLeft < 50)
- current->stepsLeft = 0;
+ std::string caption = "Steps left: ";
- }
- caption = caption + " P" + StringConverter::toString(current->id) +
- ":" + StringConverter::toString(current->stepsLeft);
- }
+ Real distance = localPlayer->lastActionLocation.distance(localPlayer->playerNode->_getDerivedPosition());
+ localPlayer->stepsLeft = STEPS - distance;
+ caption = caption + StringConverter::toString(localPlayer->stepsLeft);
+
stepsBoard->setCaption(caption);
}
playerB->dead = true;
}
- if (action == 8)
+
+
+ if (playerA == localPlayer)
{
- if (playerA == localPlayer)
- playerB->stepsLeft = STEPS+500;
- else
- playerA->stepsLeft = STEPS+500;
+ playerA->lastActionLocation = localPlayer->playerNode->_getDerivedPosition();
+ playerA->stepsLeft = STEPS;
}
- else
+
+ else if (playerB == localPlayer)
{
- if (playerA == localPlayer)
- playerB->stepsLeft = STEPS;
- else
- playerA->stepsLeft = STEPS;
+ playerB->lastActionLocation = localPlayer->playerNode->_getDerivedPosition();
+ playerB->stepsLeft = STEPS;
}
-
+
+
printPlayerScore();
}