dekar avatar dekar committed dd089ec

Simplest animation

Comments (0)

Files changed (2)

include/ct-level.hpp

 
 const int BLOCK_SIZE     = 5;	/**< размер блока, в который вписана фигура */
 const int FIELD_WIDTH    = 15;	/**< ширина поля тетриса(в клетках) */
-const int FIELD_HEIGHT   = 25;	/**< высота поля тетриса(в клетках) */
+const int FIELD_HEIGHT   = 16;	/**< высота поля тетриса(в клетках) */
 const int FIELD_WIDTH_P  = 480;	/**< ширина поля тетриса(в пикселях) */
-const int FIELD_HEIGHT_P = 800;	/**< ширина поля тетриса(в пикселях) */
+const int FIELD_HEIGHT_P = 512;	/**< ширина поля тетриса(в пикселях) */
 const int FALLING_ANIMATION_SPEED = 20;         /**< интервал обловления анимации в мс*/
 const float FALLING_ANIMATION_DELTA = 1.0f;     /**< смещение блока при падении в пикс.*/
 
         
         virtual ~Block() { };
 
-        virtual void    render(const Vec2f& fieldCorner) = 0;
+        virtual void    render() = 0;
         virtual void    update() = 0;
 
         virtual void	moveLeft() = 0;
 class SimpleBlock: public Block {
 public:
 
-        SimpleBlock(const Vec2f& pos, Color color);
+        SimpleBlock(const Vec2f& blockPos, const Vec2f& fieldCorner, Color color);
         ~SimpleBlock();
 
-        void    render(const Vec2f& fieldCorner);
+        void    render();
         void    update();
 
         void    moveLeft();
         void    onAnimationUpdate(Timer* timer);
 
         CellsArr        mCells;	/**< фигура, -1 - пустое место */
-        Vec2f           mPosition;
+        Vec2f           mPosition, mFieldCorner;
         Color           mColor;
         bool            mIsActive;
         Timer::Ptr      mAnimationTimer;
         Vec2f pos(mFieldCorner + Vec2f(FIELD_WIDTH_P - CELL_WIDTH_P * BLOCK_SIZE, FIELD_HEIGHT_P - CELL_HEIGHT_P * BLOCK_SIZE) / 2.0f);
         Color color(gColorMap[rand() % (sizeof(gColorMap) / sizeof(gColorMap[0]))]);
 
-        mBlocks.push_back(Block::Ptr(new SimpleBlock(pos, color)));
+        mBlocks.push_back(Block::Ptr(new SimpleBlock(pos, mFieldCorner, color)));
 }
 
 bool Level::loadTextures()
 {
 	//renderField();
         for (auto it = mBlocks.begin(); it != mBlocks.end(); ++it) {
-                (*it)->render(mFieldCorner);
+                (*it)->render();
         }
+
+        renderRect(FloatRect(mFieldCorner.x, mFieldCorner.y, FIELD_WIDTH_P, FIELD_HEIGHT_P), 
+                Color(177, 177, 177), 
+                NULL); //XXX use new ctor Luke!
 }
 
 void Level::onUpdate(StateMachine* machine)
         }
 }
 
-SimpleBlock::SimpleBlock(const Vec2f& pos, Color color): 
-        mPosition(pos), 
+SimpleBlock::SimpleBlock(const Vec2f& blockPos, const Vec2f& fieldCorner, Color color): 
+        mPosition(blockPos), 
+        mFieldCorner(fieldCorner),
         mColor(color),
         mIsActive(true)
 {
         int blocksCount = sizeof(gStandardBlocks) / sizeof(gStandardBlocks[0]);
-        int index = rand() % (blocksCount - 0); //XXX 
+        int index = rand() % (blocksCount + 1); //XXX 
 
         std::copy(gStandardBlocks[index], 
                 gStandardBlocks[index] + sizeof(gStandardBlocks[0]) / sizeof(gStandardBlocks[0][0]), 
 
 void SimpleBlock::onAnimationUpdate(Timer* timer)
 {
-        mPosition.y += FALLING_ANIMATION_DELTA;
-        LOG("G onAnimationUpdate");
+        float tmp = mPosition.y + FALLING_ANIMATION_DELTA;
+
+        if (tmp <= mFieldCorner.y + FIELD_HEIGHT_P) {
+                mPosition.y = tmp;
+        } else {
+                timer->disable();
+        }
 }
 
-void SimpleBlock::render(const Vec2f& fieldCorner)
+void SimpleBlock::render()
 {
         const float borderSize = 1.0f;
 
                 }
         }
 
-        renderCircle(fieldCorner, 20.0f, color::white, NULL);
+        renderCircle(mFieldCorner, 20.0f, color::white, NULL);
         renderCircle(mPosition, 20.0f, color::green - Color(100, 50, 100), NULL);
 }
 
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.