[Orxonox-commit 157] r2839 - in trunk/src/orxonox: . objects/controllers objects/gametypes objects/infos objects/worldentities

landauf at orxonox.net landauf at orxonox.net
Wed Mar 25 03:26:06 CET 2009


Author: landauf
Date: 2009-03-25 02:26:06 +0000 (Wed, 25 Mar 2009)
New Revision: 2839

Added:
   trunk/src/orxonox/objects/controllers/PongAI.cc
   trunk/src/orxonox/objects/controllers/PongAI.h
   trunk/src/orxonox/objects/infos/PongBot.cc
   trunk/src/orxonox/objects/infos/PongBot.h
Modified:
   trunk/src/orxonox/OrxonoxPrereqs.h
   trunk/src/orxonox/objects/controllers/CMakeLists.txt
   trunk/src/orxonox/objects/gametypes/Gametype.cc
   trunk/src/orxonox/objects/gametypes/Gametype.h
   trunk/src/orxonox/objects/gametypes/Pong.cc
   trunk/src/orxonox/objects/infos/CMakeLists.txt
   trunk/src/orxonox/objects/infos/PlayerInfo.cc
   trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
   trunk/src/orxonox/objects/worldentities/ControllableEntity.h
   trunk/src/orxonox/objects/worldentities/PongBall.cc
   trunk/src/orxonox/objects/worldentities/PongBall.h
   trunk/src/orxonox/objects/worldentities/PongBat.cc
   trunk/src/orxonox/objects/worldentities/PongBat.h
Log:
added AI for the Pong gametype
improved Pong gameplay


Modified: trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- trunk/src/orxonox/OrxonoxPrereqs.h	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/OrxonoxPrereqs.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -191,11 +191,13 @@
     class ArtificialController;
     class AIController;
     class ScriptController;
+    class PongAI;
 
     class Info;
     class PlayerInfo;
     class HumanPlayer;
     class Bot;
+    class PongBot;
     class GametypeInfo;
 
     class Gametype;

Modified: trunk/src/orxonox/objects/controllers/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/objects/controllers/CMakeLists.txt	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/controllers/CMakeLists.txt	2009-03-25 02:26:06 UTC (rev 2839)
@@ -4,4 +4,5 @@
   ArtificialController.cc
   AIController.cc
   ScriptController.cc
+  PongAI.cc
 )

Added: trunk/src/orxonox/objects/controllers/PongAI.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/PongAI.cc	                        (rev 0)
+++ trunk/src/orxonox/objects/controllers/PongAI.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -0,0 +1,93 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "PongAI.h"
+
+#include "core/CoreIncludes.h"
+#include "objects/worldentities/ControllableEntity.h"
+#include "objects/worldentities/PongBall.h"
+
+namespace orxonox
+{
+    CreateUnloadableFactory(PongAI);
+
+    PongAI::PongAI(BaseObject* creator) : Controller(creator)
+    {
+        RegisterObject(PongAI);
+
+        this->ball_ = 0;
+        this->randomOffset_ = 0;
+        this->relHysteresisOffset_ = 0.02;
+    }
+
+    void PongAI::tick(float dt)
+    {
+        if (!this->ball_ || !this->getControllableEntity())
+            return;
+
+        ControllableEntity* bat = this->getControllableEntity();
+
+        Vector3 mypos = bat->getPosition();
+        Vector3 ballpos = this->ball_->getPosition();
+        Vector3 ballvel = this->ball_->getVelocity();
+        float hysteresisOffset = this->relHysteresisOffset_ * this->ball_->getFieldDimension().y;
+
+        // Check in which direction the ball is flying
+        if ((mypos.x > 0 && ballvel.x < 0) || (mypos.x < 0 && ballvel.x > 0))
+        {
+            // Ball is flying away
+            this->calculateRandomOffset();
+
+            if (mypos.z > hysteresisOffset)
+                bat->moveFrontBack(1);
+            else if (mypos.z < -hysteresisOffset)
+                bat->moveFrontBack(-1);
+        }
+        else if (ballvel.x == 0)
+        {
+            // Ball is standing still
+            this->calculateRandomOffset();
+        }
+        else
+        {
+            // Ball is approaching
+            float desiredZValue = ballpos.z + this->randomOffset_;
+
+            if (mypos.z > desiredZValue + hysteresisOffset)
+                bat->moveFrontBack(1);
+            else if (mypos.z < desiredZValue - hysteresisOffset)
+                bat->moveFrontBack(-1);
+        }
+    }
+
+    void PongAI::calculateRandomOffset()
+    {
+        this->randomOffset_ = rnd(-0.45, 0.45) * this->ball_->getBatLength() * this->ball_->getFieldDimension().y;
+    }
+}


