dekar avatar dekar committed 9330056

Work on collisions.

Comments (0)

Files changed (3)

+set tags+=\dev\ee2\tags

include/ct-level.hpp

          * 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;
         }
 }
 
-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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.