[Orxonox-commit 132] r2824 - in branches/miniprojects/src/orxonox: . objects/gametypes objects/worldentities
landauf at orxonox.net
landauf at orxonox.net
Mon Mar 23 11:26:46 CET 2009
Author: landauf
Date: 2009-03-23 10:26:46 +0000 (Mon, 23 Mar 2009)
New Revision: 2824
Added:
branches/miniprojects/src/orxonox/objects/gametypes/Pong.cc
branches/miniprojects/src/orxonox/objects/gametypes/Pong.h
branches/miniprojects/src/orxonox/objects/worldentities/PongBall.cc
branches/miniprojects/src/orxonox/objects/worldentities/PongBall.h
branches/miniprojects/src/orxonox/objects/worldentities/PongBat.cc
branches/miniprojects/src/orxonox/objects/worldentities/PongBat.h
branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.cc
branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.h
Modified:
branches/miniprojects/src/orxonox/OrxonoxPrereqs.h
branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt
branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc
branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h
branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc
branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h
branches/miniprojects/src/orxonox/objects/worldentities/CMakeLists.txt
branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.cc
branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.h
branches/miniprojects/src/orxonox/objects/worldentities/ControllableEntity.cc
Log:
Added "Pong" minigame
Modified: branches/miniprojects/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- branches/miniprojects/src/orxonox/OrxonoxPrereqs.h 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/OrxonoxPrereqs.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -103,6 +103,8 @@
class Radar;
class RadarListener;
+ class Teamcolourable;
+
class CameraManager;
class LevelManager;
class PawnManager;
@@ -148,9 +150,14 @@
class ParticleEmitter;
class ParticleSpawner;
+ class PongCenterpoint;
+ class PongBall;
+ class PongBat;
+
class Camera;
class CameraPosition;
class SpawnPoint;
+ class TeamSpawnPoint;
class Spectator;
class Pawn;
@@ -192,6 +199,9 @@
class GametypeInfo;
class Gametype;
+ class Deathmatch;
+ class TeamDeathmatch;
+ class Pong;
class Scores;
class CreateLines;
Modified: branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt 2009-03-23 10:26:46 UTC (rev 2824)
@@ -2,4 +2,5 @@
Gametype.cc
Deathmatch.cc
TeamDeathmatch.cc
+ Pong.cc
)
Modified: branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -48,14 +48,18 @@
{
Gametype::start();
- COUT(0) << "game started" << std::endl;
+ std::string message = "The match has started!";
+ COUT(0) << message << std::endl;
+ Host::Broadcast(message);
}
void Deathmatch::end()
{
Gametype::end();
- COUT(0) << "game ended" << std::endl;
+ std::string message = "The match has ended.";
+ COUT(0) << message << std::endl;
+ Host::Broadcast(message);
}
void Deathmatch::playerEntered(PlayerInfo* player)
@@ -116,4 +120,16 @@
Gametype::pawnKilled(victim, killer);
}
+
+ void Deathmatch::playerScored(PlayerInfo* player)
+ {
+ Gametype::playerScored(player);
+
+ if (player)
+ {
+ std::string message = player->getName() + " scores!";
+ COUT(0) << message << std::endl;
+ Host::Broadcast(message);
+ }
+ }
}
Modified: branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -48,6 +48,7 @@
virtual bool playerChangedName(PlayerInfo* player);
virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
+ virtual void playerScored(PlayerInfo* player);
};
}
Modified: branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -199,15 +199,7 @@
// Reward killer
if (killer)
- {
- std::map<PlayerInfo*, Player>::iterator itKiller = this->players_.find(killer->getPlayer());
- if (itKiller != this->players_.end())
- {
- this->playerScored(itKiller->second);
- }
- else
- COUT(2) << "Warning: Killing Pawn was not in the playerlist" << std::endl;
- }
+ this->playerScored(killer->getPlayer());
ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
if (victim->getCamera())
@@ -227,9 +219,11 @@
}
}
- void Gametype::playerScored(Player& player)
+ void Gametype::playerScored(PlayerInfo* player)
{
- player.frags_++;
+ std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
+ if (it != this->players_.end())
+ it->second.frags_++;
}
SpawnPoint* Gametype::getBestSpawnPoint(PlayerInfo* player) const
Modified: branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -88,7 +88,7 @@
virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype);
virtual bool playerChangedName(PlayerInfo* player);
- virtual void playerScored(Player& player);
+ virtual void playerScored(PlayerInfo* player);
virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
@@ -128,15 +128,12 @@
protected:
virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
- void addPlayer(PlayerInfo* player);
- void removePlayer(PlayerInfo* player);
+ virtual void assignDefaultPawnsIfNeeded();
+ virtual void checkStart();
+ virtual void spawnPlayer(PlayerInfo* player);
+ virtual void spawnPlayersIfRequested();
+ virtual void spawnDeadPlayersIfRequested();
- void assignDefaultPawnsIfNeeded();
- void checkStart();
- void spawnPlayer(PlayerInfo* player);
- void spawnPlayersIfRequested();
- void spawnDeadPlayersIfRequested();
-
GametypeInfo gtinfo_;
bool bAutoStart_;
Added: branches/miniprojects/src/orxonox/objects/gametypes/Pong.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Pong.cc (rev 0)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Pong.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,162 @@
+/*
+ * 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 "Pong.h"
+
+#include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/Executor.h"
+#include "objects/worldentities/Model.h"
+#include "objects/worldentities/PongCenterpoint.h"
+#include "objects/worldentities/PongBall.h"
+#include "objects/worldentities/PongBat.h"
+#include "objects/infos/PlayerInfo.h"
+
+namespace orxonox
+{
+ CreateUnloadableFactory(Pong);
+
+ Pong::Pong(BaseObject* creator) : Deathmatch(creator)
+ {
+ RegisterObject(Pong);
+
+ this->center_ = 0;
+ this->ball_ = 0;
+ this->bat_[0] = 0;
+ this->bat_[1] = 0;
+
+ this->bForceSpawn_ = true;
+
+ this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall)));
+ this->starttimer_.stopTimer();
+ }
+
+ void Pong::start()
+ {
+ if (this->center_)
+ {
+ if (!this->ball_)
+ {
+ this->ball_ = new PongBall(this->center_);
+ this->ball_->addTemplate(this->center_->getBalltemplate());
+ }
+
+ this->center_->attach(this->ball_);
+ this->ball_->setPosition(0, 0, 0);
+ this->ball_->setFieldDimension(this->center_->getFieldDimension());
+ this->ball_->setSpeed(0);
+ this->ball_->setBatLength(this->center_->getBatLength());
+
+ if (!this->bat_[0])
+ {
+ this->bat_[0] = new PongBat(this->center_);
+ this->bat_[0]->addTemplate(this->center_->getBattemplate());
+ }
+ if (!this->bat_[1])
+ {
+ this->bat_[1] = new PongBat(this->center_);
+ this->bat_[1]->addTemplate(this->center_->getBattemplate());
+ }
+
+ this->center_->attach(this->bat_[0]);
+ this->center_->attach(this->bat_[1]);
+ this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
+ this->bat_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
+ this->bat_[0]->yaw(Degree(-90));
+ this->bat_[1]->yaw(Degree(90));
+ this->bat_[0]->setSpeed(this->center_->getBatSpeed());
+ this->bat_[1]->setSpeed(this->center_->getBatSpeed());
+ this->bat_[0]->setFieldHeight(this->center_->getFieldDimension().y);
+ this->bat_[1]->setFieldHeight(this->center_->getFieldDimension().y);
+ this->bat_[0]->setLength(this->center_->getBatLength());
+ this->bat_[1]->setLength(this->center_->getBatLength());
+
+ this->ball_->setBats(this->bat_);
+ }
+ else
+ {
+ COUT(1) << "Error: No Centerpoint specified." << std::endl;
+ }
+
+ this->starttimer_.startTimer();
+
+ Deathmatch::start();
+ }
+
+ void Pong::end()
+ {
+ if (this->ball_)
+ {
+ delete this->ball_;
+ this->ball_ = 0;
+ }
+
+ Deathmatch::end();
+ }
+
+ void Pong::spawnPlayer(PlayerInfo* player)
+ {
+ if (!this->bat_[0]->getPlayer())
+ {
+ player->startControl(this->bat_[0]);
+ this->players_[player].state_ = PlayerState::Alive;
+ }
+ else if (!this->bat_[1]->getPlayer())
+ {
+ player->startControl(this->bat_[1]);
+ this->players_[player].state_ = PlayerState::Alive;
+ }
+ }
+
+ void Pong::playerScored(PlayerInfo* player)
+ {
+ Deathmatch::playerScored(player);
+
+ if (this->ball_)
+ {
+ this->ball_->setPosition(Vector3::ZERO);
+ this->ball_->setVelocity(Vector3::ZERO);
+ this->ball_->setSpeed(0);
+ }
+
+ if (this->bat_[0] && this->bat_[1])
+ {
+ this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
+ this->bat_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
+ }
+
+ this->starttimer_.startTimer();
+ }
+
+ void Pong::startBall()
+ {
+ if (this->ball_ && this->center_)
+ this->ball_->setSpeed(this->center_->getBallSpeed());
+ }
+}
Added: branches/miniprojects/src/orxonox/objects/gametypes/Pong.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Pong.h (rev 0)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Pong.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,65 @@
+/*
+ * 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 _Pong_H__
+#define _Pong_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "Deathmatch.h"
+#include "tools/Timer.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport Pong : public Deathmatch
+ {
+ public:
+ Pong(BaseObject* creator);
+ virtual ~Pong() {}
+
+ virtual void start();
+ virtual void end();
+
+ virtual void spawnPlayer(PlayerInfo* player);
+
+ virtual void playerScored(PlayerInfo* player);
+
+ void setCenterpoint(PongCenterpoint* center)
+ { this->center_ = center; }
+
+ protected:
+ void startBall();
+
+ PongCenterpoint* center_;
+ PongBall* ball_;
+ PongBat* bat_[2];
+ Timer<Pong> starttimer_;
+ };
+}
+
+#endif /* _Pong_H__ */
Modified: branches/miniprojects/src/orxonox/objects/worldentities/CMakeLists.txt
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/CMakeLists.txt 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/worldentities/CMakeLists.txt 2009-03-23 10:26:46 UTC (rev 2824)
@@ -19,6 +19,9 @@
Planet.cc
SpawnPoint.cc
TeamSpawnPoint.cc
+ PongCenterpoint.cc
+ PongBall.cc
+ PongBat.cc
)
ADD_SUBDIRECTORY(pawns)
Modified: branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.cc 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -43,6 +43,7 @@
this->bDrag_ = false;
this->bAllowMouseLook_ = false;
+ this->bAbsolute_ = false;
this->setObjectMode(0x0);
}
@@ -57,6 +58,7 @@
XMLPortParam(CameraPosition, "drag", setDrag, getDrag, xmlelement, mode).defaultValues(false);
XMLPortParam(CameraPosition, "mouselook", setAllowMouseLook, getAllowMouseLook, xmlelement, mode).defaultValues(false);
+ XMLPortParam(CameraPosition, "absolute", setIsAbsolute, getIsAbsolute, xmlelement, mode).defaultValues(false);
}
void CameraPosition::attachCamera(Camera* camera)
Modified: branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.h 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/worldentities/CameraPosition.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -53,11 +53,17 @@
inline bool getAllowMouseLook() const
{ return this->bAllowMouseLook_; }
+ inline void setIsAbsolute(bool bAbsolute)
+ { this->bAbsolute_ = bAbsolute; }
+ inline bool getIsAbsolute() const
+ { return this->bAbsolute_; }
+
void attachCamera(Camera* camera);
private:
bool bDrag_;
bool bAllowMouseLook_;
+ bool bAbsolute_;
};
}
Modified: branches/miniprojects/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/ControllableEntity.cc 2009-03-23 10:12:14 UTC (rev 2823)
+++ branches/miniprojects/src/orxonox/objects/worldentities/ControllableEntity.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -143,10 +143,19 @@
void ControllableEntity::addCameraPosition(CameraPosition* position)
{
- if (position->getAllowMouseLook())
- position->attachToNode(this->cameraPositionRootNode_);
+ if (!position->getIsAbsolute())
+ {
+ if (position->getAllowMouseLook())
+ position->attachToNode(this->cameraPositionRootNode_);
+ else
+ this->attach(position);
+ }
else
- this->attach(position);
+ {
+ WorldEntity* parent = this->getParent();
+ if (parent)
+ parent->attach(position);
+ }
this->cameraPositions_.push_back(position);
}
Added: branches/miniprojects/src/orxonox/objects/worldentities/PongBall.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/PongBall.cc (rev 0)
+++ branches/miniprojects/src/orxonox/objects/worldentities/PongBall.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,124 @@
+/*
+ * 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 "PongBall.h"
+
+#include "core/CoreIncludes.h"
+#include "objects/worldentities/PongBat.h"
+#include "objects/gametypes/Gametype.h"
+
+namespace orxonox
+{
+ CreateFactory(PongBall);
+
+ PongBall::PongBall(BaseObject* creator) : MovableEntity(creator)
+ {
+ RegisterObject(PongBall);
+
+ this->speed_ = 0;
+ this->bat_ = 0;
+ }
+
+ void PongBall::tick(float dt)
+ {
+ SUPER(PongBall, tick, dt);
+
+ if (Core::isMaster())
+ {
+ Vector3 position = this->getPosition();
+ Vector3 velocity = this->getVelocity();
+
+ if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
+ {
+ velocity.z = -velocity.z;
+
+ if (position.z > this->fieldHeight_ / 2)
+ position.z = this->fieldHeight_ / 2;
+ if (position.z < -this->fieldHeight_ / 2)
+ position.z = -this->fieldHeight_ / 2;
+ }
+
+ if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
+ {
+ velocity.x = -velocity.x;
+ float distance = 0;
+
+ if (position.x > this->fieldWidth_ / 2)
+ {
+ position.x = this->fieldWidth_ / 2;
+ if (this->bat_ && 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)
+ {
+ 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])
+ {
+ distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
+ if (this->getGametype() && this->bat_[1] && fabs(distance) > 1)
+ {
+ this->getGametype()->playerScored(this->bat_[1]->getPlayer());
+ return;
+ }
+ }
+ }
+
+ velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
+ }
+
+ if (velocity != this->getVelocity())
+ this->setVelocity(velocity);
+ if (position != this->getPosition())
+ this->setPosition(position);
+ }
+ }
+
+ void PongBall::setSpeed(float speed)
+ {
+ if (speed != this->speed_)
+ {
+ this->speed_ = speed;
+
+ Vector3 velocity = this->getVelocity();
+ if (velocity.x != 0)
+ velocity.x = sgn(velocity.x) * this->speed_;
+ else
+ velocity.x = this->speed_ * sgn(rnd(-1,1));
+
+ this->setVelocity(velocity);
+ }
+ }
+}
Added: branches/miniprojects/src/orxonox/objects/worldentities/PongBall.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/PongBall.h (rev 0)
+++ branches/miniprojects/src/orxonox/objects/worldentities/PongBall.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,72 @@
+/*
+ * 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 _PongBall_H__
+#define _PongBall_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "objects/worldentities/MovableEntity.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport PongBall : public MovableEntity
+ {
+ public:
+ PongBall(BaseObject* creator);
+ virtual ~PongBall() {}
+
+ virtual void tick(float dt);
+
+ void setFieldDimension(float width, float height)
+ { this->fieldWidth_ = width; this->fieldHeight_ = height; }
+ void setFieldDimension(const Vector2& dimension)
+ { this->setFieldDimension(dimension.x, dimension.y); }
+
+ void setSpeed(float speed);
+ float getSpeed() const
+ { return this->speed_; }
+
+ void setBatLength(float batlength)
+ { this->batlength_ = batlength; }
+ float getBatLength() const
+ { return this->batlength_; }
+
+ void setBats(PongBat** bats)
+ { this->bat_ = bats; }
+
+ private:
+ float fieldWidth_;
+ float fieldHeight_;
+ float speed_;
+ float batlength_;
+ PongBat** bat_;
+ };
+}
+
+#endif /* _PongBall_H__ */
Added: branches/miniprojects/src/orxonox/objects/worldentities/PongBat.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/PongBat.cc (rev 0)
+++ branches/miniprojects/src/orxonox/objects/worldentities/PongBat.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,100 @@
+/*
+ * 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 "PongBat.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+ CreateFactory(PongBat);
+
+ PongBat::PongBat(BaseObject* creator) : ControllableEntity(creator)
+ {
+ RegisterObject(PongBat);
+
+ this->movement_ = 0;
+ this->bMoveLocal_ = false;
+ this->speed_ = 60;
+ this->length_ = 0.25;
+ this->fieldHeight_ = 100;
+
+ this->registerVariables();
+ }
+
+ void PongBat::registerVariables()
+ {
+ registerVariable(this->speed_);
+ registerVariable(this->speed_);
+ registerVariable(this->speed_);
+ }
+
+ void PongBat::tick(float dt)
+ {
+ if (this->hasLocalController())
+ {
+ 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_);
+
+ this->movement_ = 0;
+ }
+
+ 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);
+ }
+ }
+
+ void PongBat::moveFrontBack(const Vector2& value)
+ {
+ this->bMoveLocal_ = false;
+ this->movement_ -= value.x;
+ }
+
+ void PongBat::moveRightLeft(const Vector2& value)
+ {
+ this->bMoveLocal_ = true;
+ this->movement_ = value.x;
+ }
+}
Added: branches/miniprojects/src/orxonox/objects/worldentities/PongBat.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/PongBat.h (rev 0)
+++ branches/miniprojects/src/orxonox/objects/worldentities/PongBat.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,74 @@
+/*
+ * 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 _PongBat_H__
+#define _PongBat_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "objects/worldentities/ControllableEntity.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport PongBat : public ControllableEntity
+ {
+ public:
+ PongBat(BaseObject* creator);
+ virtual ~PongBat() {}
+
+ void registerVariables();
+ virtual void tick(float dt);
+
+ virtual void moveFrontBack(const Vector2& value);
+ virtual void moveRightLeft(const Vector2& value);
+
+ void setSpeed(float speed)
+ { this->speed_ = speed; }
+ float getSpeed() const
+ { return this->speed_; }
+
+ void setFieldHeight(float height)
+ { this->fieldHeight_ = height; }
+ float getFieldHeight() const
+ { return this->fieldHeight_; }
+
+ void setLength(float length)
+ { this->length_ = length; }
+ float getLength() const
+ { return this->length_; }
+
+ private:
+ float movement_;
+ bool bMoveLocal_;
+ float speed_;
+ float length_;
+ float fieldHeight_;
+ };
+}
+
+#endif /* _PongBat_H__ */
Added: branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.cc (rev 0)
+++ branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.cc 2009-03-23 10:26:46 UTC (rev 2824)
@@ -0,0 +1,80 @@
+/*
+ * 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 "PongCenterpoint.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "objects/gametypes/Pong.h"
+
+namespace orxonox
+{
+ CreateFactory(PongCenterpoint);
+
+ PongCenterpoint::PongCenterpoint(BaseObject* creator) : StaticEntity(creator)
+ {
+ RegisterObject(PongCenterpoint);
+
+ this->width_ = 200;
+ this->height_ = 120;
+ this->ballspeed_ = 100;
+ this->batspeed_ = 60;
+ this->batlength_ = 0.25;
+
+ this->checkGametype();
+ }
+
+ void PongCenterpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(PongCenterpoint, XMLPort, xmlelement, mode);
+
+ XMLPortParam(PongCenterpoint, "dimension", setFieldDimension, getFieldDimension, xmlelement, mode);
+ XMLPortParam(PongCenterpoint, "balltemplate", setBalltemplate, getBalltemplate, xmlelement, mode);
+ XMLPortParam(PongCenterpoint, "battemplate", setBattemplate, getBattemplate, xmlelement, mode);
+ XMLPortParam(PongCenterpoint, "ballspeed", setBallSpeed, getBallSpeed, xmlelement, mode);
+ XMLPortParam(PongCenterpoint, "batspeed", setBatSpeed, getBatSpeed, xmlelement, mode);
+ XMLPortParam(PongCenterpoint, "batlength", setBatLength, getBatLength, xmlelement, mode);
+ }
+
+ void PongCenterpoint::changedGametype()
+ {
+ SUPER(PongCenterpoint, changedGametype);
+
+ this->checkGametype();
+ }
+
+ void PongCenterpoint::checkGametype()
+ {
+ if (this->getGametype() && this->getGametype()->isA(Class(Pong)))
+ {
+ Pong* pong_gametype = dynamic_cast<Pong*>(this->getGametype());
+ pong_gametype->setCenterpoint(this);
+ }
+ }
+}
Added: branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.h (rev 0)
+++ branches/miniprojects/src/orxonox/objects/worldentities/PongCenterpoint.h 2009-03-23 10:26:46 UTC (rev 2824)
@@ -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:
+ * ...
+ *
+ */
+
+#ifndef _PongCenterpoint_H__
+#define _PongCenterpoint_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "objects/worldentities/StaticEntity.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport PongCenterpoint : public StaticEntity
+ {
+ public:
+ PongCenterpoint(BaseObject* creator);
+ virtual ~PongCenterpoint() {}
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+ virtual void changedGametype();
+
+ void setBalltemplate(const std::string& balltemplate)
+ { this->balltemplate_ = balltemplate; }
+ const std::string& getBalltemplate() const
+ { return this->balltemplate_; }
+
+ void setBattemplate(const std::string& battemplate)
+ { this->battemplate_ = battemplate; }
+ const std::string& getBattemplate() const
+ { return this->battemplate_; }
+
+ void setFieldDimension(const Vector2& dimension)
+ { this->width_ = dimension.x; this->height_ = dimension.y; }
+ Vector2 getFieldDimension() const
+ { return Vector2(this->width_, this->height_); }
+
+ void setBallSpeed(float ballspeed)
+ { this->ballspeed_ = ballspeed; }
+ float getBallSpeed() const
+ { return this->ballspeed_; }
+
+ void setBatSpeed(float batspeed)
+ { this->batspeed_ = batspeed; }
+ float getBatSpeed() const
+ { return this->batspeed_; }
+
+ void setBatLength(float batlength)
+ { this->batlength_ = batlength; }
+ float getBatLength() const
+ { return this->batlength_; }
+
+ private:
+ void checkGametype();
+
+ std::string balltemplate_;
+ std::string battemplate_;
+
+ float ballspeed_;
+ float batspeed_;
+ float batlength_;
+
+ float width_;
+ float height_;
+ };
+}
+
+#endif /* _PongCenterpoint_H__ */
More information about the Orxonox-commit
mailing list