Property changes on: trunk/src/orxonox/objects/controllers/PongAI.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/src/orxonox/objects/controllers/PongAI.h
===================================================================
--- trunk/src/orxonox/objects/controllers/PongAI.h	                        (rev 0)
+++ trunk/src/orxonox/objects/controllers/PongAI.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -0,0 +1,59 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _PongAI_H__
+#define _PongAI_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "Controller.h"
+#include "objects/Tickable.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport PongAI : public Controller, public Tickable
+    {
+        public:
+            PongAI(BaseObject* creator);
+            virtual ~PongAI() {}
+
+            virtual void tick(float dt);
+
+            void setPongBall(PongBall* ball)
+                { this->ball_ = ball; }
+
+        protected:
+            void calculateRandomOffset();
+
+            PongBall* ball_;
+            float randomOffset_;
+            float relHysteresisOffset_;
+    };
+}
+
+#endif /* _PongAI_H__ */


Property changes on: trunk/src/orxonox/objects/controllers/PongAI.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/Gametype.cc	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/gametypes/Gametype.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -199,7 +199,11 @@
 
                 // Reward killer
                 if (killer)
-                    this->playerScored(killer->getPlayer());
+                {
+                    std::map<PlayerInfo*, Player>::iterator it = this->players_.find(killer->getPlayer());
+                    if (it != this->players_.end())
+                        it->second.frags_++;
+                }
 
                 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
                 if (victim->getCamera())
@@ -347,7 +351,7 @@
     void Gametype::addBots(unsigned int amount)
     {
         for (unsigned int i = 0; i < amount; ++i)
-            new Bot(this);
+            this->botclass_.fabricate(this);
     }
 
     void Gametype::killBots(unsigned int amount)

Modified: trunk/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- trunk/src/orxonox/objects/gametypes/Gametype.h	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/gametypes/Gametype.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -141,6 +141,7 @@
 
             float initialStartCountdown_;
             unsigned int numberOfBots_;
+            SubclassIdentifier<Bot> botclass_;
 
             std::map<PlayerInfo*, Player> players_;
             std::set<SpawnPoint*> spawnpoints_;

Modified: trunk/src/orxonox/objects/gametypes/Pong.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/Pong.cc	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/gametypes/Pong.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -36,7 +36,9 @@
 #include "objects/worldentities/PongCenterpoint.h"
 #include "objects/worldentities/PongBall.h"
 #include "objects/worldentities/PongBat.h"
-#include "objects/infos/PlayerInfo.h"
+#include "objects/infos/HumanPlayer.h"
+#include "objects/infos/PongBot.h"
+#include "objects/controllers/PongAI.h"
 
 namespace orxonox
 {
@@ -55,6 +57,8 @@
 
         this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall)));
         this->starttimer_.stopTimer();
+
+        this->botclass_ = Class(PongBot);
     }
 
     void Pong::start()
@@ -132,6 +136,14 @@
             player->startControl(this->bat_[1]);
             this->players_[player].state_ = PlayerState::Alive;
         }
+        else
+            return;
+
+        if (player && player->getController() && player->getController()->isA(Class(PongAI)))
+        {
+            PongAI* ai = dynamic_cast<PongAI*>(player->getController());
+            ai->setPongBall(this->ball_);
+        }
     }
 
     void Pong::playerScored(PlayerInfo* player)

Modified: trunk/src/orxonox/objects/infos/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/objects/infos/CMakeLists.txt	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/infos/CMakeLists.txt	2009-03-25 02:26:06 UTC (rev 2839)
@@ -1,5 +1,6 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
   Bot.cc
+  PongBot.cc
   Info.cc
   PlayerInfo.cc
   HumanPlayer.cc

