[Orxonox-commit 4224] r8895 - code/branches/gamecontent/src/modules/pong
jo at orxonox.net
jo at orxonox.net
Thu Oct 13 20:59:27 CEST 2011
Author: jo
Date: 2011-10-13 20:59:27 +0200 (Thu, 13 Oct 2011)
New Revision: 8895
Modified:
code/branches/gamecontent/src/modules/pong/Pong.cc
code/branches/gamecontent/src/modules/pong/Pong.h
code/branches/gamecontent/src/modules/pong/PongAI.h
Log:
Added end to pong gametype. Unfortunately the hud isn't consistent at the game's end at the moment.
Modified: code/branches/gamecontent/src/modules/pong/Pong.cc
===================================================================
--- code/branches/gamecontent/src/modules/pong/Pong.cc 2011-10-12 19:48:04 UTC (rev 8894)
+++ code/branches/gamecontent/src/modules/pong/Pong.cc 2011-10-13 18:59:27 UTC (rev 8895)
@@ -38,13 +38,13 @@
#include "core/command/Executor.h"
#include "gamestates/GSLevel.h"
+#include "chat/ChatManager.h"
#include "PongCenterpoint.h"
#include "PongBall.h"
#include "PongBat.h"
#include "PongBot.h"
#include "PongAI.h"
-
namespace orxonox
{
// Events to allow to react to scoring of a player, in the level-file.
@@ -74,6 +74,7 @@
// Set the type of Bots for this particular Gametype.
this->botclass_ = Class(PongBot);
+ this->scoreLimit_ = 3; //TODO: 21
}
/**
@@ -279,8 +280,28 @@
this->bat_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
}
+ // If a palyer gets 21 points, he won the game -> end of game
+
+ PlayerInfo* player1 = this->getLeftPlayer();
+ PlayerInfo* player2 = this->getRightPlayer();
+ if(player1==NULL||player2==NULL) return; //safety
+ if(this->getScore(player1) >= scoreLimit_)
+ {
+ std::string name1=player1->getName();
+ std::string message(name1 + " has won!");
+ ChatManager::message(message);
+ this->end();
+ }
+ else if(this->getScore(player2) >= scoreLimit_)
+ {
+ std::string name2=player2->getName();
+ std::string message2(name2 + " has won!");
+ ChatManager::message(message2);
+ this->end();
+ }
// Restart the timer to start the ball.
this->starttimer_.startTimer();
+
}
/**
Modified: code/branches/gamecontent/src/modules/pong/Pong.h
===================================================================
--- code/branches/gamecontent/src/modules/pong/Pong.h 2011-10-12 19:48:04 UTC (rev 8894)
+++ code/branches/gamecontent/src/modules/pong/Pong.h 2011-10-13 18:59:27 UTC (rev 8895)
@@ -93,7 +93,8 @@
WeakPtr<PongCenterpoint> center_; //!< The playing field.
WeakPtr<PongBall> ball_; //!< The Pong ball.
WeakPtr<PongBat> bat_[2]; //!< The two bats.
- Timer starttimer_; //!< A timer to delay the start of the game.
+ Timer starttimer_; //!< A timer to delay the start of the game.
+ int scoreLimit_; //!< If a player scored that much points, the game is ended.
};
}
Modified: code/branches/gamecontent/src/modules/pong/PongAI.h
===================================================================
--- code/branches/gamecontent/src/modules/pong/PongAI.h 2011-10-12 19:48:04 UTC (rev 8894)
+++ code/branches/gamecontent/src/modules/pong/PongAI.h 2011-10-13 18:59:27 UTC (rev 8895)
@@ -79,7 +79,7 @@
void move(char direction, bool bUseDelay); //!< Determine the movement the AI will undertake.
void delayedMove(); //!< Is called, when a delayed move takes effect.
- PongBall* ball_; //!< A pointer to the ball.
+ WeakPtr<PongBall> ball_; //!< A weak pointer to the ball.
Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying.
float ballEndPosition_; //!< The calculated end position of the ball.
float randomOffset_; //!< A random offset to introduce random errors (weighted by the strength of the AI) into the AI's behavior.
More information about the Orxonox-commit
mailing list