Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11040


Ignore:
Timestamp:
Jan 4, 2016, 5:22:59 PM (8 years ago)
Author:
landauf
Message:

hover: maze size is now fully configurable in xml

Location:
code/branches/presentationHS15
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS15/data/levels/Hover.oxw

    r11026 r11040  
    1818?>
    1919
     20<?lua
     21MAZE_NUM_CELLS = 10
     22MAZE_CELL_SIZE = 100
     23MAZE_CELL_HEIGHT = 30
     24MAZE_SIZE = MAZE_NUM_CELLS*MAZE_CELL_SIZE
     25?>
     26
    2027<Level
    2128plugins = hover
     
    3239    gravity      = "0, -200, 0"
    3340  >
    34  
    3541
     42    <StaticEntity position="0,0,0" collisionType="static">
     43      <attached>
     44        <HoverOrigin
     45          numCells="<?lua print(MAZE_NUM_CELLS)?>"
     46          cellSize="<?lua print(MAZE_CELL_SIZE)?>"
     47          cellHeight="<?lua print(MAZE_CELL_HEIGHT)?>"
     48        />
     49        <Model
     50          position="<?lua print(MAZE_SIZE/2)?>,-16,<?lua print(MAZE_SIZE/2)?>"
     51          scale3D="<?lua print(MAZE_SIZE/2)?>,16,<?lua print(MAZE_SIZE/2)?>"
     52          mesh="CubeGround.mesh"
     53        />
     54      </attached>
     55      <collisionShapes>
     56        <BoxCollisionShape
     57          position="<?lua print(MAZE_SIZE/2)?>,<?lua print(MAZE_CELL_HEIGHT+1)?>,<?lua print(MAZE_SIZE/2)?>"
     58          halfExtents="<?lua print(MAZE_SIZE/2)?>,1,<?lua print(MAZE_SIZE/2)?>"
     59        />
     60        <BoxCollisionShape
     61          position="<?lua print(MAZE_SIZE/2)?>,-1,<?lua print(MAZE_SIZE/2)?>"
     62          halfExtents="<?lua print(MAZE_SIZE/2)?>,1,<?lua print(MAZE_SIZE/2)?>"
     63        />
     64      </collisionShapes>
     65    </StaticEntity>
    3666
    37  
    38 
    39   <StaticEntity position="0,0,0" collisionType="static">
    40     <attached>
    41     </attached>
    42     <collisionShapes>
    43       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500,0,0" halfExtents="500, 30, 2" />
    44       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500,0,1000" halfExtents="500, 30, 2" />
    45       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0,0,500" halfExtents="2, 30, 500" />
    46       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="1000,0,500" halfExtents="2, 30, 500" />
    47 
    48     </collisionShapes>
    49   </StaticEntity>
    50 
    51   <StaticEntity position="0,0,0" collisionType="static">
    52     <attached>
    53       <Model position="500, -16,500" yaw="0" pitch="0" roll="0" scale3D="500, 16, 500" mesh="CubeGround.mesh" />     
    54     </attached>
    55     <collisionShapes>
    56       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0,50,0" halfExtents="10000, 1, 10000" />
    57       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0,-10,0" halfExtents="10000, 10, 10000" />
    58       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500, 0,0" halfExtents="1000, 1000, 1" />
    59       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="500, 0, 1000" halfExtents="1000, 1000, 1" />   
    60       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="0, 0, 500" halfExtents="1, 1000, 1000" />
    61       <BoxCollisionShape yaw="0" pitch="0" roll="0" position="1000, 0, 500" halfExtents="1, 1000, 1000" />           
    62 
    63 
    64     </collisionShapes>
    65   </StaticEntity>
    66 
    67 
    68     <MovableEntity position="0,0,0">
    69       <attached>
    70         <HoverOrigin>
    71 
    72           <attached>
    73 
    74           </attached>
    75         </HoverOrigin>
    76       </attached>
    77     </MovableEntity>
    78 
    79 
    80 
     67    <Light
     68      type=directional
     69      position="-50,500,-50"
     70      direction="0.577, -0.577, 0.577"
     71      diffuse="1.0, 0.9, 0.9, 1.0"
     72      specular="1.0, 0.9, 0.9, 1.0"
     73    />
    8174   
    82     <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"/>
    83     <SpawnPoint team=0 position="50,20,50" lookat="100,20,100" spawnclass=HoverShip pawndesign=spaceshiphover />
     75    <SpawnPoint
     76      team=0
     77      position="50,20,50"
     78      lookat="100,20,100"
     79      spawnclass=HoverShip
     80      pawndesign=spaceshiphover
     81    />
    8482   
    8583  </Scene>
  • code/branches/presentationHS15/src/modules/hover/Hover.cc

    r11036 r11040  
    5959        SUPER(Hover, tick, dt);
    6060
    61         if(this->firstTick_)
     61        if(this->firstTick_ && this->origin_)
    6262        {
    6363            this->firstTick_ = false;
    6464
    65             MazeGenerator generator;
     65            int numCells = this->origin_->getNumCells();
     66            int cellSize = this->origin_->getCellSize();
     67            int cellHeight = this->origin_->getCellHeight();
     68
     69            MazeGenerator generator(numCells);
    6670            generator.generateMaze();
    6771            generator.renderMaze();
    6872
    69             const int NUM_CELLS = generator.getNumCells();
    7073            int* levelcode = generator.getLevelcode();
    7174
    7275            //Outer Walls
    73             for(int i = 0; i<NUM_CELLS; i++){
    74                 new HoverWall(origin_->getContext(), 0, i+1, 1);
    75                 new HoverWall(origin_->getContext(), NUM_CELLS, i+1, 1);
    76                 new HoverWall(origin_->getContext(), i+1, 0, 2);
    77                 new HoverWall(origin_->getContext(), i+1, NUM_CELLS, 2);
     76            for(int i = 0; i<numCells; i++){
     77                new HoverWall(origin_->getContext(), 0,        i+1,      cellSize, cellHeight, 1);
     78                new HoverWall(origin_->getContext(), numCells, i+1,      cellSize, cellHeight, 1);
     79                new HoverWall(origin_->getContext(), i+1,      0,        cellSize, cellHeight, 2);
     80                new HoverWall(origin_->getContext(), i+1,      numCells, cellSize, cellHeight, 2);
    7881            }
    7982
    8083            //Generate inner Walls according to levelcode
    81             for(int y=0; y<NUM_CELLS; y++){
    82                 for(int x=0; x<NUM_CELLS; x++){
    83                     switch(levelcode[ y * NUM_CELLS + x ]){
    84                         case 1: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
     84            for(int y=0; y<numCells; y++){
     85                for(int x=0; x<numCells; x++){
     86                    switch(levelcode[ y * numCells + x ]){
     87                        case 1: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 1);
    8588                                break;
    86                         case 3: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
    87                         case 2: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 0);
     89                        case 3: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 1);
     90                        case 2: new HoverWall(origin_->getContext(), x+1, numCells-y, cellSize, cellHeight, 0);
    8891                        default: break;
    8992                    }
     
    9396            //Generate 5 flags randomly
    9497            for ( int i = 0; i < 5; i++ )
    95                 flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%NUM_CELLS, rand()%NUM_CELLS));
     98                flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%numCells, rand()%numCells, cellSize));
    9699
    97100            flags_ = flagVector_.size();
  • code/branches/presentationHS15/src/modules/hover/HoverFlag.cc

    r11030 r11040  
    6464        Y-Coordinate of the flage, 0-9, origin is bottom left
    6565    */
    66     HoverFlag::HoverFlag(Context* context, int xCoordinate, int yCoordinate) : StaticEntity(context)
     66    HoverFlag::HoverFlag(Context* context, int xCoordinate, int yCoordinate, int cellSize) : StaticEntity(context)
    6767    {
    6868        RegisterObject(HoverFlag);
     
    7474        model_->setMeshSource("ss_flag_eu.mesh");
    7575        model_->setScale3D(Vector3(5, 5, 5));
    76         model_->setPosition(Vector3(xCoordinate*100.0f + 50.0f,10.0f,yCoordinate*100.0f + 50.0f));
     76        model_->setPosition(Vector3(xCoordinate*cellSize*1.0f + cellSize/2,10.0f,yCoordinate*cellSize*1.0f + cellSize/2));
    7777
    7878        this->attach(model_);
     
    8484        cs_ = new BoxCollisionShape(context);
    8585        cs_->setHalfExtents(Vector3(5, 5, 5));
    86         cs_->setPosition(Vector3(xCoordinate*100.0f + 50.0f,0.0f,yCoordinate*100.0f + 50.0f));
     86        cs_->setPosition(Vector3(xCoordinate*cellSize*1.0f + cellSize/2,0.0f,yCoordinate*cellSize*1.0f + cellSize/2));
    8787
    8888        this->attachCollisionShape(cs_);
  • code/branches/presentationHS15/src/modules/hover/HoverFlag.h

    r11029 r11040  
    4949        public:
    5050            HoverFlag(Context* context);
    51             HoverFlag(Context* context, int xCoordinate, int yCoordinate);
     51            HoverFlag(Context* context, int xCoordinate, int yCoordinate, int cellSize);
    5252            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint);           
    5353            virtual ~HoverFlag();
  • code/branches/presentationHS15/src/modules/hover/HoverOrigin.cc

    r11026 r11040  
    5050    {
    5151        SUPER(HoverOrigin, XMLPort, xmlelement, mode);
     52
     53        XMLPortParam(HoverOrigin, "numCells", setNumCells, getNumCells, xmlelement, mode);
     54        XMLPortParam(HoverOrigin, "cellSize", setCellSize, getCellSize, xmlelement, mode);
     55        XMLPortParam(HoverOrigin, "cellHeight", setCellHeight, getCellHeight, xmlelement, mode);
    5256    }
    5357
  • code/branches/presentationHS15/src/modules/hover/HoverOrigin.h

    r11026 r11040  
    115115            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method to create a HoverOrigin through XML.
    116116           
     117            inline void setNumCells(int numCells)
     118                { this->numCells_ = numCells; }
     119            inline int getNumCells() const
     120                { return this->numCells_; }
     121
     122            inline void setCellSize(int cellSize)
     123                { this->cellSize_ = cellSize; }
     124            inline int getCellSize() const
     125                { return this->cellSize_; }
     126
     127            inline void setCellHeight(int cellHeight)
     128                { this->cellHeight_ = cellHeight; }
     129            inline int getCellHeight() const
     130                { return this->cellHeight_; }
     131
    117132        private:
    118133            void checkGametype();
    119134       
     135            int numCells_;
     136            int cellSize_;
     137            int cellHeight_;
    120138    };
    121139}
  • code/branches/presentationHS15/src/modules/hover/HoverWall.cc

    r11030 r11040  
    6565            Wall on the right side (1) or on top (2) of this square, 0-1       
    6666    */
    67     HoverWall::HoverWall(Context* context, int x, int y, int orientation) : StaticEntity(context)
     67    HoverWall::HoverWall(Context* context, int x, int y, int cellSize, int cellHeight, int orientation) : StaticEntity(context)
    6868    {
    6969        RegisterObject(HoverWall);
     
    7272
    7373        if(orientation == 1){
    74             xSize_ = 50;
     74            xSize_ = cellSize/2;
    7575            zSize_ = 2;
    76             zPos_ = x*100;
    77             xPos_ = y*100 -50;
     76            zPos_ = x*cellSize;
     77            xPos_ = y*cellSize-cellSize/2;
    7878        }
    7979        else{
    8080            xSize_ = 2;
    81             zSize_ = 50;
    82             zPos_ = x*100-50;
    83             xPos_ = y*100;
     81            zSize_ = cellSize/2;
     82            zPos_ = x*cellSize-cellSize/2;
     83            xPos_ = y*cellSize;
    8484        }
    8585
     
    8787        model_ = new Model(context);
    8888        model_->setMeshSource("CuboidBody.mesh");
    89         model_->setScale3D(Vector3(xSize_*1.0f, 30.0f, zSize_*1.0f));
     89        model_->setScale3D(Vector3(xSize_*1.0f, cellHeight*1.0f, zSize_*1.0f));
    9090        model_->setPosition(Vector3(xPos_*1.0f, 0.0f, zPos_*1.0f));
    9191
     
    9797
    9898        cs_ = new BoxCollisionShape(context);
    99         cs_->setHalfExtents(Vector3(xSize_*1.0f, 30.0f, zSize_*1.0f));
     99        cs_->setHalfExtents(Vector3(xSize_*1.0f, cellHeight*1.0f, zSize_*1.0f));
    100100        cs_->setPosition(Vector3(xPos_*1.0f, 0.0f, zPos_*1.0f));
    101101
  • code/branches/presentationHS15/src/modules/hover/HoverWall.h

    r11029 r11040  
    4949        public:
    5050            HoverWall(Context* context);           
    51             HoverWall(Context* context, int x, int y, int orientation);
     51            HoverWall(Context* context, int x, int y, int cellSize, int cellHeight, int orientation);
    5252            virtual ~HoverWall();
    5353            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
  • code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc

    r11036 r11040  
    4444namespace orxonox
    4545{
    46     MazeGenerator::MazeGenerator()
    47     {
     46    MazeGenerator::MazeGenerator(int numCells)
     47    {
     48        this->numCells_ = numCells;
     49
    4850        //levelcode_ represents the pitch: It's a 10x10 field.
    4951        // 1 represents a Wall on the right side of this square
     
    5153        // 3 represents 2 and 1 at the same time
    5254        // Note: the levelcode_ is generated from the Maze-Generator functions at the beginning of the game
    53         this->levelcode_ = new int[ NUM_CELLS*NUM_CELLS ];;
    54         std::fill( levelcode_, levelcode_ + NUM_CELLS*NUM_CELLS, 0 );
    55 
    56         this->maze_ = new unsigned char[ NUM_CELLS*NUM_CELLS ];
    57         std::fill( maze_, maze_ + NUM_CELLS*NUM_CELLS, 0 );
     55        this->levelcode_ = new int[ numCells_*numCells_ ];;
     56        std::fill( levelcode_, levelcode_ + numCells_*numCells_, 0 );
     57
     58        this->maze_ = new unsigned char[ numCells_*numCells_ ];
     59        std::fill( maze_, maze_ + numCells_*numCells_, 0 );
    5860
    5961        // current traversing position
     
    9193        int NewY = ptY_ + headingY_[ Dir ];
    9294
    93         if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NUM_CELLS || NewY >= NUM_CELLS ) return false;
    94 
    95         return !maze_[ NewX + NUM_CELLS * NewY ];
     95        if ( !Dir || NewX < 0 || NewY < 0 || NewX >= numCells_ || NewY >= numCells_ ) return false;
     96
     97        return !maze_[ NewX + numCells_ * NewY ];
    9698    }
    9799
     
    150152    */
    151153    void MazeGenerator::mazeOut(){
    152         for ( int y = 0; y < NUM_CELLS; y++ )
    153         {
    154             for ( int x = 0; x < NUM_CELLS; x++ )
    155             {
    156                 char v = maze_[ y * NUM_CELLS + x ];
     154        for ( int y = 0; y < numCells_; y++ )
     155        {
     156            for ( int x = 0; x < numCells_; x++ )
     157            {
     158                char v = maze_[ y * numCells_ + x ];
    157159                orxout()<<"[";
    158160                if ( ( v & eDirection_Up    ) ) orxout()<<"U";
     
    176178    */
    177179    void MazeGenerator::levelOut(){
    178         for ( int y = 0; y < NUM_CELLS; y++ )
    179         {
    180             for ( int x = 0; x < NUM_CELLS; x++ )
     180        for ( int y = 0; y < numCells_; y++ )
     181        {
     182            for ( int x = 0; x < numCells_; x++ )
    181183            {
    182184                orxout()<<"[";
    183                 if ( levelcode_[ y * NUM_CELLS + x ] < 2) orxout()<<"U";
    184                 else orxout()<<" ";
    185                 if ( levelcode_[ y * NUM_CELLS + x ] % 2 == 0) orxout()<<"R";
     185                if ( levelcode_[ y * numCells_ + x ] < 2) orxout()<<"U";
     186                else orxout()<<" ";
     187                if ( levelcode_[ y * numCells_ + x ] % 2 == 0) orxout()<<"R";
    186188                else orxout()<<" ";
    187189
     
    200202    void MazeGenerator::renderMaze()
    201203    {
    202         for ( int y = 0; y < NUM_CELLS; y++ )
    203         {
    204             for ( int x = 0; x < NUM_CELLS; x++ )
    205             {
    206                 char v = maze_[ y * NUM_CELLS + x ];
    207 
    208                 if ( !( v & eDirection_Up    ) && y >0) levelcode_[ y * NUM_CELLS + x ] |= 2;
    209                 if ( !( v & eDirection_Right ) && x <9) levelcode_[ y * NUM_CELLS + x ] |= 1;
    210             }
    211         }
    212         for ( int y = 3; y < 7; y++ )
    213         {
    214             for ( int x = 3; x < 7; x++ )
    215             {
    216 
    217                 if(y == 3 && x != 7)
    218                     levelcode_[ y * NUM_CELLS + x ] &= 2;
    219                 else if (x == 7 && y != 3)
    220                     levelcode_[ y * NUM_CELLS + x ] &= 1;
    221                 else if(x != 7)
    222                     levelcode_[ y * NUM_CELLS + x ] = 0;
     204        for ( int y = 0; y < numCells_; y++ )
     205        {
     206            for ( int x = 0; x < numCells_; x++ )
     207            {
     208                char v = maze_[ y * numCells_ + x ];
     209
     210                if ( !( v & eDirection_Up    ) && y >0) levelcode_[ y * numCells_ + x ] |= 2;
     211                if ( !( v & eDirection_Right ) && x <(numCells_-1)) levelcode_[ y * numCells_ + x ] |= 1;
     212            }
     213        }
     214
     215        // leave an empty space in the middle of the maze
     216        int lowerBound = numCells_ / 2 - 2;
     217        int upperBound = numCells_ / 2 + 2;
     218        for ( int y = lowerBound; y < upperBound; y++ )
     219        {
     220            for ( int x = lowerBound; x < upperBound; x++ )
     221            {
     222
     223                if(y == lowerBound && x != upperBound)
     224                    levelcode_[ y * numCells_ + x ] &= 2;
     225                else if (x == upperBound && y != lowerBound)
     226                    levelcode_[ y * numCells_ + x ] &= 1;
     227                else if(x != upperBound)
     228                    levelcode_[ y * numCells_ + x ] = 0;
    223229            }
    224230        }
     
    229235    int MazeGenerator::cellIdx()
    230236    {
    231         return ptX_ + NUM_CELLS * ptY_;
     237        return ptX_ + numCells_ * ptY_;
    232238    }
    233239
    234240    int MazeGenerator::randomInt()
    235241    {
    236         return (rand() % NUM_CELLS);
     242        return (rand() % numCells_);
    237243    }
    238244
  • code/branches/presentationHS15/src/modules/hover/MazeGenerator.h

    r11036 r11040  
    5151    {
    5252        public:
    53             MazeGenerator();
     53            MazeGenerator(int numCells);
    5454
    5555            void generateMaze();
     
    6060            int* getLevelcode() const
    6161                { return this->levelcode_; }
    62             int getNumCells() const
    63                 { return NUM_CELLS; }
    6462
    6563        private:
     
    7169            int randomInt4();
    7270
    73             static const int NUM_CELLS = 10;
     71            int numCells_;
    7472            int* levelcode_;
    7573            unsigned char* maze_;
Note: See TracChangeset for help on using the changeset viewer.