1. DeKar aka MaNt
  2. ct

Commits

DeKar aka MaNt  committed 9330056

Work on collisions.

  • Participants
  • Parent commits e9e0089
  • Branches default

Comments (0)

Files changed (3)

File .exrc

View file
  • Ignore whitespace
+set tags+=\dev\ee2\tags

File include/ct-level.hpp

View file
  • Ignore whitespace
          * mSideMovementDelta == 0.0f - без анимации
          */
         float           mSideMovementValue;
+        /**
+         * Флаг столкновения с другими фигурами. 
+         * Сбрасывается каждый кадр при ::update(), устанавливается в ::onCollide()
+         */
+        bool            mIsCollided;
 };
 
 
         void            resetGame();
         void            pause(bool state);
         Block::Ptr      createFallingBlock();
-        bool            checkCollision(const Block::Ptr b1, const Block::Ptr p2);
+        bool            checkCollision(const Block::Ptr b1, const Block::Ptr b2);
 
         LevelDesc				mLevelDesc;
         std::string			        mBlockTexturesPath;

File src/ct-level.cpp

View file
  • Ignore whitespace
         }
 }
 
-bool Level::checkCollision(const Block::Ptr b1, const Block::Ptr p2)
+bool Level::checkCollision(const Block::Ptr b1, const Block::Ptr b2)
 {
+        const CellsArr& b1Cells(b1->getCells());
+        const CellsArr& b2Cells(b2->getCells());
+
+        for (uint i = 0; i < b1Cells.size(); i++) {
+                for (uint j = 0; j < b1Cells.size(); j++) {
+                        if (false) {
+                                return true;
+                        }
+                }
+        }
+
         return false;
 }
 
         mFieldCorner(fieldCorner),
         mColor(color),
         mIsActive(true),
-        mSideMovementValue(0.0f)
+        mSideMovementValue(0.0f),
+        mIsCollided(false)
 {
         const int blocksCount = sizeof(gStandardBlocks) / sizeof(gStandardBlocks[0]);
         const int index = rand() % (blocksCount + 0); //XXX 
 
 void SimpleBlock::update()
 {
+        mIsCollided = false;
 }
 
 void SimpleBlock::moveDown()
 
 void SimpleBlock::rotateLeft()
 {
+        if (mIsCollided) {
+                return;
+        }
+
         CellsArr tmp;
 
         for (int i = 0; i < BLOCK_SIZE; i++) {
 
 void SimpleBlock::rotateRight()
 {
+        if (mIsCollided) {
+                return;
+        }
+
         CellsArr tmp;
 
         for (int i = 0; i < BLOCK_SIZE; i++) {
 
 void SimpleBlock::moveLeft()
 {
-        if (mSideMovementValue != 0.0f) {
+        if (!mIsCollided && mSideMovementValue != 0.0f) {
                 mSideMovementValue = -3.0f;
         }
 }
 
 void SimpleBlock::moveRight()
 {
-        if (mSideMovementValue != 0.0f) {
+        if (!mIsCollided && mSideMovementValue != 0.0f) {
                 mSideMovementValue = 3.0f;
         }
 }
 
 void SimpleBlock::onCollide()
 {
+        mIsCollided = true;
 }
 
 void SimpleBlock::applyTransform()