[Orxonox-commit 3560] r8246 - in code/branches/tetris: data/levels src/modules src/modules/pong src/modules/tetris
dafrick at orxonox.net
dafrick at orxonox.net
Mon Apr 18 12:34:22 CEST 2011
Author: dafrick
Date: 2011-04-18 12:34:22 +0200 (Mon, 18 Apr 2011)
New Revision: 8246
Added:
code/branches/tetris/data/levels/tetris.oxw
code/branches/tetris/src/modules/tetris/
code/branches/tetris/src/modules/tetris/Tetris.cc
code/branches/tetris/src/modules/tetris/Tetris.h
code/branches/tetris/src/modules/tetris/TetrisCenterpoint.cc
code/branches/tetris/src/modules/tetris/TetrisCenterpoint.h
code/branches/tetris/src/modules/tetris/TetrisPrereqs.h
code/branches/tetris/src/modules/tetris/TetrisStone.cc
code/branches/tetris/src/modules/tetris/TetrisStone.h
Removed:
code/branches/tetris/src/modules/tetris/PongBall.cc
code/branches/tetris/src/modules/tetris/PongBall.h
Modified:
code/branches/tetris/src/modules/CMakeLists.txt
code/branches/tetris/src/modules/pong/PongBat.h
code/branches/tetris/src/modules/tetris/CMakeLists.txt
Log:
A place to start for tetris.
Added: code/branches/tetris/data/levels/tetris.oxw
===================================================================
--- code/branches/tetris/data/levels/tetris.oxw (rev 0)
+++ code/branches/tetris/data/levels/tetris.oxw 2011-04-18 10:34:22 UTC (rev 8246)
@@ -0,0 +1,61 @@
+<LevelInfo
+ name = "Tetris"
+ description = "Tetris in space!"
+ tags = ""
+/>
+
+<?lua
+ include("HUDTemplates3.oxo")
+ include("stats.oxo")
+ include("templates/lodInformation.oxt")
+?>
+
+<Template name=tetrisstonecameras defaults=0>
+ <TetrisStone>
+ <camerapositions>
+ <CameraPosition position="55,75,200" absolute=true />
+ <CameraPosition position="0,50,160" drag=true mouselook=true />
+ <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true />
+ </camerapositions>
+ </TetrisStone>
+</Template>
+
+<Template name=tetrisstone>
+ <TetrisStone camerapositiontemplate=tetrisstonecameras>
+ <attached>
+ <Model position="0,0,0" mesh="crate.mesh" scale=1 />
+ </attached>
+ </TetrisStone>
+</Template>
+
+<Level
+ name = "Presentation"
+ description = "A simple testlevel"
+ gametype = "Tetris"
+>
+ <templates>
+ <Template link=lodtemplate_default />
+ </templates>
+
+ <Scene
+ ambientlight = "0.5, 0.5, 0.5"
+ skybox = "Orxonox/skypanoramagen1"
+ >
+ <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+
+ <?lua
+ for i = 1, 10, 1 do
+ ?>
+ <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" />
+ <?lua end ?>
+
+ <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone stoneSpeed=5 position="-55,-75,0">
+ <attached>
+ <Model position="55,-1,0" mesh="cube.mesh" scale3D="57,1,11" />
+ <Model position="-1,76,0" mesh="cube.mesh" scale3D="1,76,1" />
+ <Model position="111,76,0" mesh="cube.mesh" scale3D="1,76,1" />
+ </attached>
+ </TetrisCenterpoint>
+
+ </Scene>
+</Level>
Modified: code/branches/tetris/src/modules/CMakeLists.txt
===================================================================
--- code/branches/tetris/src/modules/CMakeLists.txt 2011-04-16 09:19:06 UTC (rev 8245)
+++ code/branches/tetris/src/modules/CMakeLists.txt 2011-04-18 10:34:22 UTC (rev 8246)
@@ -32,4 +32,5 @@
ADD_SUBDIRECTORY(pickup)
ADD_SUBDIRECTORY(pong)
ADD_SUBDIRECTORY(questsystem)
+ADD_SUBDIRECTORY(tetris)
ADD_SUBDIRECTORY(weapons)
Modified: code/branches/tetris/src/modules/pong/PongBat.h
===================================================================
--- code/branches/tetris/src/modules/pong/PongBat.h 2011-04-16 09:19:06 UTC (rev 8245)
+++ code/branches/tetris/src/modules/pong/PongBat.h 2011-04-18 10:34:22 UTC (rev 8246)
@@ -99,7 +99,7 @@
void setLength(float length)
{ this->length_ = length; }
/**
- @brief get the length of the bat.
+ @brief Get the length of the bat.
@return Returns the length of the bat (in z-direction) as percentage of the height of the playing field.
*/
float getLength() const
Modified: code/branches/tetris/src/modules/tetris/CMakeLists.txt
===================================================================
--- code/branches/tetris/src/modules/pong/CMakeLists.txt 2011-04-09 13:33:06 UTC (rev 8213)
+++ code/branches/tetris/src/modules/tetris/CMakeLists.txt 2011-04-18 10:34:22 UTC (rev 8246)
@@ -1,20 +1,13 @@
-SET_SOURCE_FILES(PONG_SRC_FILES
-COMPILATION_BEGIN PongCompilation.cc
- Pong.cc
- PongAI.cc
- PongBall.cc
- PongBat.cc
- PongBot.cc
- PongCenterpoint.cc
- PongScore.cc
-COMPILATION_END
+SET_SOURCE_FILES(TETRIS_SRC_FILES
+ Tetris.cc
+ TetrisCenterpoint.cc
+ TetrisStone.cc
)
-ORXONOX_ADD_LIBRARY(pong
+ORXONOX_ADD_LIBRARY(tetris
MODULE
FIND_HEADER_FILES
LINK_LIBRARIES
orxonox
- overlays
- SOURCE_FILES ${PONG_SRC_FILES}
+ SOURCE_FILES ${TETRIS_SRC_FILES}
)
Deleted: code/branches/tetris/src/modules/tetris/PongBall.cc
===================================================================
--- code/branches/tetris/src/modules/pong/PongBall.cc 2011-04-09 13:33:06 UTC (rev 8213)
+++ code/branches/tetris/src/modules/tetris/PongBall.cc 2011-04-18 10:34:22 UTC (rev 8246)
@@ -1,264 +0,0 @@
-/*
- * 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:
- * ...
- *
- */
-
-/**
- @file PongBall.cc
- @brief Implementation of the PongBall class.
-*/
-
-#include "PongBall.h"
-
-#include "core/CoreIncludes.h"
-#include "core/GameMode.h"
-
-#include "gametypes/Gametype.h"
-
-#include "PongBat.h"
-
-namespace orxonox
-{
- CreateFactory(PongBall);
-
- const float PongBall::MAX_REL_Z_VELOCITY = 1.5;
-
- /**
- @brief
- Constructor. Registers and initializes the object.
- */
- PongBall::PongBall(BaseObject* creator)
- : MovableEntity(creator)
- {
- RegisterObject(PongBall);
-
- this->speed_ = 0;
- this->accelerationFactor_ = 1.0f;
- this->bat_ = 0;
- 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();
- }
-
- /**
- @brief
- Destructor.
- */
- PongBall::~PongBall()
- {
- if (this->isInitialized())
- {
- if (this->bDeleteBats_)
- delete[] this->bat_;
-
- delete[] this->batID_;
- }
- }
-
- /**
- @brief
- Register variables to synchronize over the network.
- */
- void PongBall::registerVariables()
- {
- registerVariable( this->fieldWidth_ );
- registerVariable( this->fieldHeight_ );
- registerVariable( this->batlength_ );
- registerVariable( this->speed_ );
- registerVariable( this->relMercyOffset_ );
- registerVariable( this->batID_[0] );
- registerVariable( this->batID_[1], VariableDirection::ToClient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
- }
-
- /**
- @brief
- Is called every tick.
- Handles the movement of the ball and its interaction with the boundaries and bats.
- @param dt
- The time since the last tick.
- */
- void PongBall::tick(float dt)
- {
- SUPER(PongBall, tick, dt);
-
- // Get the current position, velocity and acceleration of the ball.
- Vector3 position = this->getPosition();
- Vector3 velocity = this->getVelocity();
- Vector3 acceleration = this->getAcceleration();
-
- // 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)
- {
- // Its velocity in z-direction is inverted (i.e. it bounces off).
- velocity.z = -velocity.z;
- // And its position is set as to not overstep the boundary it has just crossed.
- if (position.z > this->fieldHeight_ / 2)
- position.z = this->fieldHeight_ / 2;
- if (position.z < -this->fieldHeight_ / 2)
- position.z = -this->fieldHeight_ / 2;
-
- this->fireEvent();
- }
-
- // If the ball has crossed the left or right boundary of the playing field (i.e. a player has just scored, if the bat isn't there to parry).
- if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
- {
- float distance = 0;
-
- if (this->bat_ != NULL) // If there are bats.
- {
- // If the right boundary has been crossed.
- if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL)
- {
- // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
- distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
- if (fabs(distance) <= 1) // If the bat is there to parry.
- {
- // 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) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
- acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;
-
- this->fireEvent();
- }
- // If the left player scores.
- else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
- {
- if (this->getGametype() && this->bat_[0])
- {
- this->getGametype()->playerScored(this->bat_[0]->getPlayer());
- return;
- }
- }
- }
- // If the left boundary has been crossed.
- else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL)
- {
- // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)
- distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);
- if (fabs(distance) <= 1) // If the bat is there to parry.
- {
- // 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) * PongBall::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_))
- {
- 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.
- if (acceleration != this->getAcceleration())
- this->setAcceleration(acceleration);
- if (velocity != this->getVelocity())
- this->setVelocity(velocity);
- if (position != this->getPosition())
- this->setPosition(position);
- }
-
- /**
- @brief
- Set the speed of the ball (in x-direction).
- @param speed
- The speed to be set.
- */
- void PongBall::setSpeed(float speed)
- {
- if (speed != this->speed_) // If the speed changes
- {
- this->speed_ = speed;
-
- // Set the speed in the direction of the balls current velocity.
- Vector3 velocity = this->getVelocity();
- if (velocity.x != 0)
- velocity.x = sgn(velocity.x) * this->speed_;
- else // If the balls current velocity is zero, the speed is set in a random direction.
- velocity.x = this->speed_ * sgn(rnd(-1,1));
-
- this->setVelocity(velocity);
- }
- }
-
- /**
- @brief
- Set the bats for the ball.
- @param bats
- An array (of size 2) of weak pointers, to be set as the new bats.
- */
- void PongBall::setBats(WeakPtr<PongBat>* bats)
- {
- if (this->bDeleteBats_) // If there are already some bats, delete them.
- {
- delete[] this->bat_;
- this->bDeleteBats_ = false;
- }
-
- this->bat_ = bats;
- // Also store their object IDs, for synchronization.
- this->batID_[0] = this->bat_[0]->getObjectID();
- this->batID_[1] = this->bat_[1]->getObjectID();
- }
-
- /**
- @brief
- Get the bats over the network.
- */
- void PongBall::applyBats()
- {
- // Make space for the bats, if they don't exist, yet.
- if (this->bat_ == NULL)
- {
- this->bat_ = new WeakPtr<PongBat>[2];
- this->bDeleteBats_ = true;
- }
-
- if (this->batID_[0] != OBJECTID_UNKNOWN)
- this->bat_[0] = orxonox_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0]));
- if (this->batID_[1] != OBJECTID_UNKNOWN)
- this->bat_[1] = orxonox_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1]));
- }
-}
Deleted: code/branches/tetris/src/modules/tetris/PongBall.h
===================================================================
--- code/branches/tetris/src/modules/pong/PongBall.h 2011-04-09 13:33:06 UTC (rev 8213)
+++ code/branches/tetris/src/modules/tetris/PongBall.h 2011-04-18 10:34:22 UTC (rev 8246)
@@ -1,140 +0,0 @@
-/*
- * 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:
- * ...
- *
- */
-
-/**
- @file PongBall.h
- @brief Declaration of the PongBall class.
- @ingroup Pong
-*/
-
-#ifndef _PongBall_H__
-#define _PongBall_H__
-
-#include "pong/PongPrereqs.h"
-
-#include "util/Math.h"
-
-#include "worldentities/MovableEntity.h"
-
-namespace orxonox
-{
-
- /**
- @brief
- This class manages the ball for @ref orxonox::Pong "Pong".
-
- 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::PongCenterpoint "PongCenterpoint") and the @ref orxonox::PongBat "PongBats". Or more precisely, it makes the ball bounce off then upper and lower delimiters of the playing field, it makes the ball bounce off the bats and also detects when a player scores and takes appropriate measures.
-
- @author
- Fabian 'x3n' Landau
-
- @ingroup Pong
- */
- class _PongExport PongBall : public MovableEntity
- {
- public:
- PongBall(BaseObject* creator);
- virtual ~PongBall();
-
- virtual void tick(float dt);
-
- /**
- @brief Set the dimensions of the playing field.
- @param width The width of the playing field.
- @param height The height of the playing field.
- */
- void setFieldDimension(float width, float height)
- { this->fieldWidth_ = width; this->fieldHeight_ = height; }
- /**
- @brief Get the dimensions of the playing field.
- @param dimension A vector with the width as the first and height as the second component.
- */
- void setFieldDimension(const Vector2& dimension)
- { this->setFieldDimension(dimension.x, dimension.y); }
- /**
- @brief Get the dimensions of the playing field.
- @return Returns a vector with the width as the first and height as the second component.
- */
- Vector2 getFieldDimension() const
- { return Vector2(this->fieldWidth_, this->fieldHeight_); }
-
- void setSpeed(float speed); //!< Set the speed of the ball (in x-direction).
- /**
- @brief Get the speed of the ball (in x-direction).
- @return Returns the speed of the ball (in x-direction).
- */
- float getSpeed() const
- { return this->speed_; }
-
- /**
- @brief Set the acceleration factor of the ball.
- @param factor The factor the acceleration of the ball is set to.
- */
- void setAccelerationFactor(float factor)
- { this->accelerationFactor_ = factor; }
- /**
- @brief Get the acceleration factor of the ball.
- @return Returns the acceleration factor of the ball.
- */
- float getAccelerationFactor() const
- { return this->accelerationFactor_; }
-
- /**
- @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 setBatLength(float batlength)
- { this->batlength_ = batlength; }
- /**
- @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 getBatLength() const
- { return this->batlength_; }
-
- void setBats(WeakPtr<PongBat>* bats); //!< Set the bats for the ball.
- void applyBats(); //!< Get the bats over the network.
-
- static const float MAX_REL_Z_VELOCITY;
-
- private:
- void registerVariables();
-
- float fieldWidth_; //!< The width of the playing field.
- float fieldHeight_; //!< The height of the playing field.
- float speed_; //!< The speed (in x-direction) of the ball.
- float accelerationFactor_; //!< The acceleration factor of the ball.
- float batlength_; //!< The length of the bats (in z-direction) as percentage of the height of the playing field.
- WeakPtr<PongBat>* 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.
- };
-}
-
-#endif /* _PongBall_H__ */
Added: code/branches/tetris/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/tetris/src/modules/tetris/Tetris.cc (rev 0)
+++ code/branches/tetris/src/modules/tetris/Tetris.cc 2011-04-18 10:34:22 UTC (rev 8246)
@@ -0,0 +1,233 @@
+/*
+ * 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:
+ * ...
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file Tetris.cc
+ @brief Implementation of the Tetris class.
+*/
+
+#include "Tetris.h"
+
+#include "core/CoreIncludes.h"
+#include "core/EventIncludes.h"
+#include "core/command/Executor.h"
+
+#include "gamestates/GSLevel.h"
+
+#include "TetrisCenterpoint.h"
+#include "TetrisStone.h"
+#include "infos/PlayerInfo.h"
+
+namespace orxonox
+{
+
+ CreateUnloadableFactory(Tetris);
+
+ /**
+ @brief
+ Constructor. Registers and initializes the object.
+ */
+ Tetris::Tetris(BaseObject* creator) : Deathmatch(creator)
+ {
+ RegisterObject(Tetris);
+
+ this->activeStone_ = NULL;
+
+ // Pre-set the timer, but don't start it yet.
+ this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startStone, this)));
+ this->starttimer_.stopTimer();
+ }
+
+ /**
+ @brief
+ Destructor. Cleans up, if initialized.
+ */
+ Tetris::~Tetris()
+ {
+ if (this->isInitialized())
+ this->cleanup();
+ }
+
+ /**
+ @brief
+ Cleans up the Gametype.
+ */
+ void Tetris::cleanup()
+ {
+
+ }
+
+ void Tetris::tick(float dt)
+ {
+ SUPER(Tetris, tick, dt);
+
+ TetrisStone* stone = this->activeStone_;
+ if(stone != NULL)
+ {
+ Vector3 position = stone->getPosition();
+ if(position.x < this->center_->getStoneSize()/2.0)
+ position.x = this->center_->getStoneSize()/2.0;
+ else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize())
+ position.x = (this->center_->getWidth()-0.5)*this->center_->getStoneSize();
+
+ if(position.y < this->center_->getStoneSize()/2.0)
+ {
+ position.y = this->center_->getStoneSize()/2.0;
+ stone->setVelocity(Vector3::ZERO);
+ this->createStone();
+ this->startStone();
+ }
+
+ stone->setPosition(position);
+ }
+ }
+
+ /**
+ @brief
+ Starts the Tetris minigame.
+ */
+ void Tetris::start()
+ {
+ if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.
+ {
+ // Create the first stone.
+ this->createStone();
+ }
+ else // If no centerpoint was specified, an error is thrown and the level is exited.
+ {
+ COUT(1) << "Error: No Centerpoint specified." << std::endl;
+ GSLevel::startMainMenu();
+ return;
+ }
+
+ // Start the timer. After it has expired the ball is started.
+ this->starttimer_.startTimer();
+
+ // Set variable to temporarily force the player to spawn.
+ bool temp = this->bForceSpawn_;
+ this->bForceSpawn_ = true;
+
+ // Call start for the parent class.
+ Deathmatch::start();
+
+ // Reset the variable.
+ this->bForceSpawn_ = temp;
+ }
+
+ /**
+ @brief
+ Ends the Tetris minigame.
+ */
+ void Tetris::end()
+ {
+ this->cleanup();
+
+ // Call end for the parent class.
+ Deathmatch::end();
+ }
+
+ /**
+ @brief
+ Spawns player.
+ */
+ void Tetris::spawnPlayersIfRequested()
+ {
+ // Spawn a human player.
+ for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+ if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))
+ this->spawnPlayer(it->first);
+ }
+
+ /**
+ @brief
+ Spawns the input player.
+ @param player
+ The player to be spawned.
+ */
+ void Tetris::spawnPlayer(PlayerInfo* player)
+ {
+ assert(player);
+
+ if(this->player_ != NULL)
+ {
+ this->player_ = player;
+ this->players_[player].state_ = PlayerState::Alive;
+ }
+ }
+
+ /**
+ @brief
+ Starts the first stone.
+ */
+ void Tetris::startStone(void)
+ {
+ if(this->player_ == NULL)
+ return;
+
+ if(this->activeStone_ != NULL)
+ this->player_->stopControl();
+
+ // Make the last stone to be created the active stone.
+ this->activeStone_ = this->stones_.back();
+
+ this->player_->startControl(this->activeStone_);
+ this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
+ }
+
+ /**
+ @brief
+ Creates a new stone.
+ */
+ void Tetris::createStone(void)
+ {
+ // Create a new stone and add it to the list of stones.
+ TetrisStone* stone = new TetrisStone(this->center_);
+ this->stones_.push_back(stone);
+
+ // Apply the stone template to the stone.
+ stone->addTemplate(this->center_->getStoneTemplate());
+
+ // Attach the stone to the Centerpoint and set the position of the stone to be at the top middle.
+ this->center_->attach(stone);
+ float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0)*this->center_->getStoneSize();
+ float yPos = (this->center_->getHeight()-0.5)*this->center_->getStoneSize();
+ stone->setPosition(xPos, yPos, 0.0f);
+ }
+
+ /**
+ @brief
+ Get the player.
+ @return
+ Returns a pointer to the player. If there is no player, NULL is returned.
+ */
+ PlayerInfo* Tetris::getPlayer(void) const
+ {
+ return this->player_;
+ }
+
+}
Added: code/branches/tetris/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/tetris/src/modules/tetris/Tetris.h (rev 0)
+++ code/branches/tetris/src/modules/tetris/Tetris.h 2011-04-18 10:34:22 UTC (rev 8246)
@@ -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:
+ * ...
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file Tetris.h
+ @brief Declaration of the Tetris class.
+ @ingroup Tetris
+*/
+
+#ifndef _Tetris_H__
+#define _Tetris_H__
+
+#include "tetris/TetrisPrereqs.h"
+
+#include "tools/Timer.h"
+
+#include "gametypes/Deathmatch.h"
+
+namespace orxonox
+{
+
+ /**
+ @brief
+
+ @author
+
+ @ingroup Tetris
+ */
+ class _TetrisExport Tetris : public Deathmatch
+ {
+ public:
+ Tetris(BaseObject* creator); //!< Constructor. Registers and initializes the object.
+ virtual ~Tetris(); //!< Destructor. Cleans up, if initialized.
+
+ virtual void tick(float dt);
+
+ virtual void start(void); //!< Starts the Tetris minigame.
+ virtual void end(void); ///!< Ends the Tetris minigame.
+
+ virtual void spawnPlayer(PlayerInfo* player); //!< Spawns the input player.
+
+ /**
+ @brief Set the TetrisCenterpoint (the playing field).
+ @param center A pointer to the TetrisCenterpoint to be set.
+ */
+ void setCenterpoint(TetrisCenterpoint* center)
+ { this->center_ = center; }
+
+ PlayerInfo* getPlayer(void) const; //!< Get the player.
+
+ protected:
+ virtual void spawnPlayersIfRequested(); //!< Spawns player.
+
+ void startStone(void); //!< Starts with the first stone.
+ void createStone(void);
+ void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
+
+ PlayerInfo* player_;
+
+ WeakPtr<TetrisCenterpoint> center_; //!< The playing field.
+ std::vector<TetrisStone*> stones_; //!< A list of all stones in play.
+ TetrisStone* activeStone_;
+
+ Timer starttimer_; //!< A timer to delay the start of the game.
+ };
+}
+
+#endif /* _Tetris_H__ */
Added: code/branches/tetris/src/modules/tetris/TetrisCenterpoint.cc
===================================================================
--- code/branches/tetris/src/modules/tetris/TetrisCenterpoint.cc (rev 0)
+++ code/branches/tetris/src/modules/tetris/TetrisCenterpoint.cc 2011-04-18 10:34:22 UTC (rev 8246)
@@ -0,0 +1,101 @@
+/*
+ * 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:
+ * ...
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file TetrisCenterpoint.cc
+ @brief Implementation of the TetrisCenterpoint class.
+*/
+
+#include "TetrisCenterpoint.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "Tetris.h"
+
+namespace orxonox
+{
+ CreateFactory(TetrisCenterpoint);
+
+ /**
+ @brief
+ Constructor. Registers and initializes the object and checks whether the gametype is actually Tetris.
+ */
+ TetrisCenterpoint::TetrisCenterpoint(BaseObject* creator) : StaticEntity(creator)
+ {
+ RegisterObject(TetrisCenterpoint);
+
+ this->width_ = 10;
+ this->height_ = 11;
+ this->stoneSize_ = 10.0f;
+ this->stoneTemplate_ = "";
+ this->stoneSpeed_ = 20.0f;
+
+ this->checkGametype();
+ }
+
+ /**
+ @brief
+ Method to create a TetrisCenterpoint through XML.
+ */
+ void TetrisCenterpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(TetrisCenterpoint, XMLPort, xmlelement, mode);
+
+ XMLPortParam(TetrisCenterpoint, "width", setWidth, getWidth, xmlelement, mode);
+ XMLPortParam(TetrisCenterpoint, "height", setHeight, setWidth, xmlelement, mode);
+ XMLPortParam(TetrisCenterpoint, "stoneSize", setStoneSize, getStoneSize, xmlelement, mode);
+ XMLPortParam(TetrisCenterpoint, "stoneTemplate", setStoneTemplate, getStoneTemplate, xmlelement, mode);
+ XMLPortParam(TetrisCenterpoint, "stoneSpeed", setStoneSpeed, getStoneSpeed, xmlelement, mode);
+ }
+
+ /**
+ @brief
+ Is called when the gametype has changed.
+ */
+ void TetrisCenterpoint::changedGametype()
+ {
+ SUPER(TetrisCenterpoint, changedGametype);
+
+ // Check, whether it's still Tetris.
+ this->checkGametype();
+ }
+
+ /**
+ @brief
+ Checks whether the gametype is Tetris and if it is, sets its centerpoint.
+ */
+ void TetrisCenterpoint::checkGametype()
+ {
+ if (this->getGametype() != NULL && this->getGametype()->isA(Class(Tetris)))
+ {
+ Tetris* tetrisGametype = orxonox_cast<Tetris*>(this->getGametype().get());
+ tetrisGametype->setCenterpoint(this);
+ }
+ }
+}
Added: code/branches/tetris/src/modules/tetris/TetrisCenterpoint.h
===================================================================
--- code/branches/tetris/src/modules/tetris/TetrisCenterpoint.h (rev 0)
+++ code/branches/tetris/src/modules/tetris/TetrisCenterpoint.h 2011-04-18 10:34:22 UTC (rev 8246)
@@ -0,0 +1,144 @@
+/*
+ * 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:
+ * ...
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file TetrisCenterpoint.h
+ @brief Declaration of the TetrisCenterpoint class.
+ @ingroup Tetris
+*/
+
+#ifndef _TetrisCenterpoint_H__
+#define _TetrisCenterpoint_H__
+
+#include "tetris/TetrisPrereqs.h"
+
+#include <string>
+
+#include <util/Math.h>
+
+#include "worldentities/StaticEntity.h"
+
+namespace orxonox
+{
+
+ /**
+ @brief
+
+
+ @author
+
+ @ingroup Tetris
+ */
+ class _TetrisExport TetrisCenterpoint : public StaticEntity
+ {
+ public:
+ TetrisCenterpoint(BaseObject* creator); //!< Constructor. Registers and initializes the object and checks whether the gametype is actually Tetris.
+ virtual ~TetrisCenterpoint() {}
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method to create a TetrisCenterpoint through XML.
+
+ virtual void changedGametype(); //!< Is called when the gametype has changed.
+
+ /**
+ @brief Set the width of the playing field.
+ @param width The width in number of tiles.
+ */
+ void setWidth(unsigned int width)
+ { this->width_ = width; }
+ /**
+ @brief Get the width of the playing field.
+ @return Returns the width in number of tiles.
+ */
+ unsigned int getWidth(void) const
+ { return this->width_; }
+
+ /**
+ @brief Set the height of the playing field.
+ @param height The height in number of tiles.
+ */
+ void setHeight(unsigned int height)
+ { this->height_ = height; }
+ /**
+ @brief Get the height of the playing field.
+ @return Returns the height in number of tiles.
+ */
+ unsigned int getHeight(void) const
+ { return this->height_; }
+
+ /**
+ @brief Set the size of a single stone.
+ @param size The dimensions a stone has in the game world. (A stone is a cube)
+ */
+ void setStoneSize(float size)
+ { this->stoneSize_ = size; }
+ /**
+ @brief Get the size of a single stone.
+ @return Returns the dimensions a stone has in the game world.
+ */
+ float getStoneSize(void) const
+ { return this->stoneSize_; }
+
+ /**
+ @brief Set the template for the stones.
+ @param template The template name to be applied to each stone.
+ */
+ void setStoneTemplate(const std::string& templateName)
+ { this->stoneTemplate_ = templateName; }
+ /**
+ @brief Get the template for the stones.
+ @return Returns the template name to be applied to each stone.
+ */
+ const std::string& getStoneTemplate(void) const
+ { return this->stoneTemplate_; }
+
+ /**
+ @brief Set the speed of the stones.
+ @param speed The speed to be set.
+ */
+ void setStoneSpeed(float speed)
+ { this->stoneSpeed_ = speed; }
+ /**
+ @brief Get the speed of the stones.
+ @return Returns the speed a moving stone has.
+ */
+ float getStoneSpeed(void)
+ { return this->stoneSpeed_; }
+
+ private:
+ void checkGametype(); //!< Checks whether the gametype is Tetris and if it is, sets its centerpoint.
+
+ unsigned int width_;
+ unsigned int height_;
+ float stoneSize_;
+ std::string stoneTemplate_;
+ float stoneSpeed_;
+
+ };
+}
+
+#endif /* _TetrisCenterpoint_H__ */
Added: code/branches/tetris/src/modules/tetris/TetrisPrereqs.h
===================================================================
--- code/branches/tetris/src/modules/tetris/TetrisPrereqs.h (rev 0)
+++ code/branches/tetris/src/modules/tetris/TetrisPrereqs.h 2011-04-18 10:34:22 UTC (rev 8246)
@@ -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:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ at file
+ at brief
+ Shared library macros, enums, constants and forward declarations for the tetris module
+*/
+
+#ifndef _TetrisPrereqs_H__
+#define _TetrisPrereqs_H__
+
+#include "OrxonoxConfig.h"
+#include "OrxonoxPrereqs.h"
+
+//-----------------------------------------------------------------------
+// Shared library settings
+//-----------------------------------------------------------------------
+
+#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(TETRIS_STATIC_BUILD)
+# ifdef TETRIS_SHARED_BUILD
+# define _TetrisExport __declspec(dllexport)
+# else
+# if defined( __MINGW32__ )
+# define _TetrisExport
+# else
+# define _TetrisExport __declspec(dllimport)
+# endif
+# endif
+#elif defined ( ORXONOX_GCC_VISIBILITY )
+# define _TetrisExport __attribute__ ((visibility("default")))
+#else
+# define _TetrisExport
+#endif
+
+//-----------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------
+
+namespace orxonox
+{
+ class Tetris;
+ class TetrisCenterpoint;
+ class TetrisStone;
+}
+
+#endif /* _TetrisPrereqs_H__ */
Added: code/branches/tetris/src/modules/tetris/TetrisStone.cc
===================================================================
--- code/branches/tetris/src/modules/tetris/TetrisStone.cc (rev 0)
+++ code/branches/tetris/src/modules/tetris/TetrisStone.cc 2011-04-18 10:34:22 UTC (rev 8246)
@@ -0,0 +1,92 @@
+/*
+ * 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:
+ * ...
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file TetrisStone.cc
+ @brief Implementation of the TetrisStone class.
+*/
+
+#include "TetrisStone.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+ CreateFactory(TetrisStone);
+
+ /**
+ @brief
+ Constructor. Registers and initializes the object.
+ */
+ TetrisStone::TetrisStone(BaseObject* creator) : ControllableEntity(creator)
+ {
+ RegisterObject(TetrisStone);
+
+ this->size_ = 10.0f;
+ this->delay_ = false;
+ this->delayTimer_.setTimer(0.2f, false, createExecutor(createFunctor(&TetrisStone::enableMovement, this)));
+ }
+
+ /**
+ @brief
+ Overloaded the function to rotate the stone.
+ @param value
+ A vector whose first component is the angle by which to rotate.
+ */
+ void TetrisStone::moveFrontBack(const Vector2& value)
+ {
+
+ }
+
+ /**
+ @brief
+ Overloaded the function to steer the stone right and left
+ @param value
+ A vector whose first component is the direction in which we want to steer the stone.
+ */
+ void TetrisStone::moveRightLeft(const Vector2& value)
+ {
+ if(!this->delay_)
+ {
+ const Vector3& position = this->getPosition();
+ this->setPosition(position.x+value.x/abs(value.x)*this->size_, position.y, position.z);
+ this->delay_ = true;
+ this->delayTimer_.startTimer();
+ }
+ }
+
+ /**
+ @brief
+ Is called when the player changed.
+ */
+ void TetrisStone::changedPlayer()
+ {
+ this->setVelocity(0, 0, 0);
+ }
+}
Added: code/branches/tetris/src/modules/tetris/TetrisStone.h
===================================================================
--- code/branches/tetris/src/modules/tetris/TetrisStone.h (rev 0)
+++ code/branches/tetris/src/modules/tetris/TetrisStone.h 2011-04-18 10:34:22 UTC (rev 8246)
@@ -0,0 +1,87 @@
+/*
+ * 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:
+ * ...
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file TetrisStone.h
+ @brief Declaration of the TetrisStone class.
+ @ingroup Tetris
+*/
+
+#ifndef _TetrisStone_H__
+#define _TetrisStone_H__
+
+#include "tetris/TetrisPrereqs.h"
+
+#include "worldentities/ControllableEntity.h"
+#include "tools/Timer.h"
+
+namespace orxonox
+{
+
+ /**
+ @brief
+
+ @author
+
+ @ingroup Tetris
+ */
+ class _TetrisExport TetrisStone : public ControllableEntity
+ {
+ public:
+ TetrisStone(BaseObject* creator); //!< Constructor. Registers and initializes the object.
+ virtual ~TetrisStone() {}
+
+ virtual void moveFrontBack(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
+ virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
+
+ virtual void changedPlayer(); //!< Is called when the player changed.
+
+ /**
+ @brief Set the size of the stone.
+ @param size The dimensions a stone has in the game world. (A stone is a cube)
+ */
+ void setSize(float size)
+ { this->size_ = size; }
+ /**
+ @brief Get the size of the stone.
+ @return Returns the dimensions a stone has in the game world. (A stone is a cube)
+ */
+ float getSize(void) const
+ { return this->size_; }
+
+ private:
+ void enableMovement(void)
+ { this->delay_ = false; }
+
+ float size_; //!< The dimensions a stone has in the game world.
+ bool delay_;
+ Timer delayTimer_;
+ };
+}
+
+#endif /* _TetrisStone_H__ */
More information about the Orxonox-commit
mailing list