[Orxonox-commit 7619] r12212 - in code/branches/OrxoBlox_FS19: data/tcl src/modules src/modules/OrxoBlox

ahuwyler at orxonox.net ahuwyler at orxonox.net
Thu Mar 21 14:19:17 CET 2019


Author: ahuwyler
Date: 2019-03-21 14:19:16 +0100 (Thu, 21 Mar 2019)
New Revision: 12212

Modified:
   code/branches/OrxoBlox_FS19/data/tcl/orxokart_highscores.txt
   code/branches/OrxoBlox_FS19/src/modules/CMakeLists.txt
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/CMakeLists.txt
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxPrereqs.h
Log:
A new Game is born

Modified: code/branches/OrxoBlox_FS19/data/tcl/orxokart_highscores.txt
===================================================================
--- code/branches/OrxoBlox_FS19/data/tcl/orxokart_highscores.txt	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/data/tcl/orxokart_highscores.txt	2019-03-21 13:19:16 UTC (rev 12212)
@@ -18,3 +18,4 @@
 Name: 0:31:46s
 Name: 0:25:40s
 Name: 1:27:11s
+Name: 0:29:74s

Modified: code/branches/OrxoBlox_FS19/src/modules/CMakeLists.txt
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/CMakeLists.txt	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/CMakeLists.txt	2019-03-21 13:19:16 UTC (rev 12212)
@@ -52,3 +52,4 @@
 ADD_SUBDIRECTORY(orxyroad)
 ADD_SUBDIRECTORY(orxokart)
 ADD_SUBDIRECTORY(wagnis)
+ADD_SUBDIRECTORY(OrxoBlox)
\ No newline at end of file

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/CMakeLists.txt
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/CMakeLists.txt	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/CMakeLists.txt	2019-03-21 13:19:16 UTC (rev 12212)
@@ -1,20 +1,20 @@
-SET_SOURCE_FILES(PONG_SRC_FILES
-BUILD_UNIT PongBuildUnit.cc
-  Pong.cc
-  PongAI.cc
-  PongBall.cc
-  PongBat.cc
-  PongBot.cc
-  PongCenterpoint.cc
-  PongScore.cc
+SET_SOURCE_FILES(OrxoBlox_FS19_SRC_FILES
+BUILD_UNIT OrxoBloxBuildUnit.cc
+  OrxoBlox.cc
+  OrxoBloxAI.cc
+  OrxoBloxBall.cc
+  OrxoBloxBat.cc
+  OrxoBloxBot.cc
+  OrxoBloxCenterpoint.cc
+  OrxoBloxScore.cc
 END_BUILD_UNIT
 )
 
-ORXONOX_ADD_LIBRARY(pong
+ORXONOX_ADD_LIBRARY(OrxoBlox_FS19
   PLUGIN
   FIND_HEADER_FILES
   LINK_LIBRARIES
     orxonox
     overlays
-  SOURCE_FILES ${PONG_SRC_FILES}
+  SOURCE_FILES ${OrxoBlox_FS19_SRC_FILES}
 )

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc	2019-03-21 13:19:16 UTC (rev 12212)
@@ -27,11 +27,11 @@
  */
 
 /**
-    @file Pong.cc
-    @brief Implementation of the Pong class.
+    @file OrxoBlox.cc
+    @brief Implementation of the OrxoBlox class.
 */
 
-#include "Pong.h"
+#include "OrxoBlox.h"
 
 #include "core/CoreIncludes.h"
 #include "core/EventIncludes.h"
@@ -41,27 +41,26 @@
 #include "gamestates/GSLevel.h"
 #include "chat/ChatManager.h"
 
-#include "PongCenterpoint.h"
-#include "PongBall.h"
-#include "PongBat.h"
-#include "PongBot.h"
-#include "PongAI.h"
-
+#include "OrxoBloxCenterpoint.h"
+#include "OrxoBloxBall.h"
+#include "OrxoBloxBat.h"
+#include "OrxoBloxBot.h"
+#include "OrxoBloxAI.h"
 namespace orxonox
 {
     // Events to allow to react to scoring of a player, in the level-file.
-    CreateEventName(PongCenterpoint, right);
-    CreateEventName(PongCenterpoint, left);
+    CreateEventName(OrxoBloxCenterpoint, right);
+    CreateEventName(OrxoBloxCenterpoint, left);
 
-    RegisterUnloadableClass(Pong);
+    RegisterUnloadableClass(OrxoBlox);
 
     /**
     @brief
         Constructor. Registers and initializes the object.
     */
-    Pong::Pong(Context* context) : Deathmatch(context)
+    OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context)
     {
-        RegisterObject(Pong);
+        RegisterObject(OrxoBlox);
 
         this->center_ = nullptr;
         this->ball_ = nullptr;
@@ -68,14 +67,14 @@
         this->bat_[0] = nullptr;
         this->bat_[1] = nullptr;
 
-        this->setHUDTemplate("PongHUD");
+        this->setHUDTemplate("OrxoBloxHUD");
 
         // Pre-set the timer, but don't start it yet.
-        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Pong::startBall, this)));
+        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::startBall, this)));
         this->starttimer_.stopTimer();
 
         // Set the type of Bots for this particular Gametype.
