Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9092


Ignore:
Timestamp:
Apr 17, 2012, 11:51:21 PM (12 years ago)
Author:
jo
Message:

Tetris on the way to get completed. I fixed some bugs concerning rotation, false brick placement on brick-brick collisions, clearing multiple rows and added a preview brick feature and a basic hud.

Location:
code/branches/pCuts
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pCuts/data/levels/tetris.oxw

    r9090 r9092  
    99  include("HUDTemplates3.oxo")
    1010  include("stats.oxo")
    11   include("pongHUD.oxo")
     11  include("tetrisHUD.oxo")
    1212  include("templates/lodInformation.oxt")
    1313?>
     
    2424  <TetrisStone camerapositiontemplate=tetrisstonecameras>
    2525    <attached>
    26       <Model position="0,0,0" mesh="crate.mesh" scale=1 />
     26      <Model position="0,0,0" mesh="crate.mesh" scale=0.9 />
    2727    </attached>
    2828  </TetrisStone>
     
    5959   skybox       = "Orxonox/skypanoramagen1"
    6060  >
     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
    6168    <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
    6270
    6371    <?lua
     
    8088    </TetrisCenterpoint>
    8189
     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
     100
    82101  </Scene>
    83102</Level>
  • code/branches/pCuts/src/modules/tetris/CMakeLists.txt

    r9090 r9092  
    1212  LINK_LIBRARIES
    1313    orxonox
     14    overlays
    1415  SOURCE_FILES ${TETRIS_SRC_FILES}
    1516)
  • code/branches/pCuts/src/modules/tetris/Tetris.cc

    r9090 r9092  
    2626 *
    2727 *
    28  *BUG b) the falling brick is set the wrong way after a (brick-brick) collision, if the falling brick was turned
    2928 *BUG c) destroying the old stones causes segfault -> WeakPointer as solution ?
    3029 *BUG d) wrong collision detection: sometimes stones "bounce off"
    31  *BUG e) multiple rows are not cleared in one round
    32  *
    33  *
    34  *TASK b) write a hud (show points gained; new brick)
     30 *
     31 *
    3532 *TASK c) end the game in a nicer way
    3633 *TASK d) save the highscore
     
    6461    @brief
    6562        Constructor. Registers and initializes the object.
     63    @ingroup Tetris
    6664    */
    6765    Tetris::Tetris(BaseObject* creator) : Deathmatch(creator)
     
    7775        this->player_ = NULL;
    7876        this->endGameCriteria_ = 0.0f;
     77        this->setHUDTemplate("TetrisHUD");
     78        this->futureBrick_ = NULL;
    7979    }
    8080
     
    158158        {
    159159            TetrisStone* stone = brick->getStone(i);
    160             Vector3 stonePosition;
     160            Vector3 stonePosition; //the current stone's offset to position
    161161            if(isRotation)
    162162                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
     
    164164                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
    165165
    166             if(! this->isValidMove(stone, position + stonePosition )) // wrong position??
     166            if(! this->isValidMove(stone, position + stonePosition ))
    167167            {
    168168                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                }
    169178            }
    170179        }
     
    193202            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    194203            {
    195                 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->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));
    196208                return false;
    197209            }// This case applies if the stones overlap partially vertically
     
    201213        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    202214        {
    203                 int yOffset = stone->getPosition().y;//calculate offset
    204                 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->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));
    205219            return false;
    206220        }
     
    208222        return true;
    209223    }
    210 
     224    /**
     225     * @brief This function determines wether a brick touches another brick or the ground.
     226     *
     227     */
    211228    bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position)
    212229    {
     
    247264        if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.
    248265        {
     266            // Create the futureBrick_
     267            this->createBrick();
    249268            // Create the first brick.
    250269            this->createBrick();
     
    343362    void Tetris::createBrick(void)             //TODO: random rotation offset between 0 and 3 (times 90°)
    344363    {
    345         // Create a new brick and add it to the list of bricks && to the list of stones.
    346         TetrisBrick* brick = new TetrisBrick(this->center_);
    347         this->bricks_.push_back(brick);
    348         for (unsigned int i = 0; i < brick->getNumberOfStones(); i++)
    349         {
    350             this->stones_.push_back(brick->getStone(i));
    351         }
     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
    352379
    353380        // Apply the stone template to the stone.
    354         brick->addTemplate(this->center_->getBrickTemplate());
    355 
    356         // Attach the brick to the Centerpoint and set the position of the brick to be at the top middle.
    357         this->center_->attach(brick);
    358         float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
    359         float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
    360         brick->setPosition(xPos, yPos, 0.0f);
    361         brick->setGame(this);
     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);
    362389    }
    363390
     
    389416
    390417    /**
    391     @brief Check each row if it is full. Remove all full rows. Let all stones above the deleted row sink down.
    392     @brief Manage score.
     418    @brief Check each row if it is full. Removes all full rows. Update
     419    @brief Manages score.
    393420    */
    394421    void Tetris::findFullRows()
     
    399426        {
    400427            stonesPerRow = 0;
    401             for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
     428            for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
    402429            {
    403430                correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize());
     
    408435                    {
    409436                        clearRow(row);
     437                        row--; //the row counter has to be decreased in order to detect multiple rows!
    410438                        this->playerScored(this->player_);// add points
    411439                        //increase the stone's speed
     
    413441                    }
    414442                }
    415 
    416443            }
    417 
    418444        }
    419445    }
  • code/branches/pCuts/src/modules/tetris/Tetris.h

    r9087 r9092  
    9696            std::vector< std::vector<bool> > grid_;
    9797            TetrisBrick* activeBrick_;
     98            TetrisBrick* futureBrick_;
    9899           
    99100            Timer starttimer_; //!< A timer to delay the start of the game.
  • code/branches/pCuts/src/modules/tetris/TetrisBrick.cc

    r9087 r9092  
    4949    @brief
    5050        Constructor. Registers and initializes the object.
     51    @ingroup Tetris
    5152    */
    5253    TetrisBrick::TetrisBrick(BaseObject* creator): ControllableEntity(creator)
     
    7172    { //Index 0 : single stone, 1 : 4 in a row; 2: 4-Block right shifted; 3: 'T' 4: 4-Block left shifted;
    7273      //Index 5 : 4-Block; 6 : 'L'; 7 : mirrored 'L';
    73         orxout()<< "TetrisBrick::createBrick" << endl;
    7474        if(this->shapeIndex_ == 0)
    7575            this->stonesPerBrick_ = 1;
  • code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc

    r9082 r9092  
    3030    @file TetrisCenterpoint.cc
    3131    @brief Implementation of the TetrisCenterpoint class.
     32    @ingroup Tetris
    3233*/
    3334
  • code/branches/pCuts/src/modules/tetris/TetrisScore.cc

    r9091 r9092  
    3030    @file TetrisScore.cc
    3131    @brief Implementation of the TetrisScore class.
     32    @ingroup Tetris
    3233*/
    3334
     
    4950    @brief
    5051        Constructor. Registers and initializes the object.
     52    @ingroup Tetris
    5153    */
    5254    TetrisScore::TetrisScore(BaseObject* creator) : OverlayText(creator)
     
    5658        this->owner_ = 0;
    5759        this->player_ = NULL;
    58         this->lock_ = true;
    5960    }
    6061
     
    9192        {
    9293            std::string score("0");
    93                 if(!this->owner_->hasEnded() && this->lock_)
     94                if(!this->owner_->hasEnded())
    9495            {
    9596                //get the player
    9697                player_ = this->owner_->getPlayer();
    97                 this->lock_ = false;
    9898            }
    9999
  • code/branches/pCuts/src/modules/tetris/TetrisScore.h

    r9091 r9092  
    6767            Tetris* owner_; //!< The Tetris game that owns this TetrisScore.
    6868            PlayerInfo* player_; //!< Store information about the player permanently.
    69             bool lock_;
    7069    };
    7170}
  • code/branches/pCuts/src/modules/tetris/TetrisStone.cc

    r9085 r9092  
    3030    @file TetrisStone.cc
    3131    @brief Implementation of the TetrisStone class.
     32    @ingroup Tetris
    3233*/
    3334
Note: See TracChangeset for help on using the changeset viewer.