[Orxonox-commit 6383] r11040 - in code/branches/presentationHS15: data/levels src/modules/hover
landauf at orxonox.net
landauf at orxonox.net
Mon Jan 4 17:22:59 CET 2016
Author: landauf
Date: 2016-01-04 17:22:59 +0100 (Mon, 04 Jan 2016)
New Revision: 11040
Modified:
code/branches/presentationHS15/data/levels/Hover.oxw
code/branches/presentationHS15/src/modules/hover/Hover.cc
code/branches/presentationHS15/src/modules/hover/HoverFlag.cc
code/branches/presentationHS15/src/modules/hover/HoverFlag.h
code/branches/presentationHS15/src/modules/hover/HoverOrigin.cc
code/branches/presentationHS15/src/modules/hover/HoverOrigin.h
code/branches/presentationHS15/src/modules/hover/HoverWall.cc
code/branches/presentationHS15/src/modules/hover/HoverWall.h
code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc
code/branches/presentationHS15/src/modules/hover/MazeGenerator.h
Log:
hover: maze size is now fully configurable in xml
Modified: code/branches/presentationHS15/data/levels/Hover.oxw
===================================================================
--- code/branches/presentationHS15/data/levels/Hover.oxw 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/data/levels/Hover.oxw 2016-01-04 16:22:59 UTC (rev 11040)
@@ -17,6 +17,13 @@
include("overlays/HoverHUD.oxo")
?>
+<?lua
+MAZE_NUM_CELLS = 10
+MAZE_CELL_SIZE = 100
+MAZE_CELL_HEIGHT = 30
+MAZE_SIZE = MAZE_NUM_CELLS*MAZE_CELL_SIZE
+?>
+
<Level
plugins = hover
gametype = Hover
@@ -31,56 +38,47 @@
skybox = "Orxonox/Starbox"
gravity = "0, -200, 0"
>
-
-
-
-
- <StaticEntity position="0,0,0" collisionType="static">
- <attached>
- </attached>
- <collisionShapes>
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500,0,0" halfExtents="500, 30, 2" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500,0,1000" halfExtents="500, 30, 2" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0,0,500" halfExtents="2, 30, 500" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="1000,0,500" halfExtents="2, 30, 500" />
-
- </collisionShapes>
- </StaticEntity>
-
- <StaticEntity position="0,0,0" collisionType="static">
- <attached>
- <Model position="500, -16,500" yaw="0" pitch="0" roll="0" scale3D="500, 16, 500" mesh="CubeGround.mesh" />
- </attached>
- <collisionShapes>
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0,50,0" halfExtents="10000, 1, 10000" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0,-10,0" halfExtents="10000, 10, 10000" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500, 0,0" halfExtents="1000, 1000, 1" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500, 0, 1000" halfExtents="1000, 1000, 1" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0, 0, 500" halfExtents="1, 1000, 1000" />
- <BoxCollisionShape yaw="0" pitch="0" roll="0" position="1000, 0, 500" halfExtents="1, 1000, 1000" />
-
-
- </collisionShapes>
- </StaticEntity>
-
-
- <MovableEntity position="0,0,0">
+ <StaticEntity position="0,0,0" collisionType="static">
<attached>
- <HoverOrigin>
+ <HoverOrigin
+ numCells="<?lua print(MAZE_NUM_CELLS)?>"
+ cellSize="<?lua print(MAZE_CELL_SIZE)?>"
+ cellHeight="<?lua print(MAZE_CELL_HEIGHT)?>"
+ />
+ <Model
+ position="<?lua print(MAZE_SIZE/2)?>,-16,<?lua print(MAZE_SIZE/2)?>"
+ scale3D="<?lua print(MAZE_SIZE/2)?>,16,<?lua print(MAZE_SIZE/2)?>"
+ mesh="CubeGround.mesh"
+ />
+ </attached>
+ <collisionShapes>
+ <BoxCollisionShape
+ position="<?lua print(MAZE_SIZE/2)?>,<?lua print(MAZE_CELL_HEIGHT+1)?>,<?lua print(MAZE_SIZE/2)?>"
+ halfExtents="<?lua print(MAZE_SIZE/2)?>,1,<?lua print(MAZE_SIZE/2)?>"
+ />
+ <BoxCollisionShape
+ position="<?lua print(MAZE_SIZE/2)?>,-1,<?lua print(MAZE_SIZE/2)?>"
+ halfExtents="<?lua print(MAZE_SIZE/2)?>,1,<?lua print(MAZE_SIZE/2)?>"
+ />
+ </collisionShapes>
+ </StaticEntity>
- <attached>
-
- </attached>
- </HoverOrigin>
- </attached>
- </MovableEntity>
-
-
-
+ <Light
+ type=directional
+ position="-50,500,-50"
+ direction="0.577, -0.577, 0.577"
+ diffuse="1.0, 0.9, 0.9, 1.0"
+ specular="1.0, 0.9, 0.9, 1.0"
+ />
- <Light type=directional position="-50,500,-50" direction="0.577, -0.577, 0.577" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
- <SpawnPoint team=0 position="50,20,50" lookat="100,20,100" spawnclass=HoverShip pawndesign=spaceshiphover />
+ <SpawnPoint
+ team=0
+ position="50,20,50"
+ lookat="100,20,100"
+ spawnclass=HoverShip
+ pawndesign=spaceshiphover
+ />
</Scene>
</Level>
Modified: code/branches/presentationHS15/src/modules/hover/Hover.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/Hover.cc 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/Hover.cc 2016-01-04 16:22:59 UTC (rev 11040)
@@ -58,33 +58,36 @@
{
SUPER(Hover, tick, dt);
- if(this->firstTick_)
+ if(this->firstTick_ && this->origin_)
{
this->firstTick_ = false;
- MazeGenerator generator;
+ int numCells = this->origin_->getNumCells();
+ int cellSize = this->origin_->getCellSize();
+ int cellHeight = this->origin_->getCellHeight();
+
+ MazeGenerator generator(numCells);
generator.generateMaze();
generator.renderMaze();
- const int NUM_CELLS = generator.getNumCells();
int* levelcode = generator.getLevelcode();
//Outer Walls
- for(int i = 0; i<NUM_CELLS; i++){
- new HoverWall(origin_->getContext(), 0, i+1, 1);
- new HoverWall(origin_->getContext(), NUM_CELLS, i+1, 1);
- new HoverWall(origin_->getContext(), i+1, 0, 2);
- new HoverWall(origin_->getContext(), i+1, NUM_CELLS, 2);
+ for(int i = 0; i<numCells; i++){
+ new HoverWall(origin_->getContext(), 0, i+1, cellSize, cellHeight, 1);
+ new HoverWall(origin_->getContext(), numCells, i+1, cellSize, cellHeight, 1);
+ new HoverWall(origin_->getContext(), i+1, 0, cellSize, cellHeight, 2);
+ new HoverWall(origin_->getContext(), i+1, numCells, cellSize, cellHeight, 2);
}
//Generate inner Walls according to levelcode
- for(int y=0; y<NUM_CELLS; y++){
- for(int x=0; x<NUM_CELLS; x++){
- switch(levelcode[ y * NUM_CELLS + x ]){
- case 1: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
+ for(int y=0; y<numCells; y++){
+ for(int x=0; x<numCells; x++){
+ switch(levelcode[ y * numCells + x ]){
+ case 1: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 1);
break;
- case 3: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
- case 2: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 0);
+ case 3: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 1);
+ case 2: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 0);
default: break;
}
}
@@ -92,7 +95,7 @@
//Generate 5 flags randomly
for ( int i = 0; i < 5; i++ )
- flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%NUM_CELLS, rand()%NUM_CELLS));
+ flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%numCells, rand()%numCells, cellSize));
flags_ = flagVector_.size();
Modified: code/branches/presentationHS15/src/modules/hover/HoverFlag.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverFlag.cc 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/HoverFlag.cc 2016-01-04 16:22:59 UTC (rev 11040)
@@ -63,7 +63,7 @@
@param yCoordinate
Y-Coordinate of the flage, 0-9, origin is bottom left
*/
- HoverFlag::HoverFlag(Context* context, int xCoordinate, int yCoordinate) : StaticEntity(context)
+ HoverFlag::HoverFlag(Context* context, int xCoordinate, int yCoordinate, int cellSize) : StaticEntity(context)
{
RegisterObject(HoverFlag);
enableCollisionCallback();
@@ -73,7 +73,7 @@
model_ = new Model(context);
model_->setMeshSource("ss_flag_eu.mesh");
model_->setScale3D(Vector3(5, 5, 5));
- model_->setPosition(Vector3(xCoordinate*100.0f + 50.0f,10.0f,yCoordinate*100.0f + 50.0f));
+ model_->setPosition(Vector3(xCoordinate*cellSize*1.0f + cellSize/2,10.0f,yCoordinate*cellSize*1.0f + cellSize/2));
this->attach(model_);
@@ -83,7 +83,7 @@
cs_ = new BoxCollisionShape(context);
cs_->setHalfExtents(Vector3(5, 5, 5));
- cs_->setPosition(Vector3(xCoordinate*100.0f + 50.0f,0.0f,yCoordinate*100.0f + 50.0f));
+ cs_->setPosition(Vector3(xCoordinate*cellSize*1.0f + cellSize/2,0.0f,yCoordinate*cellSize*1.0f + cellSize/2));
this->attachCollisionShape(cs_);
this->collided_ = false;
Modified: code/branches/presentationHS15/src/modules/hover/HoverFlag.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverFlag.h 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/HoverFlag.h 2016-01-04 16:22:59 UTC (rev 11040)
@@ -48,7 +48,7 @@
{
public:
HoverFlag(Context* context);
- HoverFlag(Context* context, int xCoordinate, int yCoordinate);
+ HoverFlag(Context* context, int xCoordinate, int yCoordinate, int cellSize);
virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint);
virtual ~HoverFlag();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
Modified: code/branches/presentationHS15/src/modules/hover/HoverOrigin.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverOrigin.cc 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/HoverOrigin.cc 2016-01-04 16:22:59 UTC (rev 11040)
@@ -49,6 +49,10 @@
void HoverOrigin::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(HoverOrigin, XMLPort, xmlelement, mode);
+
+ XMLPortParam(HoverOrigin, "numCells", setNumCells, getNumCells, xmlelement, mode);
+ XMLPortParam(HoverOrigin, "cellSize", setCellSize, getCellSize, xmlelement, mode);
+ XMLPortParam(HoverOrigin, "cellHeight", setCellHeight, getCellHeight, xmlelement, mode);
}
void HoverOrigin::checkGametype()
Modified: code/branches/presentationHS15/src/modules/hover/HoverOrigin.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverOrigin.h 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/HoverOrigin.h 2016-01-04 16:22:59 UTC (rev 11040)
@@ -114,9 +114,27 @@
virtual ~HoverOrigin() {}
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method to create a HoverOrigin through XML.
+ inline void setNumCells(int numCells)
+ { this->numCells_ = numCells; }
+ inline int getNumCells() const
+ { return this->numCells_; }
+
+ inline void setCellSize(int cellSize)
+ { this->cellSize_ = cellSize; }
+ inline int getCellSize() const
+ { return this->cellSize_; }
+
+ inline void setCellHeight(int cellHeight)
+ { this->cellHeight_ = cellHeight; }
+ inline int getCellHeight() const
+ { return this->cellHeight_; }
+
private:
void checkGametype();
+ int numCells_;
+ int cellSize_;
+ int cellHeight_;
};
}
Modified: code/branches/presentationHS15/src/modules/hover/HoverWall.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverWall.cc 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/HoverWall.cc 2016-01-04 16:22:59 UTC (rev 11040)
@@ -64,29 +64,29 @@
@param orientation
Wall on the right side (1) or on top (2) of this square, 0-1
*/
- HoverWall::HoverWall(Context* context, int x, int y, int orientation) : StaticEntity(context)
+ HoverWall::HoverWall(Context* context, int x, int y, int cellSize, int cellHeight, int orientation) : StaticEntity(context)
{
RegisterObject(HoverWall);
int xSize_, zSize_, xPos_, zPos_;
if(orientation == 1){
- xSize_ = 50;
+ xSize_ = cellSize/2;
zSize_ = 2;
- zPos_ = x*100;
- xPos_ = y*100 -50;
+ zPos_ = x*cellSize;
+ xPos_ = y*cellSize-cellSize/2;
}
else{
xSize_ = 2;
- zSize_ = 50;
- zPos_ = x*100-50;
- xPos_ = y*100;
+ zSize_ = cellSize/2;
+ zPos_ = x*cellSize-cellSize/2;
+ xPos_ = y*cellSize;
}
model_ = new Model(context);
model_->setMeshSource("CuboidBody.mesh");
- model_->setScale3D(Vector3(xSize_*1.0f, 30.0f, zSize_*1.0f));
+ model_->setScale3D(Vector3(xSize_*1.0f, cellHeight*1.0f, zSize_*1.0f));
model_->setPosition(Vector3(xPos_*1.0f, 0.0f, zPos_*1.0f));
this->attach(model_);
@@ -96,7 +96,7 @@
this->setCollisionType(Static);
cs_ = new BoxCollisionShape(context);
- cs_->setHalfExtents(Vector3(xSize_*1.0f, 30.0f, zSize_*1.0f));
+ cs_->setHalfExtents(Vector3(xSize_*1.0f, cellHeight*1.0f, zSize_*1.0f));
cs_->setPosition(Vector3(xPos_*1.0f, 0.0f, zPos_*1.0f));
this->attachCollisionShape(cs_);
Modified: code/branches/presentationHS15/src/modules/hover/HoverWall.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/HoverWall.h 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/HoverWall.h 2016-01-04 16:22:59 UTC (rev 11040)
@@ -48,7 +48,7 @@
{
public:
HoverWall(Context* context);
- HoverWall(Context* context, int x, int y, int orientation);
+ HoverWall(Context* context, int x, int y, int cellSize, int cellHeight, int orientation);
virtual ~HoverWall();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
Modified: code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc
===================================================================
--- code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc 2016-01-04 16:22:59 UTC (rev 11040)
@@ -43,18 +43,20 @@
namespace orxonox
{
- MazeGenerator::MazeGenerator()
+ MazeGenerator::MazeGenerator(int numCells)
{
+ this->numCells_ = numCells;
+
//levelcode_ represents the pitch: It's a 10x10 field.
// 1 represents a Wall on the right side of this square
// 2 represents a Wall on the top of this square
// 3 represents 2 and 1 at the same time
// Note: the levelcode_ is generated from the Maze-Generator functions at the beginning of the game
- this->levelcode_ = new int[ NUM_CELLS*NUM_CELLS ];;
- std::fill( levelcode_, levelcode_ + NUM_CELLS*NUM_CELLS, 0 );
+ this->levelcode_ = new int[ numCells_*numCells_ ];;
+ std::fill( levelcode_, levelcode_ + numCells_*numCells_, 0 );
- this->maze_ = new unsigned char[ NUM_CELLS*NUM_CELLS ];
- std::fill( maze_, maze_ + NUM_CELLS*NUM_CELLS, 0 );
+ this->maze_ = new unsigned char[ numCells_*numCells_ ];
+ std::fill( maze_, maze_ + numCells_*numCells_, 0 );
// current traversing position
this->ptX_ = 0;
@@ -90,9 +92,9 @@
int NewX = ptX_ + headingX_[ Dir ];
int NewY = ptY_ + headingY_[ Dir ];
- if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NUM_CELLS || NewY >= NUM_CELLS ) return false;
+ if ( !Dir || NewX < 0 || NewY < 0 || NewX >= numCells_ || NewY >= numCells_ ) return false;
- return !maze_[ NewX + NUM_CELLS * NewY ];
+ return !maze_[ NewX + numCells_ * NewY ];
}
/**
@@ -149,11 +151,11 @@
Print Maze (for Debugging only)
*/
void MazeGenerator::mazeOut(){
- for ( int y = 0; y < NUM_CELLS; y++ )
+ for ( int y = 0; y < numCells_; y++ )
{
- for ( int x = 0; x < NUM_CELLS; x++ )
+ for ( int x = 0; x < numCells_; x++ )
{
- char v = maze_[ y * NUM_CELLS + x ];
+ char v = maze_[ y * numCells_ + x ];
orxout()<<"[";
if ( ( v & eDirection_Up ) ) orxout()<<"U";
else orxout()<<" ";
@@ -175,14 +177,14 @@
Print levelcode_ (for Debugging only)
*/
void MazeGenerator::levelOut(){
- for ( int y = 0; y < NUM_CELLS; y++ )
+ for ( int y = 0; y < numCells_; y++ )
{
- for ( int x = 0; x < NUM_CELLS; x++ )
+ for ( int x = 0; x < numCells_; x++ )
{
orxout()<<"[";
- if ( levelcode_[ y * NUM_CELLS + x ] < 2) orxout()<<"U";
+ if ( levelcode_[ y * numCells_ + x ] < 2) orxout()<<"U";
else orxout()<<" ";
- if ( levelcode_[ y * NUM_CELLS + x ] % 2 == 0) orxout()<<"R";
+ if ( levelcode_[ y * numCells_ + x ] % 2 == 0) orxout()<<"R";
else orxout()<<" ";
orxout()<<" ";
@@ -199,27 +201,31 @@
*/
void MazeGenerator::renderMaze()
{
- for ( int y = 0; y < NUM_CELLS; y++ )
+ for ( int y = 0; y < numCells_; y++ )
{
- for ( int x = 0; x < NUM_CELLS; x++ )
+ for ( int x = 0; x < numCells_; x++ )
{
- char v = maze_[ y * NUM_CELLS + x ];
+ char v = maze_[ y * numCells_ + x ];
- if ( !( v & eDirection_Up ) && y >0) levelcode_[ y * NUM_CELLS + x ] |= 2;
- if ( !( v & eDirection_Right ) && x <9) levelcode_[ y * NUM_CELLS + x ] |= 1;
+ if ( !( v & eDirection_Up ) && y >0) levelcode_[ y * numCells_ + x ] |= 2;
+ if ( !( v & eDirection_Right ) && x <(numCells_-1)) levelcode_[ y * numCells_ + x ] |= 1;
}
}
- for ( int y = 3; y < 7; y++ )
+
+ // leave an empty space in the middle of the maze
+ int lowerBound = numCells_ / 2 - 2;
+ int upperBound = numCells_ / 2 + 2;
+ for ( int y = lowerBound; y < upperBound; y++ )
{
- for ( int x = 3; x < 7; x++ )
+ for ( int x = lowerBound; x < upperBound; x++ )
{
- if(y == 3 && x != 7)
- levelcode_[ y * NUM_CELLS + x ] &= 2;
- else if (x == 7 && y != 3)
- levelcode_[ y * NUM_CELLS + x ] &= 1;
- else if(x != 7)
- levelcode_[ y * NUM_CELLS + x ] = 0;
+ if(y == lowerBound && x != upperBound)
+ levelcode_[ y * numCells_ + x ] &= 2;
+ else if (x == upperBound && y != lowerBound)
+ levelcode_[ y * numCells_ + x ] &= 1;
+ else if(x != upperBound)
+ levelcode_[ y * numCells_ + x ] = 0;
}
}
@@ -228,12 +234,12 @@
// return the current index in maze_
int MazeGenerator::cellIdx()
{
- return ptX_ + NUM_CELLS * ptY_;
+ return ptX_ + numCells_ * ptY_;
}
int MazeGenerator::randomInt()
{
- return (rand() % NUM_CELLS);
+ return (rand() % numCells_);
}
int MazeGenerator::randomInt4()
Modified: code/branches/presentationHS15/src/modules/hover/MazeGenerator.h
===================================================================
--- code/branches/presentationHS15/src/modules/hover/MazeGenerator.h 2016-01-04 13:22:14 UTC (rev 11039)
+++ code/branches/presentationHS15/src/modules/hover/MazeGenerator.h 2016-01-04 16:22:59 UTC (rev 11040)
@@ -50,7 +50,7 @@
class _HoverExport MazeGenerator
{
public:
- MazeGenerator();
+ MazeGenerator(int numCells);
void generateMaze();
void renderMaze();
@@ -59,8 +59,6 @@
int* getLevelcode() const
{ return this->levelcode_; }
- int getNumCells() const
- { return NUM_CELLS; }
private:
bool isDirValid( eDirection Dir );
@@ -70,7 +68,7 @@
int randomInt();
int randomInt4();
- static const int NUM_CELLS = 10;
+ int numCells_;
int* levelcode_;
unsigned char* maze_;
More information about the Orxonox-commit
mailing list