dekar avatar dekar committed e9e0089

const modifier added everywhere

Comments (0)

Files changed (1)

 
 namespace r2 {
 
-int gStandardBlocks[][25] = {
+const int gStandardBlocks[][25] = {
         {0, 0, 0, 0, 0,
          0, 0, 1, 0, 0,
          0, 1, 0, 1, 0,
          1, 1, 0, 0, 0}
 };
 
-Color gColorMap[] = {
+const Color gColorMap[] = {
         Color(200, 100, 0),     // 0
         Color(0, 200, 100),     // 1
         Color(50, 200, 200),    // 2
 
 Block::Ptr Level::createFallingBlock()
 {
-        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]))]);
+        const Vec2f     delta(FIELD_WIDTH_P - CELL_WIDTH_P * BLOCK_SIZE, FIELD_HEIGHT_P - CELL_HEIGHT_P * BLOCK_SIZE);
+        const Vec2f     pos(mFieldCorner + delta / 2.0f);
+        const Color     color(gColorMap[rand() % (sizeof(gColorMap) / sizeof(gColorMap[0]))]);
         Block::Ptr      block(new SimpleBlock(pos, mFieldCorner, color));
 
         mBlocks.push_back(block);
 
         for (int i = 0; i < FIELD_WIDTH; i++) {
                 for (int j = 0; j < FIELD_HEIGHT; j++) {
-                        FloatRect r(startX + i * blockW, startY + j * blockH, blockW, blockH);
+                        const FloatRect r(startX + i * blockW, startY + j * blockH, blockW, blockH);
 
                         renderRect(r, color::green, NULL);
                 }
 
 void Level::keyListener(Application::EventData* event)
 {
-        SDL_Event* ev = event->eventSDL;
+        const SDL_Event* ev = event->eventSDL;
 
         if (ev->type == SDL_KEYDOWN) {
                 //Выход в меню по Escape 
         mIsActive(true),
         mSideMovementValue(0.0f)
 {
-        int blocksCount = sizeof(gStandardBlocks) / sizeof(gStandardBlocks[0]);
-        int index = rand() % (blocksCount + 0); //XXX 
+        const int blocksCount = sizeof(gStandardBlocks) / sizeof(gStandardBlocks[0]);
+        const int index = rand() % (blocksCount + 0); //XXX 
+
         assert(index < blocksCount);
 
-        uint size = sizeof(gStandardBlocks[0]) / sizeof(gStandardBlocks[0][0]);
+        const 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);
 
 void SimpleBlock::onAnimationUpdate(Timer* timer)
 {
-        FloatRect rect = computeBoundBox();
-        float h = rect.y + rect.h;
+        const FloatRect rect = computeBoundBox();
+        const float h = rect.y + rect.h;
         //bool canDisableTimer = false;
 
         if (mPosition.y + h + FALLING_ANIMATION_DELTA <= mFieldCorner.y + FIELD_HEIGHT_P) {
         } else {
                 //timer->disable();
         }
+
+        if (mSideMovementValue != 0.0f) {
+                float absSideMovementValue = std::abs(mSideMovementValue);
+                if (absSideMovementValue > FALLING_ANIMATION_DELTA) {
+                        mSideMovementValue -= FALLING_ANIMATION_DELTA;
+
+                        mPosition.x -= FALLING_ANIMATION_DELTA;
+                } else {
+                        mSideMovementValue = 0.0f;
+                }
+        }
 }
 
 void SimpleBlock::render()
 
         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;
+                        const 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++) {
-                        int newIndex = (BLOCK_SIZE - j - 1) + i * BLOCK_SIZE;
+                        const int newIndex = (BLOCK_SIZE - j - 1) + i * BLOCK_SIZE;
 
                         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.