[Orxonox-commit 366] r2970 - in branches/gametypes/src/orxonox: objects/gametypes objects/worldentities/triggers overlays/hud
Aurelian at orxonox.net
Aurelian at orxonox.net
Mon May 11 17:00:55 CEST 2009
Author: Aurelian
Date: 2009-05-11 17:00:55 +0200 (Mon, 11 May 2009)
New Revision: 2970
Added:
branches/gametypes/src/orxonox/overlays/hud/HUDTimer.cc
branches/gametypes/src/orxonox/overlays/hud/HUDTimer.h
Modified:
branches/gametypes/src/orxonox/objects/gametypes/Asteroids.cc
branches/gametypes/src/orxonox/objects/gametypes/Asteroids.h
branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc
branches/gametypes/src/orxonox/objects/gametypes/Gametype.h
branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.cc
branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.h
branches/gametypes/src/orxonox/overlays/hud/CMakeLists.txt
Log:
Added timer in class gametype, timer working in asteroids, modified checkpoint with firstCheckPoint... working! yeepa ;-)
Modified: branches/gametypes/src/orxonox/objects/gametypes/Asteroids.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/Asteroids.cc 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/objects/gametypes/Asteroids.cc 2009-05-11 15:00:55 UTC (rev 2970)
@@ -42,8 +42,28 @@
Asteroids::Asteroids(BaseObject* creator) : Gametype(creator)
{
RegisterObject(Asteroids);
+ this->firstCheckpointReached_ = false;
+ this->timeLimit_ = 30;
}
+ void Asteroids::tick(float dt)
+ {
+ SUPER(Asteroids, tick, dt);
+
+ if (firstCheckpointReached_)
+ {
+ this->timeLimit_ = this->time_;
+ this->startTimer();
+ }
+
+ if (this->time_ < 0 && !this->hasEnded())
+ {
+ this->end();
+ }
+
+ }
+
+
void Asteroids::start()
{
Gametype::start();
Modified: branches/gametypes/src/orxonox/objects/gametypes/Asteroids.h
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/Asteroids.h 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/objects/gametypes/Asteroids.h 2009-05-11 15:00:55 UTC (rev 2970)
@@ -41,8 +41,18 @@
Asteroids(BaseObject* creator);
virtual ~Asteroids() {}
+ virtual void tick(float dt);
+
virtual void start();
virtual void end();
+
+ inline void firstCheckpointReached(bool reached)
+ { this->firstCheckpointReached_ = reached; }
+
+ private:
+ bool firstCheckpointReached_;
+ bool gameEnded_;
+
};
}
Modified: branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc 2009-05-11 15:00:55 UTC (rev 2970)
@@ -59,6 +59,10 @@
this->bForceSpawn_ = false;
this->numberOfBots_ = 0;
+ this->timeLimit_ = 0;
+ this->time_ = 0;
+ this->timerIsActive_ = false;
+
this->initialStartCountdown_ = 3;
this->setConfigValues();
@@ -87,6 +91,15 @@
{
SUPER(Gametype, tick, dt);
+ //count timer
+ if (timerIsActive_)
+ {
+ if (this->timeLimit_ == 0)
+ this->time_ += dt;
+ else
+ this->time_ -= dt;
+ }
+
if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
this->gtinfo_.startCountdown_ -= dt;
@@ -392,4 +405,31 @@
}
}
}
+
+ void Gametype::addTime(float t)
+ {
+ if (this->timeLimit_ == 0)
+ this->time_ -= t;
+ else
+ this->time_ += t;
+ }
+
+ void Gametype::removeTime(float t)
+ {
+ if (this->timeLimit_ == 0)
+ this->time_ += t;
+ else
+ this->time_ -= t;
+ }
+
+ void Gametype::resetTimer()
+ {
+ this->resetTimer(timeLimit_);
+ }
+
+ void Gametype::resetTimer(float t)
+ {
+ this->timeLimit_ = t;
+ this->time_ = t;
+ }
}
Modified: branches/gametypes/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/Gametype.h 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/objects/gametypes/Gametype.h 2009-05-11 15:00:55 UTC (rev 2970)
@@ -125,6 +125,24 @@
inline unsigned int getNumberOfPlayers() const
{ return this->players_.size(); }
+ virtual void addTime(float t);
+ virtual void removeTime(float t);
+
+ inline void startTimer()
+ { this->timerIsActive_ = true; }
+
+ inline void stopTimer()
+ { this->timerIsActive_ = false; }
+
+ inline float getTime()
+ { return this->time_; }
+
+ inline bool getTimerIsActive()
+ { return timerIsActive_; }
+
+ virtual void resetTimer();
+ virtual void resetTimer(float t);
+
protected:
virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
@@ -140,6 +158,10 @@
bool bAutoStart_;
bool bForceSpawn_;
+ float time_;
+ float timeLimit_;
+ bool timerIsActive_;
+
float initialStartCountdown_;
unsigned int numberOfBots_;
Modified: branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.cc 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.cc 2009-05-11 15:00:55 UTC (rev 2970)
@@ -46,8 +46,9 @@
RegisterObject(CheckPoint);
this->setStayActive(true);
- this->setDistance(20);
- bIsDestination_ = false;
+ this->setDistance(50);
+ this->bIsFirst_ = false;
+ this->bIsDestination_ = false;
this->setVisible(true);
}
@@ -59,31 +60,29 @@
{
SUPER(CheckPoint, XMLPort, xmlelement, mode);
+ XMLPortParam(CheckPoint, "isfirst", setFirst, getFirst, xmlelement, mode).defaultValues(false);
XMLPortParam(CheckPoint, "isdestination", setDestination, getDestination, xmlelement, mode).defaultValues(false);
+ XMLPortParam(CheckPoint, "addtime", setAddTime, getAddTime, xmlelement, mode).defaultValues(30);
}
- void CheckPoint::setDestination(bool isDestination)
- {
- bIsDestination_ = isDestination;
- }
-
- bool CheckPoint::getDestination()
- {
- return bIsDestination_;
- }
-
-
void CheckPoint::triggered(bool bIsTriggered)
{
DistanceTrigger::triggered(bIsTriggered);
- if (bIsTriggered && bIsDestination_)
- {
- Asteroids* gametype = dynamic_cast<Asteroids*>(this->getGametype());
- if (gametype)
- {
- gametype->end();
- }
- }
+ Asteroids* gametype = dynamic_cast<Asteroids*>(this->getGametype());
+ if (gametype)
+ {
+ gametype->addTime(addTime_);
+
+ if (bIsTriggered && bIsFirst_)
+ {
+ gametype->firstCheckpointReached(true);
+ }
+
+ if (bIsTriggered && bIsDestination_)
+ {
+ gametype->end();
+ }
+ }
}
}
Modified: branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.h
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.h 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/objects/worldentities/triggers/CheckPoint.h 2009-05-11 15:00:55 UTC (rev 2970)
@@ -56,10 +56,28 @@
private:
virtual void triggered(bool bIsTriggered);
- virtual void setDestination(bool isDestination);
- virtual bool getDestination();
+
+ inline void setDestination(bool isDestination)
+ { bIsDestination_ = isDestination; }
+
+ inline bool getDestination()
+ { return bIsDestination_; }
+
+ inline void setFirst(bool isFirst)
+ { this->bIsFirst_ = isFirst; }
+
+ inline bool getFirst()
+ { return this->bIsFirst_; }
+
+ inline void setAddTime(float time)
+ { this->addTime_ = time; }
+
+ inline bool getAddTime()
+ { return this->addTime_; }
+ bool bIsFirst_;
bool bIsDestination_;
+ float addTime_;
};
}
Modified: branches/gametypes/src/orxonox/overlays/hud/CMakeLists.txt
===================================================================
--- branches/gametypes/src/orxonox/overlays/hud/CMakeLists.txt 2009-05-11 13:58:38 UTC (rev 2969)
+++ branches/gametypes/src/orxonox/overlays/hud/CMakeLists.txt 2009-05-11 15:00:55 UTC (rev 2970)
@@ -4,6 +4,7 @@
HUDRadar.cc
HUDSpeedBar.cc
HUDHealthBar.cc
+ HUDTimer.cc
ChatOverlay.cc
GametypeStatus.cc
)
Added: branches/gametypes/src/orxonox/overlays/hud/HUDTimer.cc
===================================================================
--- branches/gametypes/src/orxonox/overlays/hud/HUDTimer.cc (rev 0)
+++ branches/gametypes/src/orxonox/overlays/hud/HUDTimer.cc 2009-05-11 15:00:55 UTC (rev 2970)
@@ -0,0 +1,75 @@
+/*
+ * 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:
+ * Aurelian Jaggi
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "HUDTimer.h"
+
+#include <OgreTextAreaOverlayElement.h>
+
+#include "core/CoreIncludes.h"
+#include "util/Convert.h"
+#include "objects/infos/GametypeInfo.h"
+#include "objects/infos/PlayerInfo.h"
+#include "objects/worldentities/ControllableEntity.h"
+#include "objects/worldentities/pawns/Spectator.h"
+#include "objects/gametypes/Gametype.h"
+
+namespace orxonox
+{
+ CreateFactory(HUDTimer);
+
+ HUDTimer::HUDTimer(BaseObject* creator) : OverlayText(creator)
+ {
+ RegisterObject(HUDTimer);
+
+ this->owner_ = 0;
+ }
+
+ HUDTimer::~HUDTimer()
+ {
+ }
+
+ void HUDTimer::tick(float dt)
+ {
+ SUPER(HUDTimer, tick, dt);
+
+ Gametype* gametype = this->getGametype();
+
+ if (gametype->getTimerIsActive())
+ {
+ this->setCaption(convertToString((int)gametype->getTime()));
+ }
+ }
+
+ void HUDTimer::changedOwner()
+ {
+ SUPER(HUDTimer, changedOwner);
+
+ this->owner_ = dynamic_cast<ControllableEntity*>(this->getOwner());
+ }
+}
Added: branches/gametypes/src/orxonox/overlays/hud/HUDTimer.h
===================================================================
--- branches/gametypes/src/orxonox/overlays/hud/HUDTimer.h (rev 0)
+++ branches/gametypes/src/orxonox/overlays/hud/HUDTimer.h 2009-05-11 15:00:55 UTC (rev 2970)
@@ -0,0 +1,53 @@
+/*
+ * 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:
+ * Aurelian Jaggi
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _HUDTimer_H__
+#define _HUDTimer_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "overlays/OverlayText.h"
+#include "objects/Tickable.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport HUDTimer : public OverlayText, public Tickable
+ {
+ public:
+ HUDTimer(BaseObject* creator);
+ ~HUDTimer();
+
+ virtual void tick(float dt);
+
+ virtual void changedOwner();
+
+ private:
+ ControllableEntity* owner_;
+ };
+}
+#endif /* _HUDTimer_H__ */
More information about the Orxonox-commit
mailing list