dekar avatar dekar committed 6bccb4e

Blocks rotation fixed

Comments (0)

Files changed (1)

 
 void Level::onInit(StateMachine* machine)
 {
-        mListenerConnection = gApplication->subscribeToEvent(SDL_KEYDOWN, sigc::mem_fun(*this, &Level::keyListener));
+        mListenerConnection = gApplication->subscribeToEvent(SDL_KEYDOWN, 
+                sigc::mem_fun(*this, &Level::keyListener));
 }
 
 Block::Ptr Level::createFallingBlock()
 {
-        Vec2f           pos(mFieldCorner + Vec2f(FIELD_WIDTH_P - CELL_WIDTH_P * BLOCK_SIZE, FIELD_HEIGHT_P - CELL_HEIGHT_P * BLOCK_SIZE) / 2.0f);
+        Vec2f           delta(FIELD_WIDTH_P - CELL_WIDTH_P * BLOCK_SIZE, FIELD_HEIGHT_P - CELL_HEIGHT_P * BLOCK_SIZE);
+        Vec2f           pos(mFieldCorner + delta / 2.0f);
         Color           color(gColorMap[rand() % (sizeof(gColorMap) / sizeof(gColorMap[0]))]);
         Block::Ptr      block(new SimpleBlock(pos, mFieldCorner, color));
 
 
 bool Level::loadTextures()
 {
-	TextureManager*         tm	   = gTextureManager;
+	TextureManager*         tm = gTextureManager;
         fs::Enumerator::Ptr	enumerator = fs::enumerate(mBlockTexturesPath);
 
 	LOG("G + start block textures loading");
                 (*it)->render();
         }
 
-        renderRect(FloatRect(mFieldCorner.x, mFieldCorner.y, FIELD_WIDTH_P, FIELD_HEIGHT_P), 
+        renderRect(FloatRect(mFieldCorner, FIELD_WIDTH_P, FIELD_HEIGHT_P), 
                 Color(177, 177, 177), 
                 NULL); //XXX use new ctor Luke!
 }
         int index = rand() % (blocksCount + 0); //XXX 
         assert(index < blocksCount);
 
-        std::copy(gStandardBlocks[index], 
-                gStandardBlocks[index] + sizeof(gStandardBlocks[0]) / sizeof(gStandardBlocks[0][0]), 
-                mCells.begin());
+        uint size = sizeof(gStandardBlocks[0]) / sizeof(gStandardBlocks[0][0]);
+        std::copy(gStandardBlocks[index], gStandardBlocks[index] + size, mCells.begin());
 
         mAnimationTimer = gApplication->createTimer(FALLING_ANIMATION_SPEED, true);
         mAnimationTimer->getSignal().connect(sigc::mem_fun(*this, &SimpleBlock::onAnimationUpdate));
 void SimpleBlock::rotateLeft()
 {
         CellsArr tmp;
-        LOG("G rot l");
 
         for (int i = 0; i < BLOCK_SIZE; i++) {
                 for (int j = 0; j < BLOCK_SIZE; j++) {
-                        //tmp[i + j * BLOCK_SIZE] = mCells[j + i * BLOCK_SIZE];
-                        tmp[i + j * BLOCK_SIZE] = mCells[(BLOCK_SIZE - j - 1) + 
-                                i * BLOCK_SIZE];
+                        int newIndex = (BLOCK_SIZE - j - 1) + i * BLOCK_SIZE;
+                        
+                        tmp[i + j * BLOCK_SIZE] = mCells[newIndex];
                 }
         }
 
-        //for (int i = 0; i < BLOCK_SIZE; i++) {
-                //for (int j = 0; j < BLOCK_SIZE; j++) {
-                        //tmp[j + i * BLOCK_SIZE] = mCells[i + j * BLOCK_SIZE];
-                //}
-        //}
-
         std::copy(tmp.begin(), tmp.end(), mCells.begin());
 }
 
 void SimpleBlock::rotateRight()
 {
         CellsArr tmp;
-        LOG("G rot r");
 
         for (int i = 0; i < BLOCK_SIZE; i++) {
                 for (int j = 0; j < BLOCK_SIZE; j++) {
                         int newIndex = (BLOCK_SIZE - j - 1) + i * BLOCK_SIZE;
-                        
-                        tmp[i + j * BLOCK_SIZE] = mCells[newIndex];
+
+                        tmp[newIndex] = mCells[i + j * BLOCK_SIZE]; 
                 }
         }
 
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.