-        this->botclass_ = Class(PongBot);
+        this->botclass_ = Class(OrxoBloxBot);
 
         this->scoreLimit_ = 10;
         this->setConfigValues();
@@ -85,13 +84,13 @@
     @brief
         Destructor. Cleans up, if initialized.
     */
-    Pong::~Pong()
+    OrxoBlox::~OrxoBlox()
     {
         if (this->isInitialized())
             this->cleanup();
     }
 
-    void Pong::setConfigValues()
+    void OrxoBlox::setConfigValues()
     {
         SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins.");
     }
@@ -100,7 +99,7 @@
     @brief
         Cleans up the Gametype by destroying the ball and the bats.
     */
-    void Pong::cleanup()
+    void OrxoBlox::cleanup()
     {
         if (this->ball_ != nullptr) // Destroy the ball, if present.
         {
@@ -122,15 +121,15 @@
 
     /**
     @brief
-        Starts the Pong minigame.
+        Starts the OrxoBlox minigame.
     */
-    void Pong::start()
+    void OrxoBlox::start()
     {
-        if (this->center_ != nullptr) // There needs to be a PongCenterpoint, i.e. the area the game takes place.
+        if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place.
         {
             if (this->ball_ == nullptr) // If there is no ball, create a new ball.
             {
-                this->ball_ = new PongBall(this->center_->getContext());
+                this->ball_ = new OrxoBloxBall(this->center_->getContext());
                 // Apply the template for the ball specified by the centerpoint.
                 this->ball_->addTemplate(this->center_->getBalltemplate());
             }
@@ -144,11 +143,11 @@
             this->ball_->setBatLength(this->center_->getBatLength());
 
             // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
-            for (WeakPtr<orxonox::PongBat>& bat : this->bat_)
+            for (WeakPtr<orxonox::OrxoBloxBat>& bat : this->bat_)
             {
                 if (bat == nullptr)
                 {
-                    bat = new PongBat(this->center_->getContext());
+                    bat = new OrxoBloxBat(this->center_->getContext());
                     bat->addTemplate(this->center_->getBattemplate());
                 }
             }
@@ -172,7 +171,7 @@
         }
         else // If no centerpoint was specified, an error is thrown and the level is exited.
         {
-            orxout(internal_error) << "Pong: No Centerpoint specified." << endl;
+            orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl;
             GSLevel::startMainMenu();
             return;
         }
@@ -193,9 +192,9 @@
 
     /**
     @brief
-        Ends the Pong minigame.
+        Ends the OrxoBlox minigame.
     */
-    void Pong::end()
+    void OrxoBlox::end()
     {
         this->cleanup();
 
@@ -207,7 +206,7 @@
     @brief
         Spawns players, and fills the rest up with bots.
     */
-    void Pong::spawnPlayersIfRequested()
+    void OrxoBlox::spawnPlayersIfRequested()
     {
         // first spawn human players to assign always the left bat to the player in singleplayer
         for (const auto& mapEntry : this->players_)
@@ -225,7 +224,7 @@
     @param player
         The player to be spawned.
     */
-    void Pong::spawnPlayer(PlayerInfo* player)
+    void OrxoBlox::spawnPlayer(PlayerInfo* player)
     {
         assert(player);
 
@@ -246,10 +245,10 @@
             return;
 
         // If the player is an AI, it receives a pointer to the ball.
-        if (player->getController() != nullptr && player->getController()->isA(Class(PongAI)))
+        if (player->getController() != nullptr && player->getController()->isA(Class(OrxoBloxAI)))
         {
-            PongAI* ai = orxonox_cast<PongAI*>(player->getController());
-            ai->setPongBall(this->ball_);
+            OrxoBloxAI* ai = orxonox_cast<OrxoBloxAI*>(player->getController());
+            ai->setOrxoBloxBall(this->ball_);
         }
     }
 
@@ -257,7 +256,7 @@
     @brief
         Is called when the player scored.
     */
-    void Pong::playerScored(PlayerInfo* player, int score)
+    void OrxoBlox::playerScored(PlayerInfo* player, int score)
     {
         Deathmatch::playerScored(player, score);
 
@@ -265,9 +264,9 @@
         {
             // 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(PongCenterpoint, right));
+                this->center_->fireEvent(FireEventName(OrxoBloxCenterpoint, right));
             else if (player == this->getLeftPlayer())
-                this->center_->fireEvent(FireEventName(PongCenterpoint, left));
+                this->center_->fireEvent(FireEventName(OrxoBloxCenterpoint, left));
 
             // Also announce, that the player has scored.
             if (player != nullptr)
@@ -311,7 +310,7 @@
     @brief
         Starts the ball with some default speed.
     */
-    void Pong::startBall()
+    void OrxoBlox::startBall()
     {
         if (this->ball_ != nullptr && this->center_ != nullptr)
             this->ball_->setSpeed(this->center_->getBallSpeed());
@@ -323,7 +322,7 @@
     @return
         Returns a pointer to the player playing on the left. If there is no left player, nullptr is returned.
     */
-    PlayerInfo* Pong::getLeftPlayer() const
+    PlayerInfo* OrxoBlox::getLeftPlayer() const
     {
         if (this->bat_[0] != nullptr)
             return this->bat_[0]->getPlayer();
@@ -337,7 +336,7 @@
     @return
         Returns a pointer to the player playing on the right. If there is no right player, nullptr is returned.
     */
-    PlayerInfo* Pong::getRightPlayer() const
+    PlayerInfo* OrxoBlox::getRightPlayer() const
     {
         if (this->bat_[1] != nullptr)
             return this->bat_[1]->getPlayer();

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h	2019-03-21 13:19:16 UTC (rev 12212)
@@ -40,7 +40,7 @@
 #include "tools/Timer.h"
 
 #include "gametypes/Deathmatch.h"
-#include "PongCenterpoint.h"
+#include "OrxoBloxCenterpoint.h"
 
 namespace orxonox
 {
@@ -47,28 +47,28 @@
 
     /**
     @brief
-        Implements a Pong minigame (<a href="http://en.wikipedia.org/wiki/Pong">Wikipedia::Pong</a>).
-        It connects the different entities present in a game of Pong.
+        Implements a OrxoBlox minigame (<a href="http://en.wikipedia.org/wiki/OrxoBlox">Wikipedia::OrxoBlox</a>).
+        It connects the different entities present in a game of OrxoBlox.
 
-        - The @ref orxonox::PongCenterpoint "PongCenterpoint" is the playing field for the Pong 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::PongBat "PongBats". 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 Pong class redistributes the important parameters defined in @ref orxonox::PongCenterpoint "PongCenterpoint" to the other entities, that need to know them, e.g. the @ref orxonox::PongBall "PongBall" and the @ref orxonox::PongBat "PongBats".<br />
-        The @ref orxonox::PongCenterpoint "PongCenterpoint" needs to exist in a level with the @ref orxonox::Gametype "Gametype" <em>Pong</em>.
-        - The @ref orxonox::PongBall "PongBall" is the ball both players play with. The @ref orxonox::PongBall "PongBall" 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::PongBat "PongBats") 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::PongBat "PongBats" are the entities through which the players can actively participate in the game, by controlling them. The @ref orxonox::PongBat "PongBat" class manages the movement (and restrictions thereof) and the influence of the players on the bats.
+        - The @ref orxonox::OrxoBloxCenterpoint "OrxoBloxCenterpoint" is the playing field for the OrxoBlox 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::OrxoBloxBat "OrxoBloxBats". 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 OrxoBlox class redistributes the important parameters defined in @ref orxonox::OrxoBloxCenterpoint "OrxoBloxCenterpoint" to the other entities, that need to know them, e.g. the @ref orxonox::OrxoBloxBall "OrxoBloxBall" and the @ref orxonox::OrxoBloxBat "OrxoBloxBats".<br />
+        The @ref orxonox::OrxoBloxCenterpoint "OrxoBloxCenterpoint" needs to exist in a level with the @ref orxonox::Gametype "Gametype" <em>OrxoBlox</em>.
+        - The @ref orxonox::OrxoBloxBall "OrxoBloxBall" is the ball both players play with. The @ref orxonox::OrxoBloxBall "OrxoBloxBall" 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::OrxoBloxBat "OrxoBloxBats") 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::OrxoBloxBat "OrxoBloxBats" are the entities through which the players can actively participate in the game, by controlling them. The @ref orxonox::OrxoBloxBat "OrxoBloxBat" class manages the movement (and restrictions thereof) and the influence of the players on the bats.
 
     @author
         Fabian 'x3n' Landau
 
-    @ingroup Pong
+    @ingroup OrxoBlox
     */
-    class _PongExport Pong : public Deathmatch
+    class _OrxoBloxExport OrxoBlox : public Deathmatch
     {
         public:
-            Pong(Context* context); //!< Constructor. Registers and initializes the object.
-            virtual ~Pong(); //!< Destructor. Cleans up, if initialized.
+            OrxoBlox(Context* context); //!< Constructor. Registers and initializes the object.
+            virtual ~OrxoBlox(); //!< Destructor. Cleans up, if initialized.
 
-            virtual void start() override; //!< Starts the Pong minigame.
-            virtual void end() override; ///!< Ends the Pong minigame.
+            virtual void start() override; //!< Starts the OrxoBlox minigame.
+            virtual void end() override; ///!< Ends the OrxoBlox minigame.
 
             virtual void spawnPlayer(PlayerInfo* player) override; //!< Spawns the input player.
 
@@ -75,10 +75,10 @@
             virtual void playerScored(PlayerInfo* player, int score = 1) override; //!< Is called when the player scored.
 
             /**
-            @brief Set the PongCenterpoint (the playing field).
-            @param center A pointer to the PongCenterpoint to be set.
+            @brief Set the OrxoBloxCenterpoint (the playing field).
+            @param center A pointer to the OrxoBloxCenterpoint to be set.
             */
-            void setCenterpoint(PongCenterpoint* center)
+            void setCenterpoint(OrxoBloxCenterpoint* center)
                 { this->center_ = center; }
             void setConfigValues(); //!< Makes scoreLimit configurable.
 
@@ -91,12 +91,12 @@
             void startBall(); //!< Starts the ball with some default speed.
             void cleanup(); //!< Cleans up the Gametype by destroying the ball and the bats.
 
-            WeakPtr<PongCenterpoint> center_; //!< The playing field.
-            WeakPtr<PongBall> ball_; //!< The Pong ball.
-            WeakPtr<PongBat> bat_[2]; //!< The two bats.
+            WeakPtr<OrxoBloxCenterpoint> center_; //!< The playing field.
+            WeakPtr<OrxoBloxBall> ball_; //!< The OrxoBlox ball.
+            WeakPtr<OrxoBloxBat> bat_[2]; //!< The two bats.
             Timer starttimer_; //!< A timer to delay the start of the game.
             int scoreLimit_; //!< If a player scored that much points, the game is ended.
     };
 }
 
-#endif /* _Pong_H__ */
+#endif /* _OrxoBlox_H__ */

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc	2019-03-21 13:19:16 UTC (rev 12212)
@@ -1,9 +1,3 @@
-
-//TODO: Sounds (all the sounds are still from the pong module...)
-//TODO: Blocks (the Ball-Block comunication is based on how the blocks are implemented)
-//TODO: The bottom boundary/ the Ball collecter
-//TODO: Ability to shoot the ball (the ball is still constructed like the pong ball)
-
 /*
  *   ORXONOX - the hottest 3D action shooter ever to exist
  *                    > www.orxonox.net <
@@ -44,7 +38,7 @@
 
 #include "gametypes/Gametype.h"
 
-#include "OrxoBloxBlocks.h"
+#include "OrxoBloxBat.h"
 
 #include "sound/WorldSound.h"
 #include "core/XMLPort.h"
@@ -66,12 +60,12 @@
 
         this->speed_ = 0;
         this->accelerationFactor_ = 1.0f;
-        this->block_ = nullptr;
-        this->bDeleteBlock_ = false;
-        this->blockID_ = new unsigned int[100];
-	for (int i = 0; i < 100; i++) {
-		this->blockID_[i] = OBJECTID_UNKNOWN;
-	}
+        this->bat_ = nullptr;
+        this->bDeleteBats_ = false;
+        this->batID_ = new unsigned int[2];
+        this->batID_[0] = OBJECTID_UNKNOWN;
+        this->batID_[1] = OBJECTID_UNKNOWN;
+        this->relMercyOffset_ = 0.05f;
 
         this->registerVariables();
 
@@ -101,10 +95,10 @@
     {
         if (this->isInitialized())
         {
-            if (this->bDeleteBlock_)
-                delete[] this->block_;
+            if (this->bDeleteBats_)
+                delete[] this->bat_;
 
-            delete[] this->blockID_;
+            delete[] this->batID_;
         }
     }
 
@@ -125,16 +119,17 @@
     {
         registerVariable( this->fieldWidth_ );
         registerVariable( this->fieldHeight_ );
-        registerVariable( this->blocklength_ );
+        registerVariable( this->batlength_ );
         registerVariable( this->speed_ );
-        registerVariable( this->blockID_[0] );
-        registerVariable( this->blockID_[1], VariableDirection::ToClient, new NetworkCallback<OrxoBloxBall>( this, &OrxoBloxBall::applyBlock) );
+        registerVariable( this->relMercyOffset_ );
+        registerVariable( this->batID_[0] );
+        registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<OrxoBloxBall>( this, &OrxoBloxBall::applyBats) );
     }
 
     /**
     @brief
         Is called every tick.
-        Handles the movement of the ball and its interaction with the boundaries and blocks.
+        Handles the movement of the ball and its interaction with the boundaries and bats.
     @param dt
         The time since the last tick.
     */
@@ -147,37 +142,87 @@
         Vector3 velocity = this->getVelocity();
         Vector3 acceleration = this->getAcceleration();
 
-        // If the ball has hit the boundaries on either the right side or the left 
-        if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
+        // 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 x-direction is inverted (i.e. it bounces off).
-            velocity.x = -velocity.x;
+            // 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.x > this->fieldWidth_ / 2)
-                position.x = this->fieldWidth_ / 2;
-            if (position.x < -this->fieldWidth_ / 2)
-                position.x = -this->fieldWidth_ / 2;
+            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 hit the boundary on the top
-        if (position.z > this->fieldHeight_ / 2)
+        // 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)
         {
-            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.
-            position.z = this->fieldHeight_ / 2;
+            float distance = 0;
 
-            this->fireEvent();
-        }
+            if (this->bat_ != nullptr) // If there are bats.
+            {
+                // If the right boundary has been crossed.
+                if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != nullptr)
+                {
+                    // 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) * OrxoBloxBall::MAX_REL_Z_VELOCITY * this->speed_;
+                        acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;
 
-        // If the ball has crossed the bottom boundary
-        if (position.z < -this->fieldHeight_ / 2)
-        {
-	//TODO: Ball Collector
+                        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] != nullptr)
+                {
+                    // 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_[0]->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) * OrxoBloxBall::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;
+                        }
+                    }
+                }
+            }
         }
 
         // Set the position, velocity and acceleration of the ball, if they have changed.
@@ -214,48 +259,47 @@
 
     /**
     @brief
-        Set the blocks for the ball.
+        Set the bats for the ball.
     @param bats
-        An array (of size n (n=#Blocks) of weak pointers, to be set as the new blocks.
+        An array (of size 2) of weak pointers, to be set as the new bats.
     */
-    void OrxoBloxBall::setBlock(WeakPtr<OrxoBloxBlock>* block, int n)
+    void OrxoBloxBall::setBats(WeakPtr<OrxoBloxBat>* bats)
     {
-        if (this->bDeleteBlock_) // If there are already some blocks, delete them.
+        if (this->bDeleteBats_) // If there are already some bats, delete them.
         {
-            delete[] this->block_;
-            this->bDeleteBlock_ = false;
+            delete[] this->bat_;
+            this->bDeleteBats_ = false;
         }
 
-        this->block_ = block;
+        this->bat_ = bats;
         // Also store their object IDs, for synchronization.
-	for (int i = 0; i < n; i++) {
-        	this->blockID_[i] = this->block_[i]->getObjectID();
-	}
+        this->batID_[0] = this->bat_[0]->getObjectID();
+        this->batID_[1] = this->bat_[1]->getObjectID();
     }
 
     /**
     @brief
-        Get the blocks over the network.
+        Get the bats over the network.
     */
-    void OrxoBloxBall::applyBlock(int n)
+    void OrxoBloxBall::applyBats()
     {
-        // Make space for the blocks, if they don't exist, yet.
-        if (this->block_ == nullptr)
+        // Make space for the bats, if they don't exist, yet.
+        if (this->bat_ == nullptr)
         {
-            this->block_ = new WeakPtr<OrxoBloxBlock>[n];
-            this->bDeleteBlock_ = true;
+            this->bat_ = new WeakPtr<OrxoBloxBat>[2];
+            this->bDeleteBats_ = true;
         }
-	
-	for (int i = 0; i < n; i++) {
-		if (this->blockID_[i] != OBJECTID_UNKNOWN)
-            	this->bat_[i] = orxonox_cast<OrxoBloxBlock*>(Synchronisable::getSynchronisable(this->blockID_[i]));
-	}
+
+        if (this->batID_[0] != OBJECTID_UNKNOWN)
+            this->bat_[0] = orxonox_cast<OrxoBloxBat*>(Synchronisable::getSynchronisable(this->batID_[0]));
+        if (this->batID_[1] != OBJECTID_UNKNOWN)
+            this->bat_[1] = orxonox_cast<OrxoBloxBat*>(Synchronisable::getSynchronisable(this->batID_[1]));
     }
 
-    void OrxoBloxBall::setDefScoreSound(const std::string &pongSound)
+    void OrxoBloxBall::setDefScoreSound(const std::string &OrxoBloxSound)
     {
         if( defScoreSound_ )
-            defScoreSound_->setSource(pongSound);
+            defScoreSound_->setSource(OrxoBloxSound);
         else
             assert(0); // This should never happen, because soundpointer is only available on master
     }
@@ -269,10 +313,10 @@
         return BLANKSTRING;
     }
 
-    void OrxoBloxBall::setDefBatSound(const std::string &pongSound)
+    void OrxoBloxBall::setDefBatSound(const std::string &OrxoBloxSound)
     {
         if( defBatSound_ )
-            defBatSound_->setSource(pongSound);
+            defBatSound_->setSource(OrxoBloxSound);
         else
             assert(0); // This should never happen, because soundpointer is only available on master
     }
@@ -286,10 +330,10 @@
         return BLANKSTRING;
     }
 
-    void OrxoBloxBall::setDefBoundarySound(const std::string &pongSound)
+    void OrxoBloxBall::setDefBoundarySound(const std::string &OrxoBloxSound)
     {
         if( defBoundarySound_ )
-            defBoundarySound_->setSource(pongSound);
+            defBoundarySound_->setSource(OrxoBloxSound);
         else
             assert(0); // This should never happen, because soundpointer is only available on master
     }

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h	2019-03-21 13:19:16 UTC (rev 12212)
@@ -49,7 +49,7 @@
     @brief
         This class manages the ball for @ref orxonox::OrxoBlox "OrxoBlox".
 
-        It is responsible for both the movement of the ball in the x,y-plane as well as its interaction with the boundaries of the playing field (defined by the @ref orxonox::OrxoBloxCenterpoint "OrxoBloxCenterpoint") and the @ref orxonox::OrxoBloxBlocks "OrxoBloxBlocks". Or more precisely, it makes the ball bounce off then left and right delimiters of the playing field, it makes the ball bounce off the blocks, damages them and also detects when it reaches the lower bound and takes appropriate measures.
+        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::OrxoBloxCenterpoint "OrxoBloxCenterpoint") and the @ref orxonox::OrxoBloxBat "OrxoBloxBats". 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
@@ -75,13 +75,13 @@
                 { 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.
+            @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.
+            @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_); }
@@ -108,20 +108,20 @@
                 { return this->accelerationFactor_; }
 
             /**
-            @brief Set the length of the blocks.
-            @param batlength The length of the blocks (in x-direction) as percentage of the height 		    of the playing field.
+            @brief Set the length of the bats.
+            @param batlength The length of the bats (in z-direction) as percentage of the height of the playing field.
             */
-            void setBlockLength(float blocklength)
-                { this->blocklength_ = blocklength; }
+            void setBatLength(float batlength)
+                { this->batlength_ = batlength; }
             /**
-            @brief Get the length of the blocks.
-            @return Returns the length of the blocks as percentage of the height of the playing 	    field.
+            @brief Get the length of the bats.
+            @return Returns the length of the bats (in z-direction) as percentage of the height of the playing field.
             */
-            float getBlockLength() const
-		{ return this->blocklength_; }
+            float getBatLength() const
+                { return this->batlength_; }
 
-            void setBlock(WeakPtr<OrxoBloxBlock>* block); //!< Set the blocks for the ball.
-            void applyBlock(); //!< Get the block over the network.
+            void setBats(WeakPtr<OrxoBloxBat>* bats); //!< Set the bats for the ball.
+            void applyBats(); //!< Get the bats over the network.
 
             static const float MAX_REL_Z_VELOCITY;
 
@@ -137,13 +137,13 @@
 
             float fieldWidth_; //!< The width of the playing field.
             float fieldHeight_; //!< The height of the playing field.
-            float speedX_; //!< The speed (in x-direction) of the ball.
-            float speedY_; //!< The speed (in y-direction) of the ball.
+            float speed_; //!< The speed (in x-direction) of the ball.
             float accelerationFactor_; //!< The acceleration factor of the ball.
-            float blocklength_; //!< The length of the bats (in z-direction) as percentage of the 	    height of the playing field.
-            WeakPtr<OrxoBloxBlock>* block_; //!< An array with the blocks.
-            bool bDeleteBlock_; //!< Bool, to keep track, of whether this->block_ exists or not.
-            unsigned int* blockID_; //!< The object IDs of the blocks, to be able to synchronize 		    them over the network.
+            float batlength_; //!< The length of the bats (in z-direction) as percentage of the height of the playing field.
+            WeakPtr<OrxoBloxBat>* bat_; //!< 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/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxPrereqs.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxPrereqs.h	2019-03-14 15:03:00 UTC (rev 12211)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxPrereqs.h	2019-03-21 13:19:16 UTC (rev 12212)
@@ -42,23 +42,23 @@
 // Shared library settings
 //-----------------------------------------------------------------------
 
-#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(PONG_STATIC_BUILD)
-#  ifdef PONG_SHARED_BUILD
-#    define _PongExport __declspec(dllexport)
+#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(OrxoBlox_STATIC_BUILD)
+#  ifdef OrxoBlox_SHARED_BUILD
+#    define _OrxoBloxExport __declspec(dllexport)
 #  else
 #    if defined( __MINGW32__ )
-#      define _PongExport
+#      define _OrxoBloxExport
 #    else
-#      define _PongExport __declspec(dllimport)
+#      define _OrxoBloxExport __declspec(dllimport)
 #    endif
 #  endif
-#  define _PongPrivate
+#  define _OrxoBloxPrivate
 #elif defined (ORXONOX_GCC_VISIBILITY)
-#  define _PongExport  __attribute__ ((visibility("default")))
-#  define _PongPrivate __attribute__ ((visibility("hidden")))
+#  define _OrxoBloxExport  __attribute__ ((visibility("default")))
+#  define _OrxoBloxPrivate __attribute__ ((visibility("hidden")))
 #else
-#  define _PongExport
-#  define _PongPrivate
+#  define _OrxoBloxExport
+#  define _OrxoBloxPrivate
 #endif
 
 //-----------------------------------------------------------------------
@@ -67,13 +67,13 @@
 
 namespace orxonox
 {
-    class Pong;
-    class PongAI;
-    class PongBall;
-    class PongBat;
-    class PongBot;
-    class PongCenterpoint;
-    class PongScore;
+    class OrxoBlox;
+    class OrxoBloxAI;
+    class OrxoBloxBall;
+    class OrxoBloxBat;
+    class OrxoBloxBot;
+    class OrxoBloxCenterpoint;
+    class OrxoBloxScore;
 }
 
-#endif /* _PongPrereqs_H__ */
+#endif /* _OrxoBloxPrereqs_H__ */



More information about the Orxonox-commit mailing list