Modified: trunk/src/orxonox/objects/infos/PlayerInfo.cc
===================================================================
--- trunk/src/orxonox/objects/infos/PlayerInfo.cc	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/infos/PlayerInfo.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -109,6 +109,11 @@
 
     void PlayerInfo::createController()
     {
+        if (this->controller_)
+        {
+            delete this->controller_;
+            this->controller_ = 0;
+        }
         this->controller_ = this->defaultController_.fabricate(this);
         assert(this->controller_);
         this->controller_->setPlayer(this);

Added: trunk/src/orxonox/objects/infos/PongBot.cc
===================================================================
--- trunk/src/orxonox/objects/infos/PongBot.cc	                        (rev 0)
+++ trunk/src/orxonox/objects/infos/PongBot.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -0,0 +1,46 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "PongBot.h"
+
+#include "core/CoreIncludes.h"
+#include "objects/controllers/PongAI.h"
+
+namespace orxonox
+{
+    CreateFactory(PongBot);
+
+    PongBot::PongBot(BaseObject* creator) : Bot(creator)
+    {
+        RegisterObject(PongBot);
+
+        this->defaultController_ = Class(PongAI);
+        this->createController();
+    }
+}


Property changes on: trunk/src/orxonox/objects/infos/PongBot.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/src/orxonox/objects/infos/PongBot.h
===================================================================
--- trunk/src/orxonox/objects/infos/PongBot.h	                        (rev 0)
+++ trunk/src/orxonox/objects/infos/PongBot.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -0,0 +1,46 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _PongBot_H__
+#define _PongBot_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "Bot.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport PongBot : public Bot
+    {
+        public:
+            PongBot(BaseObject* creator);
+            virtual ~PongBot() {}
+    };
+}
+
+#endif /* _PongBot_H__ */


Property changes on: trunk/src/orxonox/objects/infos/PongBot.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/worldentities/ControllableEntity.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -250,6 +250,8 @@
                 this->setObjectMode(objectDirection::bidirectional);
             }
         }
+
+        this->changedPlayer();
     }
 
     void ControllableEntity::removePlayer()
@@ -263,6 +265,8 @@
         this->bHasHumanController_ = false;
         this->setObjectMode(objectDirection::toclient);
 
+        this->changedPlayer();
+
         if (this->bDestroyWhenPlayerLeft_)
             delete this;
     }

Modified: trunk/src/orxonox/objects/worldentities/ControllableEntity.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/ControllableEntity.h	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/worldentities/ControllableEntity.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -48,6 +48,7 @@
             void setConfigValues();
 
             virtual void changedGametype();
+            virtual void changedPlayer() {}
 
             virtual void setPlayer(PlayerInfo* player);
             virtual void removePlayer();

Modified: trunk/src/orxonox/objects/worldentities/PongBall.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/PongBall.cc	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/worldentities/PongBall.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -43,6 +43,7 @@
 
         this->speed_ = 0;
         this->bat_ = 0;
+        this->relMercyOffset_ = 0.05;
     }
 
     void PongBall::tick(float dt)
@@ -66,37 +67,47 @@
 
             if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
             {
-                velocity.x = -velocity.x;
                 float distance = 0;
 
-                if (position.x > this->fieldWidth_ / 2)
+                if (this->bat_)
                 {
-                    position.x = this->fieldWidth_ / 2;
-                    if (this->bat_ && this->bat_[1])
+                    if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
                     {
-                        distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
-                        if (this->getGametype() && this->bat_[0] && fabs(distance) > 1)
+                        distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
+                        if (fabs(distance) <= 1)
                         {
-                            this->getGametype()->playerScored(this->bat_[0]->getPlayer());
-                            return;
+                            position.x = this->fieldWidth_ / 2;
+                            velocity.x = -velocity.x;
+                            velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
                         }
+                        else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
+                        {
+                            if (this->getGametype() && this->bat_[0])
+                            {
+                                this->getGametype()->playerScored(this->bat_[0]->getPlayer());
+                                return;
+                            }
+                        }
                     }
-                }
-                if (position.x < -this->fieldWidth_ / 2)
-                {
-                    position.x = -this->fieldWidth_ / 2;
-                    if (this->bat_ && this->bat_[0])
+                    if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
                     {
-                        distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
-                        if (this->getGametype() && this->bat_[1] && fabs(distance) > 1)
+                        distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
+                        if (fabs(distance) <= 1)
                         {
-                            this->getGametype()->playerScored(this->bat_[1]->getPlayer());
-                            return;
+                            position.x = -this->fieldWidth_ / 2;
+                            velocity.x = -velocity.x;
+                            velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
                         }
+                        else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
+                        {
+                            if (this->getGametype() && this->bat_[1])
+                            {
+                                this->getGametype()->playerScored(this->bat_[1]->getPlayer());
+                                return;
+                            }
+                        }
                     }
                 }
-
-                velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
             }
 
             if (velocity != this->getVelocity())

