[Orxonox-commit 5377] r10040 - code/branches/pickupsFS14/src/modules/jump
fvultier at orxonox.net
fvultier at orxonox.net
Thu Apr 17 16:29:25 CEST 2014
Author: fvultier
Date: 2014-04-17 16:29:25 +0200 (Thu, 17 Apr 2014)
New Revision: 10040
Modified:
code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt
code/branches/pickupsFS14/src/modules/jump/Jump.cc
code/branches/pickupsFS14/src/modules/jump/Jump.h
code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc
code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h
code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h
Log:
Bewegung mit WASD und Absprung von einer Platform in der Mitte funktioniert.
Modified: code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt 2014-04-17 14:05:06 UTC (rev 10039)
+++ code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt 2014-04-17 14:29:25 UTC (rev 10040)
@@ -1,9 +1,12 @@
-SET_SOURCE_FILES(Jump_SRC_FILES
+SET_SOURCE_FILES(JUMP_SRC_FILES
BUILD_UNIT JumpBuildUnit.cc
Jump.cc
- JumpCenterPoint.cc
- JumpShip.cc
JumpPlatform.cc
+ JumpPlatformHMove.cc
+ JumpPlatformVMove.cc
+ JumpFigure.cc
+ JumpCenterpoint.cc
+ JumpScore.cc
END_BUILD_UNIT
)
@@ -13,6 +16,5 @@
LINK_LIBRARIES
orxonox
overlays
- weapons
- SOURCE_FILES ${Jump_SRC_FILES}
+ SOURCE_FILES ${JUMP_SRC_FILES}
)
Modified: code/branches/pickupsFS14/src/modules/jump/Jump.cc
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/Jump.cc 2014-04-17 14:05:06 UTC (rev 10039)
+++ code/branches/pickupsFS14/src/modules/jump/Jump.cc 2014-04-17 14:29:25 UTC (rev 10040)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Florian Zinggeler
+ * Fabian 'x3n' Landau
* Co-authors:
* ...
*
@@ -32,6 +32,7 @@
*/
#include "Jump.h"
+
#include "core/CoreIncludes.h"
#include "core/EventIncludes.h"
#include "core/command/Executor.h"
@@ -40,198 +41,316 @@
#include "gamestates/GSLevel.h"
#include "chat/ChatManager.h"
-// ! HACK
+#include "JumpCenterpoint.h"
+#include "JumpPlatform.h"
+#include "JumpFigure.h"
+
#include "infos/PlayerInfo.h"
-#include "JumpCenterPoint.h"
-#include "JumpShip.h"
-/*
-#include "JumpEnemy.h"
-#include "JumpEnemyShooter.h"*/
-
-#include "core/command/ConsoleCommand.h"
-#include "worldentities/BigExplosion.h"
-
namespace orxonox
{
+ // Events to allow to react to scoring of a player, in the level-file.
+ CreateEventName(JumpCenterpoint, right);
+ CreateEventName(JumpCenterpoint, left);
+
RegisterUnloadableClass(Jump);
+ /**
+ @brief
+ Constructor. Registers and initializes the object.
+ */
Jump::Jump(Context* context) : Deathmatch(context)
{
RegisterObject(Jump);
- platformList.clear();
- yScreenPosition = 0;
- screenShiftSinceLastUpdate = 0;
- //this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
- //this->center_ = 0;
+ this->center_ = 0;
+ this->ball_ = 0;
+ this->figure_ = 0;
+ this->camera = 0;
+
//this->setHUDTemplate("JumpHUD");
+ // Pre-set the timer, but don't start it yet.
+ this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Jump::startBall, this)));
+ this->starttimer_.stopTimer();
+
+ this->scoreLimit_ = 10;
+ this->setConfigValues();
}
-
- /*void Jump::levelUp()
+ /**
+ @brief
+ Destructor. Cleans up, if initialized.
+ */
+ Jump::~Jump()
{
- level++;
- if (getPlayer() != NULL)
+ if (this->isInitialized())
{
- for (int i = 0; i < 7; i++)
- {
- WeakPtr<BigExplosion> chunk = new BigExplosion(this->center_->getContext());
- chunk->setPosition(Vector3(600, 0, 100.f * i - 300));
- chunk->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity()
- chunk->setScale(20);
- }
+ this->cleanup();
}
- addPoints(multiplier * 42);
- multiplier *= 2;
- toggleShowLevel();
- showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Jump::toggleShowLevel, this)));
- }*/
-
- WeakPtr<JumpShip> Jump::getPlayer()
- {
- if (player == NULL)
- {
- for (ObjectList<JumpShip>::iterator it = ObjectList<JumpShip>::begin(); it != ObjectList<JumpShip>::end(); ++it)
- {
- player = *it;
- }
- }
- return player;
}
void Jump::tick(float dt)
{
+ SUPER(Jump, tick, dt);
+ if (figure_ != NULL)
+ {
+ Vector3 figurePosition = figure_->getPosition();
- if (getPlayer() != NULL)
- {
- Vector3 shipPosition = getPlayer()->getPosition();
+ if (figurePosition.z > totalScreenShift)
+ {
+ totalScreenShift = figurePosition.z;
+ }
- // Bildschirmposition kann nur nach oben verschoben werden
- if (shipPosition.y > yScreenPosition)
- {
- screenShiftSinceLastUpdate += shipPosition.y - yScreenPosition;
+ if (this->camera != NULL)
+ {
+ Vector3 cameraPosition = Vector3(0,totalScreenShift,0);
+ camera->setPosition(cameraPosition);
+ }
+ else
+ {
+ orxout() << "no camera found" << endl;
+ //this->camera = this->figure_->getCamera();
+ }
+ }
- yScreenPosition = shipPosition.y;
- }
- // Kameraposition nachfuehren
- if (camera == NULL)
- {
- camera = getPlayer()->getCamera();
- }
- if (camera != NULL)
- {
- camera->setPosition(Vector3(-shipPosition.x, yScreenPosition-shipPosition.y, 100));
- //camera->setOrientation(Vector3::UNIT_Z, Degree(180));
- }
- if (screenShiftSinceLastUpdate > 200.0)
- {
- screenShiftSinceLastUpdate -= 200.0;
- orxout() << "new section added" << endl;
- addPlatform(shipPosition.x, shipPosition.y + 300.0);
- }
- }
- SUPER(Jump, tick, dt);
}
- /*void Jump::spawnEnemy()
+ void Jump::setConfigValues()
{
- if (getPlayer() == NULL)
- return;
+ SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
+ }
- for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
+ /**
+ @brief
+ Cleans up the Gametype by destroying the ball and the bats.
+ */
+ void Jump::cleanup()
+ {
+ if (this->ball_ != NULL) // Destroy the ball, if present.
{
- WeakPtr<JumpEnemy> newPawn;
- if (rand() % 42/(1 + level*level) == 0)
- {
- newPawn = new JumpEnemyShooter(this->center_->getContext());
- newPawn->addTemplate("enemyjumpshooter");
- }
- else
- {
- newPawn = new JumpEnemy(this->center_->getContext());
- newPawn->addTemplate("enemyjump");
- }
- newPawn->setPlayer(player);
- newPawn->level = level;
- // spawn enemy at random points in front of player.
- newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
+ this->ball_->destroy();
+ this->ball_ = 0;
}
- }*/
- /*void Jump::costLife()
- {
- lives--;
- multiplier = 1;
- // end the game in 30 seconds.
- if (lives <= 0)
- enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&Jump::end, this)));
- };*/
+ // Destroy both bats, if present.
+ if (this->figure_ != NULL)
+ {
+ this->figure_->destroy();
+ this->figure_ = 0;
+ }
+ this->camera = 0;
+ }
- /*void Jump::comboControll()
+ /**
+ @brief
+ Starts the Jump minigame.
+ */
+ void Jump::start()
{
- if (b_combo)
- multiplier++;
- // if no combo was performed before, reset multiplier
- else
- multiplier = 1;
- b_combo = false;
- }*/
+ if (this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place.
+ {
+ if (this->ball_ == NULL) // If there is no ball, create a new ball.
+ {
+ this->ball_ = new JumpPlatform(this->center_->getContext());
+ // Apply the template for the ball specified by the centerpoint.
+ this->ball_->addTemplate(this->center_->getBalltemplate());
+ }
+ // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
+ this->center_->attach(this->ball_);
+ this->ball_->setPosition(0, 0, 0);
+ this->ball_->setFieldDimension(this->center_->getFieldDimension());
- void Jump::start()
- {
- // Call start for the parent class.
- Deathmatch::start();
+ // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
+ if (this->figure_ == NULL)
+ {
+ this->figure_ = new JumpFigure(this->center_->getContext());
+ this->figure_->addTemplate(this->center_->getBattemplate());
+ }
- /*
- // Set variable to temporarily force the player to spawn.
- this->bForceSpawn_ = true;
+ // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to.
+ this->center_->attach(this->figure_);
+ this->figure_->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
+ this->figure_->yaw(Degree(-90));
+ this->figure_->setSpeed(this->center_->getBatSpeed());
+ this->figure_->setFieldDimension(this->center_->getFieldDimension());
+ this->figure_->setLength(this->center_->getBatLength());
- if (this->center_ == NULL) // abandon mission!
+ // Set the bats for the ball.
+ this->ball_->setFigure(this->figure_);
+ }
+ else // If no centerpoint was specified, an error is thrown and the level is exited.
{
orxout(internal_error) << "Jump: No Centerpoint specified." << endl;
GSLevel::startMainMenu();
return;
}
- */
- //addPlatform(0,0);
+ // Start the timer. After it has expired the ball is started.
+ this->starttimer_.startTimer();
+ // Set variable to temporarily force the player to spawn.
+ bool temp = this->bForceSpawn_;
+ this->bForceSpawn_ = true;
+
+ // Call start for the parent class.
+ Deathmatch::start();
+
+ // Reset the variable.
+ this->bForceSpawn_ = temp;
+
+ if (this->figure_ != NULL)
+ {
+ this->camera = this->figure_->getCamera();
+ }
+
+ totalScreenShift = 0.0;
}
+ /**
+ @brief
+ Ends the Jump minigame.
+ */
+ void Jump::end()
+ {
+ this->cleanup();
- /*void Jump::addPoints(int numPoints)
+ // Call end for the parent class.
+ Deathmatch::end();
+ }
+
+ /**
+ @brief
+ Spawns players, and fills the rest up with bots.
+ */
+ void Jump::spawnPlayersIfRequested()
{
- if (!bEndGame)
+
+ // first spawn human players to assign always the left bat to the player in singleplayer
+ for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+ if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
+ this->spawnPlayer(it->first);
+ // now spawn bots
+ /*
+ for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+ if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
+ this->spawnPlayer(it->first);
+ */
+ }
+
+ /**
+ @brief
+ Spawns the input player.
+ @param player
+ The player to be spawned.
+ */
+ void Jump::spawnPlayer(PlayerInfo* player)
+ {
+ assert(player);
+
+ // If the first (left) bat has no player.
+ if (this->figure_->getPlayer() == NULL)
{
- point += numPoints * multiplier;
- b_combo = true;
+ player->startControl(this->figure_);
+ this->players_[player].state_ = PlayerState::Alive;
}
- }*/
+ // If both bats are taken.
+ else
+ {
+ return;
+ }
- /*void Jump::end()
+ }
+
+ /**
+ @brief
+ Is called when the player scored.
+ */
+ void Jump::playerScored(PlayerInfo* player, int score)
{
- // DON'T CALL THIS!
- // Deathmatch::end();
- // It will misteriously crash the game!
- // Instead startMainMenu, this won't crash.
- GSLevel::startMainMenu();
- }*/
+ /*
+ Deathmatch::playerScored(player, score);
+ if (this->center_ != NULL) // If there is a centerpoint.
+ {
+ // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks.
+ if (player == this->getRightPlayer())
+ this->center_->fireEvent(FireEventName(JumpCenterpoint, right));
+ else if (player == this->getLeftPlayer())
+ this->center_->fireEvent(FireEventName(JumpCenterpoint, left));
- void Jump::addPlatform(float xPosition, float yPosition)
+ // Also announce, that the player has scored.
+ if (player != NULL)
+ this->gtinfo_->sendAnnounceMessage(player->getName() + " scored");
+ }
+
+ // If there is a ball present, reset its position, velocity and acceleration.
+ if (this->ball_ != NULL)
+ {
+ this->ball_->setPosition(Vector3::ZERO);
+ this->ball_->setVelocity(Vector3::ZERO);
+ this->ball_->setAcceleration(Vector3::ZERO);
+ this->ball_->setSpeed(0);
+ }
+
+ // If there are bats reset them to the middle position.
+ if (this->figure_[0] != NULL && this->figure_[1] != NULL)
+ {
+ this->figure_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
+ this->figure_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
+ }
+
+ // If a player gets enough points, he won the game -> end of game
+ PlayerInfo* winningPlayer = NULL;
+ if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_)
+ winningPlayer = this->getLeftPlayer();
+ else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_)
+ winningPlayer = getLeftPlayerthis->getRightPlayer();
+
+ if (winningPlayer)
+ {
+ ChatManager::message(winningPlayer->getName() + " has won!");
+ this->end();
+ }
+
+ // Restart the timer to start the ball.
+ this->starttimer_.startTimer();
+
+ */
+ }
+
+ /**
+ @brief
+ Starts the ball with some default speed.
+ */
+ void Jump::startBall()
{
- JumpPlatform* newPlatform = new JumpPlatform(center_->getContext());
- newPlatform->setPosition(Vector3(xPosition, yPosition, 0));
- platformList.push_front(newPlatform);
+
}
+ /**
+ @brief
+ Get the left player.
+ @return
+ Returns a pointer to the player playing on the left. If there is no left player, NULL is returned.
+ */
+ PlayerInfo* Jump::getPlayer() const
+ {
+ if (this->figure_ != NULL)
+ {
+ return this->figure_->getPlayer();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
}
Modified: code/branches/pickupsFS14/src/modules/jump/Jump.h
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/Jump.h 2014-04-17 14:05:06 UTC (rev 10039)
+++ code/branches/pickupsFS14/src/modules/jump/Jump.h 2014-04-17 14:29:25 UTC (rev 10040)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Florian Zinggeler
+ * Fabian 'x3n' Landau
* Co-authors:
* ...
*
@@ -28,7 +28,7 @@
/**
@file Jump.h
- @brief Gametype.
+ @brief Declaration of the Jump class.
@ingroup Jump
*/
@@ -36,63 +36,71 @@
#define _Jump_H__
#include "jump/JumpPrereqs.h"
-#include "gametypes/Deathmatch.h"
-#include "JumpCenterPoint.h"
+
#include "tools/Timer.h"
-#include "JumpPlatform.h"
-#include <list>
+#include "graphics/Camera.h"
+#include "gametypes/Deathmatch.h"
+#include "JumpCenterpoint.h"
namespace orxonox
{
+ /**
+ @brief
+ Implements a Jump minigame (<a href="http://en.wikipedia.org/wiki/Jump">Wikipedia::Jump</a>).
+ It connects the different entities present in a game of Jump.
+
+ - The @ref orxonox::JumpCenterpoint "JumpCenterpoint" is the playing field for the Jump minigame, it allows for configuration of the minigame, e.g. by setting the size of the playing field, or the length of the @ref orxonox::JumpFigure "JumpFigures". The playing field is always in the x,y-plane, the x-axis being the horizontal and the z-axis being the vertical axis.<br />
+ The Jump class redistributes the important parameters defined in @ref orxonox::JumpCenterpoint "JumpCenterpoint" to the other entities, that need to know them, e.g. the @ref orxonox::JumpPlatform "JumpPlatform" and the @ref orxonox::JumpFigure "JumpFigures".<br />
+ The @ref orxonox::JumpCenterpoint "JumpCenterpoint" needs to exist in a level with the @ref orxonox::Gametype "Gametype" <em>Jump</em>.
+ - The @ref orxonox::JumpPlatform "JumpPlatform" is the ball both players play with. The @ref orxonox::JumpPlatform "JumpPlatform" both implements the movement of the ball, as well as the influence of the boundaries and consequently, also the bouncing (off the upper and lower delimiters, and as off the @ref orxonox::JumpFigure "JumpFigures") of the ball and the effects of the failure of a player to catch the ball (i.e. the scoring of the other player).
+ - The two @ref orxonox::JumpFigure "JumpFigures" are the entities through which the players can actively participate in the game, by controlling them. The @ref orxonox::JumpFigure "JumpFigure" class manages the movement (and restrictions thereof) and the influence of the players on the bats.
+
+ @author
+ Fabian 'x3n' Landau
+
+ @ingroup Jump
+ */
class _JumpExport Jump : public Deathmatch
{
public:
- Jump(Context* context);
- virtual void start();
- //virtual void end();
- //virtual void addBots(unsigned int amount){} //<! overwrite function in order to bypass the addbots command
+ Jump(Context* context); //!< Constructor. Registers and initializes the object.
+ virtual ~Jump(); //!< Destructor. Cleans up, if initialized.
virtual void tick(float dt);
- //void spawnEnemy();
+ virtual void start(); //!< Starts the Jump minigame.
+ virtual void end(); ///!< Ends the Jump minigame.
- void setCenterpoint(JumpCenterPoint* center){ this->center_ = center; }
+ virtual void spawnPlayer(PlayerInfo* player); //!< Spawns the input player.
- virtual void addPlatform(float x, float y);
+ virtual void playerScored(PlayerInfo* player, int score = 1); //!< Is called when the player scored.
- /*int getLives(){return this->lives;}
- int getLevel(){return this->level;}
- int getPoints(){return this->point;}
- int getMultiplier(){return this->multiplier;}*/
+ /**
+ @brief Set the JumpCenterpoint (the playing field).
+ @param center A pointer to the JumpCenterpoint to be set.
+ */
+ void setCenterpoint(JumpCenterpoint* center)
+ { this->center_ = center; }
+ void setConfigValues(); //!< Makes scoreLimit configurable.
- /*void costLife();
- void levelUp();
- void addPoints(int numPoints);
- // checks if multiplier should be reset.
- void comboControll();*/
- //int lives;
- //int multiplier;
- //bool bEndGame;
- //bool bShowLevel;
- private:
- //void toggleShowLevel(){bShowLevel = !bShowLevel;}
- WeakPtr<JumpShip> getPlayer();
- WeakPtr<JumpCenterPoint> center_;
- WeakPtr<JumpShip> player;
+ PlayerInfo* getPlayer() const; //!< Get the left player.
+
+ protected:
+ virtual void spawnPlayersIfRequested(); //!< Spawns players, and fills the rest up with bots.
+
+ void startBall(); //!< Starts the ball with some default speed.
+ void cleanup(); //!< Cleans up the Gametype by destroying the ball and the bats.
+
+ WeakPtr<JumpCenterpoint> center_; //!< The playing field.
+ WeakPtr<JumpPlatform> ball_; //!< The Jump ball.
+ WeakPtr<JumpFigure> figure_; //!< The two bats.
WeakPtr<Camera> camera;
+ Timer starttimer_; //!< A timer to delay the start of the game.
+ int scoreLimit_; //!< If a player scored that much points, the game is ended.
- /*Timer enemySpawnTimer;
- Timer comboTimer;
- Timer showLevelTimer;
- //Context* context; <-- War schon auskommentiert!!!
- int level;
- int point;
- bool b_combo;*/
- std::list<JumpPlatform*> platformList;
- float yScreenPosition;
- float screenShiftSinceLastUpdate;
+ float totalScreenShift;
};
}
Modified: code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc 2014-04-17 14:05:06 UTC (rev 10039)
+++ code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc 2014-04-17 14:29:25 UTC (rev 10040)
@@ -20,55 +20,310 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Benjamin de Capitani
+ * Fabian 'x3n' Landau
* Co-authors:
* ...
*
*/
+/**
+ @file JumpPlatform.cc
+ @brief Implementation of the JumpPlatform class.
+*/
+
#include "JumpPlatform.h"
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
-#include "core/command/Executor.h"
-#include "tools/ParticleInterface.h"
-#include "Scene.h"
-#include "graphics/ParticleSpawner.h"
-#include "graphics/Model.h"
-#include "worldentities/MovableEntity.h"
-#include "chat/ChatManager.h"
-#include "OrxonoxPrereqs.h"
+#include "gametypes/Gametype.h"
+
+#include "JumpFigure.h"
+
+#include "sound/WorldSound.h"
+#include "core/XMLPort.h"
+
namespace orxonox
{
RegisterClass(JumpPlatform);
- JumpPlatform::JumpPlatform(Context* context) : MobileEntity(context)
+ const float JumpPlatform::MAX_REL_Z_VELOCITY = 1.5;
+
+ /**
+ @brief
+ Constructor. Registers and initializes the object.
+ */
+ JumpPlatform::JumpPlatform(Context* context) : MovableEntity(context)
{
RegisterObject(JumpPlatform);
+ this->figure_ = 0;
+ this->bDeleteBats_ = false;
+ this->batID_ = new unsigned int[1];
+ this->batID_[0] = OBJECTID_UNKNOWN;
+ this->relMercyOffset_ = 0.05f;
- model = new Model(getContext());
- model->setSyncMode(0);
- model->setMeshSource("Platform01.mesh");
+ this->registerVariables();
- attach(model);
- setScale(5);
- setPosition(Vector3(0,0,0));
- setVelocity(Vector3(0,0,0));
+ //initialize sound
+ if (GameMode::isMaster())
+ {
+ this->defScoreSound_ = new WorldSound(this->getContext());
+ this->defScoreSound_->setVolume(1.0f);
+ this->defBatSound_ = new WorldSound(this->getContext());
+ this->defBatSound_->setVolume(0.4f);
+ this->defBoundarySound_ = new WorldSound(this->getContext());
+ this->defBoundarySound_->setVolume(0.5f);
+ }
+ else
+ {
+ this->defScoreSound_ = 0;
+ this->defBatSound_ = 0;
+ this->defBoundarySound_ = 0;
+ }
+ this->setPosition(Vector3(0,0,0));
+ this->setVelocity(Vector3(0,0,0));
+ this->setAcceleration(Vector3(0,0,0));
}
+ /**
+ @brief
+ Destructor.
+ */
+ JumpPlatform::~JumpPlatform()
+ {
+ if (this->isInitialized())
+ {
+ if (this->bDeleteBats_)
+ delete this->figure_;
+
+ delete[] this->batID_;
+ }
+ }
+
+ //xml port for loading sounds
+ void JumpPlatform::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(JumpPlatform, XMLPort, xmlelement, mode);
+ XMLPortParam(JumpPlatform, "defScoreSound", setDefScoreSound, getDefScoreSound, xmlelement, mode);
+ XMLPortParam(JumpPlatform, "defBatSound", setDefBatSound, getDefBatSound, xmlelement, mode);
+ XMLPortParam(JumpPlatform, "defBoundarySound", setDefBoundarySound, getDefBoundarySound, xmlelement, mode);
+ }
+
+ /**
+ @brief
+ Register variables to synchronize over the network.
+ */
+ void JumpPlatform::registerVariables()
+ {
+ registerVariable( this->fieldWidth_ );
+ registerVariable( this->fieldHeight_ );
+ registerVariable( this->relMercyOffset_ );
+ registerVariable( this->batID_[0] );
+ //registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<JumpPlatform>( this, &JumpPlatform::applyBats) );
+ }
+
+ /**
+ @brief
+ Is called every tick.
+ Handles the movement of the ball and its interaction with the boundaries and bats.
+ @param dt
+ The time since the last tick.
+ */
void JumpPlatform::tick(float dt)
{
- //setAngularVelocity(getAngularVelocity() + Vector3(0.05,0,0));
- /*Vector3 movement(0,0,0);
- Vector3 shipPosition = getPosition();*/
+ SUPER(JumpPlatform, tick, dt);
+ Vector3 platformPosition = this->getPosition();
+ Vector3 platformVelocity = this->getVelocity();
+ if (figure_ != NULL)
+ {
+ Vector3 figurePosition = figure_->getPosition();
+ Vector3 figureVelocity = figure_->getVelocity();
- SUPER(JumpPlatform, tick, dt);
+ if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-10 && figurePosition.x < platformPosition.x+10 && figurePosition.z > platformPosition.z-4 && figurePosition.z < platformPosition.z+4)
+ {
+ figure_->JumpFromPlatform(200.0f);
+ }
+ }
+
+
+
+ /*
+ // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).
+ if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
+ {
+ defBoundarySound_->play(); //play boundary sound
+ // Its velocity in z-direction is inverted (i.e. it bounces off).
+ velocity.z = -velocity.z;
+ // And its position is set as to not overstep the boundary it has just crossed.
+ if (position.z > this->fieldHeight_ / 2)
+ position.z = this->fieldHeight_ / 2;
+ if (position.z < -this->fieldHeight_ / 2)
+ position.z = -this->fieldHeight_ / 2;
+
+ this->fireEvent();
+ }
+
+ // If the ball has crossed the left or right boundary of the playing field (i.e. a player has just scored, if the bat isn't there to parry).
+ if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
+ {
+ float distance = 0;
+
+ if (this->bat_ != NULL) // If there are bats.
+ {
+ // If the right boundary has been crossed.
+ if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL)
+ {
+ // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
+ distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
+ if (fabs(distance) <= 1) // If the bat is there to parry.
+ {
+ defBatSound_->play(); //play bat sound
+ // Set the ball to be exactly at the boundary.
+ position.x = this->fieldWidth_ / 2;
+ // Invert its velocity in x-direction (i.e. it bounces off).
+ velocity.x = -velocity.x;
+ // Adjust the velocity in the z-direction, depending on where the ball hit the bat.
+ velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;
+ acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;
+
+ this->fireEvent();
+ }
+ // If the left player scores.
+ else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
+ {
+ defScoreSound_->play();//play score sound
+ if (this->getGametype() && this->bat_[0])
+ {
+ this->getGametype()->playerScored(this->bat_[0]->getPlayer());
+ return;
+ }
+ }
+ }
+ // If the left boundary has been crossed.
+ else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL)
+ {
+ // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
+ distance = (position.z - this->figure_->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
+ if (fabs(distance) <= 1) // If the bat is there to parry.
+ {
+ defBatSound_->play(); //play bat sound
+ // Set the ball to be exactly at the boundary.
+ position.x = -this->fieldWidth_ / 2;
+ // Invert its velocity in x-direction (i.e. it bounces off).
+ velocity.x = -velocity.x;
+ // Adjust the velocity in the z-direction, depending on where the ball hit the bat.
+ velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;
+ acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1;
+
+ this->fireEvent();
+ }
+ // If the right player scores.
+ else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
+ {
+ defScoreSound_->play();//play score sound
+ if (this->getGametype() && this->bat_[1])
+ {
+ this->getGametype()->playerScored(this->bat_[1]->getPlayer());
+ return;
+ }
+ }
+ }
+ }
+ }
+ */
}
+ /**
+ @brief
+ Set the bats for the ball.
+ @param bats
+ An array (of size 2) of weak pointers, to be set as the new bats.
+ */
+ void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure)
+ {
+ if (this->bDeleteBats_) // If there are already some bats, delete them.
+ {
+ delete this->figure_;
+ this->bDeleteBats_ = false;
+ }
+ this->figure_ = newFigure;
+ // Also store their object IDs, for synchronization.
+ this->batID_[0] = this->figure_->getObjectID();
+ }
+
+ /**
+ @brief
+ Get the bats over the network.
+ */
+ void JumpPlatform::applyBats()
+ {
+ // Make space for the bats, if they don't exist, yet.
+ if (this->figure_ == NULL)
+ {
+ this->figure_ = *(new WeakPtr<JumpFigure>);
+ this->bDeleteBats_ = true;
+ }
+
+ if (this->batID_[0] != OBJECTID_UNKNOWN)
+ {
+ // WAR IM PONG NICHT AUSKOMMENTIERT!!!
+ //this->figure_ = orxonox_cast<JumpFigure>(Synchronisable::getSynchronisable(this->batID_[0]));
+ }
+ }
+
+ void JumpPlatform::setDefScoreSound(const std::string &jumpSound)
+ {
+ if( defScoreSound_ )
+ defScoreSound_->setSource(jumpSound);
+ else
+ assert(0); // This should never happen, because soundpointer is only available on master
+ }
+
+ const std::string& JumpPlatform::getDefScoreSound()
+ {
+ if( defScoreSound_ )
+ return defScoreSound_->getSource();
+ else
+ assert(0);
+ return BLANKSTRING;
+ }
+
+ void JumpPlatform::setDefBatSound(const std::string &jumpSound)
+ {
+ if( defBatSound_ )
+ defBatSound_->setSource(jumpSound);
+ else
+ assert(0); // This should never happen, because soundpointer is only available on master
+ }
+
+ const std::string& JumpPlatform::getDefBatSound()
+ {
+ if( defBatSound_ )
+ return defBatSound_->getSource();
+ else
+ assert(0);
+ return BLANKSTRING;
+ }
+
+ void JumpPlatform::setDefBoundarySound(const std::string &jumpSound)
+ {
+ if( defBoundarySound_ )
+ defBoundarySound_->setSource(jumpSound);
+ else
+ assert(0); // This should never happen, because soundpointer is only available on master
+ }
+
+ const std::string& JumpPlatform::getDefBoundarySound()
+ {
+ if( defBoundarySound_ )
+ return defBoundarySound_->getSource();
+ else
+ assert(0);
+ return BLANKSTRING;
+ }
}
Modified: code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h 2014-04-17 14:05:06 UTC (rev 10039)
+++ code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h 2014-04-17 14:29:25 UTC (rev 10040)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Florian Zinggeler
+ * Fabian 'x3n' Landau
* Co-authors:
* ...
*
@@ -29,6 +29,7 @@
/**
@file JumpPlatform.h
@brief Declaration of the JumpPlatform class.
+ @ingroup Jump
*/
#ifndef _JumpPlatform_H__
@@ -36,18 +37,80 @@
#include "jump/JumpPrereqs.h"
-#include "worldentities/MobileEntity.h"
+#include "util/Math.h"
+#include "worldentities/MovableEntity.h"
+
+
namespace orxonox
{
- class _JumpExport JumpPlatform : public MobileEntity
+
+ /**
+ @brief
+ This class manages the ball for @ref orxonox::Jump "Jump".
+
+ It is responsible for both the movement of the ball in the x,z-plane as well as its interaction with the boundaries of the playing field (defined by the @ref orxonox::JumpCenterpoint "JumpCenterpoint") and the @ref orxonox::JumpFigure "JumpFigures". Or more precisely, it makes the ball bounce off then upper and lower delimiters of the playing field, it makes the ball bounce off the bats and also detects when a player scores and takes appropriate measures.
+
+ @author
+ Fabian 'x3n' Landau
+
+ @ingroup Jump
+ */
+ class _JumpExport JumpPlatform : public MovableEntity
{
public:
JumpPlatform(Context* context);
+ virtual ~JumpPlatform();
+
virtual void tick(float dt);
- private:
- Model* model;
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+ /**
+ @brief Set the dimensions of the playing field.
+ @param width The width of the playing field.
+ @param height The height of the playing field.
+ */
+ void setFieldDimension(float width, float height)
+ { this->fieldWidth_ = width; this->fieldHeight_ = height; }
+ /**
+ @brief Get the dimensions of the playing field.
+ @param dimension A vector with the width as the first and height as the second component.
+ */
+ void setFieldDimension(const Vector2& dimension)
+ { this->setFieldDimension(dimension.x, dimension.y); }
+ /**
+ @brief Get the dimensions of the playing field.
+ @return Returns a vector with the width as the first and height as the second component.
+ */
+ Vector2 getFieldDimension() const
+ { return Vector2(this->fieldWidth_, this->fieldHeight_); }
+
+
+ void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball.
+ void applyBats(); //!< Get the bats over the network.
+
+ static const float MAX_REL_Z_VELOCITY;
+
+ void setDefScoreSound(const std::string& engineSound);
+ const std::string& getDefScoreSound();
+ void setDefBatSound(const std::string& engineSound);
+ const std::string& getDefBatSound();
+ void setDefBoundarySound(const std::string& engineSound);
+ const std::string& getDefBoundarySound();
+
+ protected:
+ void registerVariables();
+
+ float fieldWidth_; //!< The width of the playing field.
+ float fieldHeight_; //!< The height of the playing field.
+ WeakPtr<JumpFigure> figure_; //!< An array with the two bats.
+ bool bDeleteBats_; //!< Bool, to keep track, of whether this->bat_ exists or not.
+ unsigned int* batID_; //!< The object IDs of the bats, to be able to synchronize them over the network.
+ float relMercyOffset_; //!< Offset, that makes the player not loose, when, in all fairness, he would have.
+ WorldSound* defScoreSound_;
+ WorldSound* defBatSound_;
+ WorldSound* defBoundarySound_;
};
}
Modified: code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h
===================================================================
--- code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h 2014-04-17 14:05:06 UTC (rev 10039)
+++ code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h 2014-04-17 14:29:25 UTC (rev 10040)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Florian Zinggeler
+ * Reto Grieder
* Co-authors:
* ...
*
@@ -29,7 +29,7 @@
/**
@file
@brief
- Shared library macros, enums, constants and forward declarations for the Invader module
+ Shared library macros, enums, constants and forward declarations for the jump module
*/
#ifndef _JumpPrereqs_H__
@@ -42,8 +42,8 @@
// Shared library settings
//-----------------------------------------------------------------------
-#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(INVADER_STATIC_BUILD)
-# ifdef INVADER_SHARED_BUILD
+#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(PONG_STATIC_BUILD)
+# ifdef PONG_SHARED_BUILD
# define _JumpExport __declspec(dllexport)
# else
# if defined( __MINGW32__ )
@@ -68,14 +68,11 @@
namespace orxonox
{
class Jump;
- class JumpCenterPoint;
- class JumpShip;
class JumpPlatform;
- class JumpEnemy;
- class JumpEnemyShooter;
- class JumpWeapon;
- class JumpWeaponEnemy;
- class JumpHUDinfo;
+ class JumpPlatformHMove;
+ class JumpFigure;
+ class JumpCenterpoint;
+ class JumpScore;
}
#endif /* _JumpPrereqs_H__ */
More information about the Orxonox-commit
mailing list