Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9286


Ignore:
Timestamp:
Jun 10, 2012, 5:13:00 PM (12 years ago)
Author:
jo
Message:

Merged pCuts branch.

Location:
code/branches/presentation2012merge
Files:
16 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2012merge

  • code/branches/presentation2012merge/data/levels/presentationHS11.oxw

    r9272 r9286  
     1<!-- TODO: add in level documentation !! -->
     2
     3
    14<LevelInfo
    25 name = "Presentation HS 2011"
     
    7982        </events>
    8083    </SimpleNotification>
     84
     85
    8186
    8287
     
    131136<?lua end ?>
    132137
    133 
    134 
    135 
    136 
    137 
     138<!-- @Triggers: "hintX" <->  delayed LetsGo -->
     139    <EventTrigger name="hint1" activations="1" stayactive="true" delay=4.2>
     140      <events>
     141        <trigger>
     142          <EventListener event="LetsGo" />
     143        </trigger>
     144      </events>
     145    </EventTrigger>
     146    <EventTrigger name="hint2" activations="1" stayactive="true" delay=8.4>
     147      <events>
     148        <trigger>
     149          <EventListener event="LetsGo" />
     150        </trigger>
     151      </events>
     152    </EventTrigger>
     153    <EventTrigger name="hint3" activations="1" stayactive="true" delay=12.6>
     154      <events>
     155        <trigger>
     156          <EventListener event="LetsGo" />
     157        </trigger>
     158      </events>
     159    </EventTrigger>
     160    <EventTrigger name="hint4" activations="1" stayactive="true" delay=16.8>
     161      <events>
     162        <trigger>
     163          <EventListener event="LetsGo" />
     164        </trigger>
     165      </events>
     166    </EventTrigger>
     167    <EventTrigger name="hint5" activations="1" stayactive="true" delay=21>
     168      <events>
     169        <trigger>
     170          <EventListener event="LetsGo" />
     171        </trigger>
     172      </events>
     173    </EventTrigger>
     174    <EventTrigger name="hint6" activations="1" stayactive="true" delay=25.2>
     175      <events>
     176        <trigger>
     177          <EventListener event="LetsGo" />
     178        </trigger>
     179      </events>
     180    </EventTrigger>
     181
     182
     183
     184    <SimpleNotification message="Make bots follow you: Press (1)"  broadcast="true">
     185        <events>
     186            <trigger>
     187                <EventListener event=hint1 />
     188            </trigger>
     189        </events>
     190    </SimpleNotification>
     191
     192    <SimpleNotification message="Toggle group behaviour: Press (1)"  broadcast="true">
     193        <events>
     194            <trigger>
     195                <EventListener event=hint2 />
     196            </trigger>
     197        </events>
     198    </SimpleNotification>
     199
     200    <SimpleNotification message="Tell the bots to defend you: Press (2)"  broadcast="true">
     201        <events>
     202            <trigger>
     203                <EventListener event=hint3 />
     204            </trigger>
     205        </events>
     206    </SimpleNotification>
     207
     208    <SimpleNotification message="Make them attack opponents: Press (2)"  broadcast="true">
     209        <events>
     210            <trigger>
     211                <EventListener event=hint4 />
     212            </trigger>
     213        </events>
     214    </SimpleNotification>
     215
     216    <SimpleNotification message="Let the bots behave normal: Press (2) "  broadcast="true">
     217        <events>
     218            <trigger>
     219                <EventListener event=hint5 />
     220            </trigger>
     221        </events>
     222    </SimpleNotification>
     223
     224    <SimpleNotification message="Have a look at the console to verify this."  broadcast="true">
     225        <events>
     226            <trigger>
     227                <EventListener event=hint6 />
     228            </trigger>
     229        </events>
     230    </SimpleNotification>
    138231
    139232<!-- Generate asteroid field and asteroid belt -->
  • code/branches/presentation2012merge/data/levels/tetris.oxw

    r9016 r9286  
    99  include("HUDTemplates3.oxo")
    1010  include("stats.oxo")
     11  include("tetrisHUD.oxo")
    1112  include("templates/lodInformation.oxt")
    1213?>
     
    1617    <camerapositions>
    1718      <CameraPosition position="55,75,200" absolute=true />
    18       <CameraPosition position="0,50,160" drag=true mouselook=true />
    19       <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true />
    2019    </camerapositions>
    2120  </TetrisStone>
     
    2524  <TetrisStone camerapositiontemplate=tetrisstonecameras>
    2625    <attached>
    27       <Model position="0,0,0" mesh="crate.mesh" scale=1 />
     26      <Model position="0,0,0" mesh="crate.mesh" scale=0.9 />
    2827    </attached>
    2928  </TetrisStone>
    3029</Template>
     30
     31
     32
     33<Template name=tetrisbrickcameras defaults=0>
     34  <TetrisBrick>
     35    <camerapositions>
     36      <CameraPosition position="55,75,200" absolute=true />
     37      <CameraPosition position="0,50,160" drag=true mouselook=true />
     38      <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true />
     39    </camerapositions>
     40  </TetrisBrick>
     41</Template>
     42
     43<Template name=tetrisbrick>
     44  <TetrisBrick camerapositiontemplate=tetrisbrickcameras>
     45  </TetrisBrick>
     46</Template>
     47
    3148
    3249<Level
     
    4259   skybox       = "Orxonox/skypanoramagen1"
    4360  >
     61<!--luke_grey_-_hypermode.ogg allgorythm-lift_up.ogg Fight1.ogg -->
     62    <WorldAmbientSound
     63      source="Ganymede.ogg"
     64      looping="true"
     65      playOnLoad="true"
     66    />
     67
    4468    <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" />
     69
    4570
    4671    <?lua
     
    5075    <?lua end ?>
    5176
    52     <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone stoneSpeed=10 position="-55,-75,0">
     77    <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone brickTemplate=tetrisbrick stoneSpeed=10 position="-55,-75,0">
    5378        <attached>
    5479            <Model position="55,-1,0" mesh="cube.mesh" scale3D="57,1,11" />
     
    5681            <Model position="111,76,0" mesh="cube.mesh" scale3D="1,76,1" />
    5782        </attached>
     83        <!--collisionShapes>
     84            <BoxCollisionShape position="55,-1,0"  halfExtents="57,1,11" />
     85            <BoxCollisionShape position="-1,76,0"  halfExtents="1,76,1" />
     86            <BoxCollisionShape position="111,76,0" halfExtents="1,76,1" />
     87        </collisionShapes-->
    5888    </TetrisCenterpoint>
     89
     90<!-- ------------ insert eye candy here  ---------------- -->
     91
     92<!-- asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) -->
     93<!-- DONT DARE TO TURN THE FOG ON, whithout finding a better belt position -->
     94    <?lua
     95        dofile("includes/asteroidField.lua")
     96        asteroidBelt(10000, 0, 0, -40, -90, 70, 100, 200, 24000, 20000, 500, 0)
     97
     98    ?>
     99
    59100
    60101  </Scene>
  • code/branches/presentation2012merge/src/modules/tetris/CMakeLists.txt

    r8706 r9286  
    33  TetrisCenterpoint.cc
    44  TetrisStone.cc
     5  TetrisBrick.cc
     6  TetrisScore.cc
    57)
    68
     
    1012  LINK_LIBRARIES
    1113    orxonox
     14    overlays
    1215  SOURCE_FILES ${TETRIS_SRC_FILES}
    1316)
  • code/branches/presentation2012merge/src/modules/tetris/Tetris.cc

    r8858 r9286  
    2323 *      ...
    2424 *   Co-authors:
    25  *      ...
    26  *
     25 *      Johannes Ritz
     26 *
     27 *
     28 *BUG c) destroying the old stones causes segfault -> WeakPointer as solution ?
     29 *BUG d) wrong collision detection: sometimes stones "bounce off"
     30 *
     31 *
     32 *TASK c) end the game in a nicer way
     33 *TASK d) save the highscore
     34 *TASK e) eye candy
    2735 */
    2836
     
    4250#include "TetrisCenterpoint.h"
    4351#include "TetrisStone.h"
     52#include "TetrisBrick.h"
    4453#include "infos/PlayerInfo.h"
    4554
     
    5261    @brief
    5362        Constructor. Registers and initializes the object.
     63    @ingroup Tetris
    5464    */
    5565    Tetris::Tetris(BaseObject* creator) : Deathmatch(creator)
     
    5767        RegisterObject(Tetris);
    5868
    59         this->activeStone_ = NULL;
     69        this->activeBrick_ = NULL;
    6070
    6171        // Pre-set the timer, but don't start it yet.
    62         this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startStone, this)));
     72        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startBrick, this)));
    6373        this->starttimer_.stopTimer();
    6474
    6575        this->player_ = NULL;
     76        this->endGameCriteria_ = 0.0f;
     77        this->setHUDTemplate("TetrisHUD");
     78        this->futureBrick_ = NULL;
    6679    }
    6780
     
    8295    void Tetris::cleanup()
    8396    {
     97        /*for(int i = 0;i < this->stones_.size(); i++) //TODO: Why isn't there any code like this
     98        {                                              // compensating the 'new' statement?
     99            delete this->stones_[i];
     100        }//*/
    84101
    85102    }
     
    89106        SUPER(Tetris, tick, dt);
    90107
    91         if(this->activeStone_ != NULL)
    92         {
    93             if(!this->isValidStonePosition(this->activeStone_, this->activeStone_->getPosition()))
    94             {
    95                 this->activeStone_->setVelocity(Vector3::ZERO);
    96                 this->createStone();
    97                 this->startStone();
     108        if((this->activeBrick_ != NULL)&&(!this->hasEnded()))
     109        {
     110                this->endGameCriteria_ += dt;
     111            if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition()))
     112            {
     113                this->activeBrick_->setVelocity(Vector3::ZERO);
     114                this->activeBrick_->releaseStones(this->center_);
     115                //delete this->activeBrick_; //releasing the memory
     116                this->findFullRows();
     117                if(this->endGameCriteria_ < 0.1f) //end game if two bricks are created within a 0.1s interval.
     118                    this->end();
     119                this->createBrick();
     120                this->startBrick();
     121                this->endGameCriteria_ = 0.0f;
    98122            }
    99123        }
     
    123147    }
    124148
     149    /**
     150    @brief
     151        Check for each stone in a brick if it is moved the right way.
     152    */
     153    bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation = false)
     154    {
     155        assert(brick);
     156
     157        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
     158        {
     159            TetrisStone* stone = brick->getStone(i);
     160            Vector3 stonePosition; //the current stone's offset to position
     161            if(isRotation)
     162                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
     163            else
     164                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     165
     166            if(! this->isValidMove(stone, position + stonePosition ))
     167            {
     168                return false;
     169            }
     170
     171            //catch illegal rotation (such that collisions with ground are not permitted)
     172            if(isRotation)
     173            {
     174                if((position + stonePosition).y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
     175                {
     176                    return false;
     177                }
     178            }
     179        }
     180        return true;
     181
     182    }
     183
     184
     185
    125186    bool Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position)
    126187    {
     
    130191        for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
    131192        {
    132             if(stone == *it)
     193            if(this->activeBrick_->contains(*it))//skip the moving brick' stones
    133194                continue;
    134 
     195            //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
    135196            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
    136 
     197            //!< Saves the position of the currentStone
     198
     199            //filter out cases where the falling stone is already below a steady stone
     200            if(position.y < currentStonePosition.y - this->center_->getStoneSize()/2.0f)
     201                continue;
    137202            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    138203            {
    139                 this->activeStone_->setPosition(Vector3(this->activeStone_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeStone_->getPosition().z));
     204                int y_offset = static_cast<int>((this->activeBrick_->getPosition().y-currentStonePosition.y+10)/10)*10 + currentStonePosition.y;
     205                if(y_offset < 0) //filter out extreme cases (very rare bug)
     206                        y_offset = 0;
     207                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, y_offset, this->activeBrick_->getPosition().z));
    140208                return false;
    141209            }// This case applies if the stones overlap partially vertically
     
    145213        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    146214        {
    147             stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
     215                int yOffset = stone->getPosition().y + this->center_->getStoneSize()/2.0f;//calculate offset
     216                if(yOffset < 0) //catch brake-throughs
     217                    yOffset = 0;
     218                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, yOffset, this->activeBrick_->getPosition().z));
    148219            return false;
    149220        }
     
    151222        return true;
    152223    }
     224    /**
     225     * @brief This function determines wether a brick touches another brick or the ground.
     226     *
     227     */
     228    bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position)
     229    {
     230        assert(brick);
     231
     232        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
     233        {
     234            TetrisStone* stone = brick->getStone(i);
     235            Vector3 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     236            if(! this->isValidStonePosition(stone, position + stonePosition) )
     237                return false;
     238        }
     239        return true;
     240    }
     241
     242    /**
     243    @brief
     244        A Vector3 is rolled 90 * degrees * amount (anticlockwise rotation)
     245    */
     246    Vector3 Tetris::rotateVector(Vector3 position, unsigned int amount)
     247    {
     248        int temp = 0;
     249        for(unsigned int i = 0; i < amount; i++)
     250        {
     251            temp = position.x;
     252            position.x = -position.y;
     253            position.y = temp;
     254        }
     255        return position;
     256    }
    153257
    154258    /**
     
    160264        if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.
    161265        {
    162             // Create the first stone.
    163             this->createStone();
     266            // Create the futureBrick_
     267            this->createBrick();
     268            // Create the first brick.
     269            this->createBrick();
    164270        }
    165271        else // If no centerpoint was specified, an error is thrown and the level is exited.
     
    190296    void Tetris::end()
    191297    {
     298        this->activeBrick_->setVelocity(Vector3::ZERO);
     299        if(this->activeBrick_ != NULL)
     300        {
     301            this->player_->stopControl();
     302        }
     303
    192304        this->cleanup();
    193305
     
    225337    }
    226338
    227     /**
    228     @brief
    229         Starts the first stone.
    230     */
    231     void Tetris::startStone(void)
     339
     340
     341    void Tetris::startBrick(void)
    232342    {
    233343        if(this->player_ == NULL)
     
    235345
    236346        unsigned int cameraIndex = 0;
    237         if(this->activeStone_ != NULL)
     347        if(this->activeBrick_ != NULL)
    238348        {
    239349            // Get camera settings
    240             cameraIndex = this->activeStone_->getCurrentCameraIndex();
     350            cameraIndex = this->activeBrick_->getCurrentCameraIndex();
    241351            this->player_->stopControl();
    242352        }
    243        
    244         // Make the last stone to be created the active stone.
    245         this->activeStone_ = this->stones_.back();
    246        
    247         this->player_->startControl(this->activeStone_);
    248         this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
    249         this->activeStone_->setCameraPosition(cameraIndex);
    250     }
    251 
    252     /**
    253     @brief
    254         Creates a new stone.
    255     */
    256     void Tetris::createStone(void)
    257     {
    258         // Create a new stone and add it to the list of stones.
    259         TetrisStone* stone = new TetrisStone(this->center_);
    260         this->stones_.push_back(stone);
    261        
     353
     354        // Make the last brick to be created the active brick.
     355        this->activeBrick_ = this->bricks_.back();
     356
     357        this->player_->startControl(this->activeBrick_);
     358        this->activeBrick_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
     359        this->activeBrick_->setCameraPosition(cameraIndex);
     360    }
     361
     362    void Tetris::createBrick(void)             //TODO: random rotation offset between 0 and 3 (times 90°)
     363    {
     364        // Use the futureBrick_ as new currentBrick by setting its position and storing it in this->bricks
     365        if(this->futureBrick_ != NULL)
     366        {
     367            for (unsigned int i = 0; i < this->futureBrick_->getNumberOfStones(); i++)
     368            {
     369                this->stones_.push_back(this->futureBrick_->getStone(i));
     370            }
     371            float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
     372            float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
     373            this->futureBrick_->setPosition(xPos, yPos, 0.0f);
     374            this->bricks_.push_back(this->futureBrick_);
     375        }
     376        // create new futureBrick_
     377        this->futureBrick_ = new TetrisBrick(this->center_);
     378
     379
    262380        // Apply the stone template to the stone.
    263         stone->addTemplate(this->center_->getStoneTemplate());
    264        
    265         // Attach the stone to the Centerpoint and set the position of the stone to be at the top middle.
    266         this->center_->attach(stone);
    267         float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
    268         float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
    269         stone->setPosition(xPos, yPos, 0.0f);
    270         stone->setGame(this);
    271     }
     381        this->futureBrick_->addTemplate(this->center_->getBrickTemplate());
     382
     383        // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
     384        this->center_->attach(this->futureBrick_);
     385        float xPos = (this->center_->getWidth()*1.6 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
     386        float yPos = (this->center_->getHeight()-5.1f)*this->center_->getStoneSize();
     387        this->futureBrick_->setPosition(xPos, yPos, 0.0f);
     388        this->futureBrick_->setGame(this);
     389    }
     390
    272391
    273392    /**
     
    282401    }
    283402
     403    /*TetrisCenterpoint* Tetris::getCenterpoint(void) const
     404    {
     405        return this->center_;
     406    }*/
     407
    284408    /**
    285409    @brief Set the TetrisCenterpoint (the playing field).
     
    291415    }
    292416
     417    /**
     418    @brief Check each row if it is full. Removes all full rows. Update
     419    @brief Manages score.
     420    */
     421    void Tetris::findFullRows()
     422    {
     423        unsigned int correctPosition = 0;
     424        unsigned int stonesPerRow = 0;
     425        for (unsigned int row = 0; row < this->center_->getHeight(); row++)
     426        {
     427            stonesPerRow = 0;
     428            for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     429            {
     430                correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize());
     431                if(correctPosition == row)
     432                {
     433                    stonesPerRow++;
     434                    if(stonesPerRow == this->center_->getWidth())
     435                    {
     436                        clearRow(row);
     437                        row--; //the row counter has to be decreased in order to detect multiple rows!
     438                        this->playerScored(this->player_);// add points
     439                        //increase the stone's speed
     440                        this->center_->setStoneSpeed(this->center_->getStoneSpeed()+1.0f);
     441                    }
     442                }
     443            }
     444        }
     445    }
     446
     447    void Tetris::clearRow(unsigned int row)
     448    {// clear the full row
     449        for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     450        {
     451            if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row)
     452                (*it)->setPosition(Vector3(-50,-50,100));
     453                //{(*it)->destroy(); this->stones_.erase(it); orxout()<< "destroy row "<<endl;}//experimental
     454        }
     455      // adjust height of stones above the deleted row //TODO: check if this could be a source of a bug.
     456        for(std::vector<TetrisStone*>::iterator it2 = this->stones_.begin(); it2 != this->stones_.end(); ++it2)
     457        {
     458            if(static_cast<unsigned int>(((*it2)->getPosition().y - 5)/this->center_->getStoneSize()) > row)
     459                (*it2)->setPosition((*it2)->getPosition()-Vector3(0,10,0));
     460        }
     461
     462    }
     463
     464
    293465}
  • code/branches/presentation2012merge/src/modules/tetris/Tetris.h

    r8706 r9286  
    6868
    6969            PlayerInfo* getPlayer(void) const; //!< Get the player.
     70            WeakPtr<TetrisCenterpoint> getCenterpoint(void)
     71                { return this->center_; }
    7072
    7173            bool isValidMove(TetrisStone* stone, const Vector3& position);
     74            bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation);
     75            Vector3 rotateVector(Vector3 position, unsigned int amount);
    7276
    7377        protected:
    7478            virtual void spawnPlayersIfRequested(); //!< Spawns player.
    7579
     80
    7681        private:
    77             void startStone(void); //!< Starts with the first stone.
    78             void createStone(void);
     82            void startBrick(void);
     83            void createBrick(void);
    7984            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    8085            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
     86            bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
     87            void findFullRows(void);
     88            void clearRow(unsigned int row);
     89
    8190           
    8291            PlayerInfo* player_;
    8392
    8493            WeakPtr<TetrisCenterpoint> center_; //!< The playing field.
     94            std::vector<TetrisBrick*> bricks_; //!< A list of all bricks in play.
    8595            std::vector<TetrisStone*> stones_; //!< A list of all stones in play.
    8696            std::vector< std::vector<bool> > grid_;
    87             TetrisStone* activeStone_;
     97            TetrisBrick* activeBrick_;
     98            TetrisBrick* futureBrick_;
    8899           
    89100            Timer starttimer_; //!< A timer to delay the start of the game.
     101            float endGameCriteria_; //<! Works as a timer which is resetted, whenever a brick is created.
    90102    };
    91103}
  • code/branches/presentation2012merge/src/modules/tetris/TetrisCenterpoint.cc

    r8706 r9286  
    3030    @file TetrisCenterpoint.cc
    3131    @brief Implementation of the TetrisCenterpoint class.
     32    @ingroup Tetris
    3233*/
    3334
     
    5556        this->stoneSize_ = 10.0f;
    5657        this->stoneTemplate_ = "";
     58        this->brickTemplate_ = "";
    5759        this->stoneSpeed_ = 20.0f;
    5860       
     
    6971
    7072        XMLPortParam(TetrisCenterpoint, "width", setWidth, getWidth, xmlelement, mode); // die Breite
    71         XMLPortParam(TetrisCenterpoint, "height", setHeight, setWidth, xmlelement, mode); // die Grösse
     73        XMLPortParam(TetrisCenterpoint, "height", setHeight, getHeight, xmlelement, mode); // die Grösse //was sollte das mit setWidth??
    7274        XMLPortParam(TetrisCenterpoint, "stoneSize", setStoneSize, getStoneSize, xmlelement, mode);
    7375        XMLPortParam(TetrisCenterpoint, "stoneTemplate", setStoneTemplate, getStoneTemplate, xmlelement, mode);
     76        XMLPortParam(TetrisCenterpoint, "brickTemplate", setBrickTemplate, getBrickTemplate, xmlelement, mode);
    7477        XMLPortParam(TetrisCenterpoint, "stoneSpeed", setStoneSpeed, getStoneSpeed, xmlelement, mode);
    7578    }
  • code/branches/presentation2012merge/src/modules/tetris/TetrisCenterpoint.h

    r8706 r9286  
    4545
    4646namespace orxonox
    47 {
     47{//idea: add 2 triggers to the centerpoint (one to determine when a box would go above the centerpoint;
     48//the other to find out when the lowest row is filled totally)
    4849   
    4950    /**
     
    118119           
    119120            /**
     121            @brief Set the template for the bricks.
     122            @param template The template name to be applied to each brick.
     123            */
     124            void setBrickTemplate(const std::string& templateName)
     125                { this->brickTemplate_ = templateName; }
     126            /**
     127            @brief Get the template for the bricks.
     128            @return Returns the template name to be applied to each brick.
     129            */
     130            const std::string& getBrickTemplate(void) const
     131                { return this->brickTemplate_; }
     132
     133            /**
    120134            @brief Set the speed of the stones.
    121135            @param speed The speed to be set.
     
    137151            float stoneSize_;
    138152            std::string stoneTemplate_;
     153            std::string brickTemplate_;
    139154            float stoneSpeed_;
    140155
  • code/branches/presentation2012merge/src/modules/tetris/TetrisPrereqs.h

    r8706 r9286  
    6868    class TetrisCenterpoint;
    6969    class TetrisStone;
     70    class TetrisBrick;
     71    class TetrisScore;
    7072}
    7173
  • code/branches/presentation2012merge/src/modules/tetris/TetrisStone.cc

    r8706 r9286  
    3030    @file TetrisStone.cc
    3131    @brief Implementation of the TetrisStone class.
     32    @ingroup Tetris
    3233*/
    3334
     
    4748        Constructor. Registers and initializes the object.
    4849    */
    49     TetrisStone::TetrisStone(BaseObject* creator) : ControllableEntity(creator)
     50    TetrisStone::TetrisStone(BaseObject* creator) : Pawn(creator)
    5051    {
    5152        RegisterObject(TetrisStone);
    52        
     53
    5354        this->size_ = 10.0f;
    5455        this->delay_ = false;
    5556        this->delayTimer_.setTimer(0.2f, false, createExecutor(createFunctor(&TetrisStone::enableMovement, this)));
     57        this->lockRotation_ = false;
     58
    5659    }
    5760
     
    6467    void TetrisStone::moveFrontBack(const Vector2& value)
    6568    {
    66         if(value.x < 0)
     69        if(value.x < 0) //speedup on key down
    6770        {
    6871            this->setVelocity(this->getVelocity()*1.1);
     72        }
     73        else if(!this->lockRotation_) //rotate when key up is pressed
     74        {
     75            this->lockRotation_ = true; // multiple calls of this function have to be filtered out.
     76            this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisStone::unlockRotation, this)));
     77            Quaternion q(Degree(90), Vector3::UNIT_Z);
     78            this->setOrientation(this->getOrientation()*q); //rotation: roll 90°
     79
    6980        }
    7081    }
  • code/branches/presentation2012merge/src/modules/tetris/TetrisStone.h

    r8706 r9286  
    3838#include "tetris/TetrisPrereqs.h"
    3939
    40 #include "worldentities/ControllableEntity.h"
     40#include "worldentities/pawns/Pawn.h"
    4141#include "tools/Timer.h"
    4242
     
    5151    @ingroup Tetris
    5252    */
    53     class _TetrisExport TetrisStone : public ControllableEntity
     53    class _TetrisExport TetrisStone : public Pawn
    5454    {
    5555        public:
     
    8181            void enableMovement(void)
    8282                { this->delay_ = false; }
    83            
     83            void unlockRotation(void)
     84                { this->lockRotation_ = false; }
     85
    8486            float size_; //!< The dimensions a stone has in the game world.
    8587            bool delay_;
     88            bool lockRotation_;
    8689            Timer delayTimer_;
     90            Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
    8791
    8892            Tetris* tetris_;
  • code/branches/presentation2012merge/src/orxonox/OrxonoxPrereqs.h

    r8858 r9286  
    109109    class TeamDeathmatch;
    110110    class UnderAttack;
     111    class TeamGametype;
    111112
    112113    // graphics
  • code/branches/presentation2012merge/src/orxonox/gametypes/Dynamicmatch.cc

    r9279 r9286  
    3131//Low; Codeoptimierung und Dokumentation
    3232
    33 /*
    34 short gaming manual:
    35 There are three different parties a player can belong to: victim, chaser or killer
    36 Every player starts as chaser. As long as there are not enough victims and killers, you can change your and other player's parties by shooting them.
    37 In order to win you have to earn as much points as possible:
    38 - as victim by escaping the chasers
    39 - as chaser by shooting the victim
    40 - as killer by killing the chasers
    41 
    42 
    43 What you shouldn't do is shooting at players of your own party. By doing so your score will decrease.
    44 P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser.
     33/**
     34@brief
     35    Short Gaming Manual:
     36    There are three different parties a player can belong to: victim, chaser or killer
     37    Every player starts as chaser. As long as there are not enough victims and killers, you can change your and other player's parties by shooting them.
     38    In order to win you have to earn as much points as possible:
     39    - as victim by escaping the chasers
     40    - as chaser by shooting the victim
     41    - as killer by killing the chasers
     42
     43
     44    What you shouldn't do is shooting at players of your own party. By doing so your score will decrease.
     45    P.S: If you don't want to be a victim: Get rid of your part by shooting a chaser.
    4546*/
    4647#include "Dynamicmatch.h"
     
    9596            ColourValue(0.3f, 0.3f, 1.0f),  //piggycolour
    9697            ColourValue(0.3f, 1.0f, 0.3f)   //killercolour  what about black: 0.0f, 0.0f, 0.0f
    97 
    9898        };
    9999        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
     
    111111        if (victim && victim->getPlayer()) //&& originator && originator->getPlayer() ??
    112112        {
    113         int target= playerParty_[victim->getPlayer()];
    114         int source= playerParty_[originator->getPlayer()];
     113            int target = playerParty_[victim->getPlayer()];
     114            int source = playerParty_[originator->getPlayer()];
    115115
    116116            //Case: Not Enough Pigs: party change (= party management)
     
    309309    /**
    310310    @brief
    311         Grant the piggy a boost.
     311        Grant the victim a boost.
    312312    @param spaceship
    313313        The SpaceShip to give the boost.
     
    315315    void Dynamicmatch::grantPigBoost(SpaceShip* spaceship)
    316316    {
    317         // Give pig boost
     317        // Give victim boost
    318318        if (spaceship)
    319319        {
     
    374374
    375375        if (this->hasStarted() && !gameEnded_)
    376         {   pointsPerTime =pointsPerTime + dt;
    377             gameTime_ = gameTime_ - dt;
    378             if (pointsPerTime > 2.0f)//hard coded!! should be changed
    379             {
    380                 pointsPerTime=0.0f;
     376        {
     377orxout() << " number of chasers:  " << numberOf[chaser] << endl;
     378orxout() << " number of killers:  " << numberOf[killer] << endl;
     379orxout() << " number of victims:  " << numberOf[piggy] << endl;
     380            pointsPerTime = pointsPerTime + dt; //increase points
     381            gameTime_ = gameTime_ - dt; // decrease game time
     382            if (pointsPerTime > 2.0f) //hard coded points for victim! should be changed
     383            {
     384                pointsPerTime = 0.0f;
    381385                rewardPig();
    382386            }
     
    408412    }
    409413
     414/**
     415    @brief The reward function is called every 2 seconds via the tick function and makes the victim score points.
     416*/
    410417    void Dynamicmatch::rewardPig()
    411418    {
     
    415422            {
    416423                 //Spieler mit der Pig-party frags++
    417                  std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);// still not sure if right syntax
     424                 std::map<PlayerInfo*, Player>::iterator it2 = this->players_.find(it->first);
    418425                 if (it2 != this->players_.end())
    419426                 {
  • code/branches/presentation2012merge/src/orxonox/gametypes/TeamDeathmatch.cc

    r7182 r9286  
    3030
    3131#include "core/CoreIncludes.h"
    32 #include "core/ConfigValueIncludes.h"
    33 #include "interfaces/TeamColourable.h"
    34 #include "worldentities/TeamSpawnPoint.h"
     32#include "chat/ChatManager.h"
     33#include "infos/PlayerInfo.h"
    3534#include "worldentities/pawns/Pawn.h"
    3635
     
    3938    CreateUnloadableFactory(TeamDeathmatch);
    4039
    41     TeamDeathmatch::TeamDeathmatch(BaseObject* creator) : Deathmatch(creator)
     40    TeamDeathmatch::TeamDeathmatch(BaseObject* creator) : TeamGametype(creator)
    4241    {
    4342        RegisterObject(TeamDeathmatch);
    44 
    45         this->teams_ = 2;
    46 
    47         this->setConfigValues();
    4843    }
    4944
    50     void TeamDeathmatch::setConfigValues()
     45    void TeamDeathmatch::start()
    5146    {
    52         SetConfigValue(teams_, 2);
     47        TeamGametype::start();
    5348
    54         static ColourValue colours[] =
    55         {
    56             ColourValue(1.0f, 0.3f, 0.3f),
    57             ColourValue(0.3f, 0.3f, 1.0f),
    58             ColourValue(0.3f, 1.0f, 0.3f),
    59             ColourValue(1.0f, 1.0f, 0.0f)
    60         };
    61         static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
     49        std::string message("The match has started!");
     50        ChatManager::message(message);
     51    }
    6252
    63         SetConfigValue(teamcolours_, defaultcolours);
     53    void TeamDeathmatch::end()
     54    {
     55        TeamGametype::end();
     56
     57        std::string message("The match has ended.");
     58        ChatManager::message(message);
    6459    }
    6560
    6661    void TeamDeathmatch::playerEntered(PlayerInfo* player)
    6762    {
    68         Deathmatch::playerEntered(player);
     63        TeamGametype::playerEntered(player);
    6964
    70         std::vector<unsigned int> playersperteam(this->teams_, 0);
    71 
    72         for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    73             if (it->second < static_cast<int>(this->teams_) && it->second >= 0)
    74                 playersperteam[it->second]++;
    75 
    76         unsigned int minplayers = static_cast<unsigned int>(-1);
    77         size_t minplayersteam = 0;
    78         for (size_t i = 0; i < this->teams_; ++i)
    79         {
    80             if (playersperteam[i] < minplayers)
    81             {
    82                 minplayers = playersperteam[i];
    83                 minplayersteam = i;
    84             }
    85         }
    86 
    87         this->teamnumbers_[player] = minplayersteam;
     65        const std::string& message = player->getName() + " entered the game";
     66        ChatManager::message(message);
    8867    }
    8968
    9069    bool TeamDeathmatch::playerLeft(PlayerInfo* player)
    9170    {
    92         bool valid_player = Deathmatch::playerLeft(player);
     71        bool valid_player = TeamGametype::playerLeft(player);
    9372
    9473        if (valid_player)
    95             this->teamnumbers_.erase(player);
     74        {
     75            const std::string& message = player->getName() + " left the game";
     76            ChatManager::message(message);
     77        }
     78
     79        return valid_player;
     80    }
     81    bool TeamDeathmatch::playerChangedName(PlayerInfo* player)
     82    {
     83        bool valid_player = TeamGametype::playerChangedName(player);
     84
     85        if (valid_player)
     86        {
     87            const std::string& message = player->getOldName() + " changed name to " + player->getName();
     88            ChatManager::message(message);
     89        }
    9690
    9791        return valid_player;
    9892    }
    9993
    100     bool TeamDeathmatch::allowPawnHit(Pawn* victim, Pawn* originator)
     94    void TeamDeathmatch::pawnKilled(Pawn* victim, Pawn* killer)
    10195    {
    102         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
     96        if (victim && victim->getPlayer())
     97        {
     98            std::string message;
     99            if (killer)
     100            {
     101                if (killer->getPlayer())
     102                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
     103                else
     104                    message = victim->getPlayer()->getName() + " was killed";
     105            }
     106            else
     107                message = victim->getPlayer()->getName() + " died";
     108
     109            ChatManager::message(message);
     110        }
     111
     112        Gametype::pawnKilled(victim, killer);
    103113    }
    104114
    105     bool TeamDeathmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
     115    void TeamDeathmatch::playerScored(PlayerInfo* player)
    106116    {
    107         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
    108     }
     117        TeamGametype::playerScored(player);
    109118
    110     bool TeamDeathmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
    111     {
    112         return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
    113     }
    114 
    115     SpawnPoint* TeamDeathmatch::getBestSpawnPoint(PlayerInfo* player) const
    116     {
    117         int desiredTeamNr = -1;
    118         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    119         if (it_player != this->teamnumbers_.end())
    120             desiredTeamNr = it_player->second;
    121 
    122         // Only use spawnpoints of the own team (or non-team-spawnpoints)
    123         std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
    124         for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
     119        if (player)
    125120        {
    126             if ((*it)->isA(Class(TeamSpawnPoint)))
    127             {
    128                 TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
    129                 if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)
    130                 {
    131                     teamSpawnPoints.erase(it++);
    132                     continue;
    133                 }
    134             }
    135 
    136             ++it;
    137         }
    138 
    139         SpawnPoint* fallbackSpawnPoint = NULL;
    140         if (teamSpawnPoints.size() > 0)
    141         {
    142             unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
    143             unsigned int index = 0;
    144             // Get random fallback spawnpoint in case there is no active SpawnPoint.
    145             for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
    146             {
    147                 if (index == randomspawn)
    148                 {
    149                     fallbackSpawnPoint = (*it);
    150                     break;
    151                 }
    152 
    153                 ++index;
    154             }
    155 
    156             // Remove all inactive SpawnPoints from the list.
    157             for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
    158             {
    159                 if(!(*it)->isActive())
    160                 {
    161                     teamSpawnPoints.erase(it++);
    162                     continue;
    163                 }
    164 
    165                 ++it;
    166             }
    167 
    168             randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
    169             index = 0;
    170             for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
    171             {
    172                 if (index == randomspawn)
    173                     return (*it);
    174 
    175                 ++index;
    176             }
    177 
    178             return fallbackSpawnPoint;
    179         }
    180 
    181         return 0;
    182     }
    183 
    184     void TeamDeathmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn)
    185     {
    186         if (!player)
    187             return;
    188 
    189         // Set the team colour
    190         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    191         if (it_player != this->teamnumbers_.end() && it_player->second >= 0 && it_player->second < static_cast<int>(this->teamcolours_.size()))
    192         {
    193             if (pawn)
    194             {
    195                 pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
    196 
    197                 std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
    198                 for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
    199                 {
    200                     if ((*it)->isA(Class(TeamColourable)))
    201                     {
    202                         TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
    203                         tc->setTeamColour(this->teamcolours_[it_player->second]);
    204                     }
    205                 }
    206             }
     121            const std::string& message = player->getName() + " scores!";
     122            ChatManager::message(message);
    207123        }
    208124    }
    209125
    210     bool TeamDeathmatch::pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2)
    211     {
    212         if (pawn1 && pawn2)
    213         {
    214             std::map<PlayerInfo*, int>::const_iterator it1 = this->teamnumbers_.find(pawn1->getPlayer());
    215             std::map<PlayerInfo*, int>::const_iterator it2 = this->teamnumbers_.find(pawn2->getPlayer());
    216 
    217             if (it1 != this->teamnumbers_.end() && it2 != this->teamnumbers_.end())
    218                 return (it1->second == it2->second);
    219         }
    220         return false;
    221     }
    222 
    223     int TeamDeathmatch::getTeam(PlayerInfo* player)
    224     {
    225         std::map<PlayerInfo*, int>::const_iterator it_player = this->teamnumbers_.find(player);
    226         if (it_player != this->teamnumbers_.end())
    227             return it_player->second;
    228         else
    229             return -1;
    230     }
    231126}
  • code/branches/presentation2012merge/src/orxonox/gametypes/TeamDeathmatch.h

    r9016 r9286  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include <map>
    35 #include <vector>
    36 #include "Deathmatch.h"
     33#include "TeamGametype.h"
    3734
    3835namespace orxonox
    3936{
    40     class _OrxonoxExport TeamDeathmatch : public Deathmatch
     37    class _OrxonoxExport TeamDeathmatch : public TeamGametype
    4138    {
    4239        public:
     
    4441            virtual ~TeamDeathmatch() {}
    4542
    46             void setConfigValues();
    47 
     43            virtual void start();
     44            virtual void end();
    4845            virtual void playerEntered(PlayerInfo* player);
    4946            virtual bool playerLeft(PlayerInfo* player);
     47            virtual bool playerChangedName(PlayerInfo* player);
    5048
    51             virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
    52             virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
    53             virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
    54 
    55             virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
    56 
    57             int getTeam(PlayerInfo* player);
    58             inline const ColourValue& getTeamColour(int teamnr) const
    59                 { return this->teamcolours_[teamnr]; }
    60 
    61         protected:
    62             virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
    63             bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
    64 
    65             std::map<PlayerInfo*, int> teamnumbers_;
    66             std::vector<ColourValue> teamcolours_;
    67             unsigned int teams_;
     49            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
     50            virtual void playerScored(PlayerInfo* player);
    6851    };
    6952}
  • code/branches/presentation2012merge/src/orxonox/gametypes/TeamGametype.cc

    r9271 r9286  
    8989    }
    9090
     91    /**
     92    @brief
     93        Function that determines the player's team number when entering the game for the first time.
     94        Override this function for other team structures.
     95    */
    9196    void TeamGametype::findAndSetTeam(PlayerInfo* player)
    9297    {
     
    130135            this->allowedInGame_.erase(player);
    131136        }
    132 
    133137
    134138        return valid_player;
Note: See TracChangeset for help on using the changeset viewer.