Modified: trunk/src/orxonox/objects/worldentities/PongBall.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/PongBall.h	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/worldentities/PongBall.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -47,6 +47,8 @@
                 { this->fieldWidth_ = width; this->fieldHeight_ = height; }
             void setFieldDimension(const Vector2& dimension)
                 { this->setFieldDimension(dimension.x, dimension.y); }
+            Vector2 getFieldDimension() const
+                { return Vector2(this->fieldWidth_, this->fieldHeight_); }
 
             void setSpeed(float speed);
             float getSpeed() const
@@ -66,6 +68,7 @@
             float speed_;
             float batlength_;
             PongBat** bat_;
+            float relMercyOffset_;
     };
 }
 

Modified: trunk/src/orxonox/objects/worldentities/PongBat.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/PongBat.cc	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/worldentities/PongBat.cc	2009-03-25 02:26:06 UTC (rev 2839)
@@ -45,6 +45,7 @@
         this->speed_ = 60;
         this->length_ = 0.25;
         this->fieldHeight_ = 100;
+        this->bSteadiedPosition_ = false;
 
         this->registerVariables();
     }
@@ -60,30 +61,36 @@
     {
         if (this->hasLocalController())
         {
-            this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
+            if (this->movement_ != 0)
+            {
+                this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
 
-            if (this->bMoveLocal_)
-                this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
-            else
-                this->setVelocity(0, 0, this->movement_);
+                if (this->bMoveLocal_)
+                    this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
+                else
+                    this->setVelocity(0, 0, this->movement_);
 
-            this->movement_ = 0;
+                this->movement_ = 0;
+                this->bSteadiedPosition_ = false;
+            }
+            else if (!this->bSteadiedPosition_)
+            {
+                // To ensure network synchronicity
+                this->setVelocity(0, 0, 0);
+                this->setPosition(this->getPosition());
+                this->bSteadiedPosition_ = true;
+            }
         }
 
         SUPER(PongBat, tick, dt);
 
-        if (this->hasLocalController())
-        {
-            Vector3 position = this->getPosition();
-
-            if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
-                position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
-            if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
-                position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
-
-            if (position != this->getPosition())
-                this->setPosition(position);
-        }
+        Vector3 position = this->getPosition();
+        if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
+            position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
+        if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
+            position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
+        if (position != this->getPosition())
+            this->setPosition(position);
     }
 
     void PongBat::moveFrontBack(const Vector2& value)
@@ -97,4 +104,9 @@
         this->bMoveLocal_ = true;
         this->movement_ = value.x;
     }
+
+    void PongBat::changedPlayer()
+    {
+        this->setVelocity(0, 0, 0);
+    }
 }

Modified: trunk/src/orxonox/objects/worldentities/PongBat.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/PongBat.h	2009-03-24 13:50:13 UTC (rev 2838)
+++ trunk/src/orxonox/objects/worldentities/PongBat.h	2009-03-25 02:26:06 UTC (rev 2839)
@@ -47,6 +47,8 @@
             virtual void moveFrontBack(const Vector2& value);
             virtual void moveRightLeft(const Vector2& value);
 
+            virtual void changedPlayer();
+
             void setSpeed(float speed)
                 { this->speed_ = speed; }
             float getSpeed() const
@@ -68,6 +70,7 @@
             float speed_;
             float length_;
             float fieldHeight_;
+            bool bSteadiedPosition_;
     };
 }
 




More information about the Orxonox-commit mailing list