dekar avatar dekar committed ecb9494

Work on gameplay basics

Comments (0)

Files changed (3)

include/ct-level.hpp

         virtual void	moveRight() = 0;
         virtual void    moveDown() = 0;
 
-        virtual void    onCollide(CellsArr* cells, uint num) = 0;
+        virtual void    onCollide() = 0;
         virtual void    applyTransform() = 0;
 
         virtual bool    isActive() const = 0;
         void    moveRight();
         void    moveDown();
 
-        void    onCollide(CellsArr* cells, uint num);
+        void    onCollide();
         void    applyTransform();
 
         bool    isActive() const { return mIsActive; };
         CellsArr&       getCells() { return mCells; }
 private:
 
+        float   calculateHeight();
         void            onAnimationUpdate(Timer* timer);
         /**
          * Рассчет bound box'а по пикселям
         void    keyListener(Application::EventData* event);
         void    resetGame();
         void    pause(bool state);
-        void    createFallingBlock();
+        Block*  createFallingBlock();
 
         LevelDesc				mLevelDesc;
         std::string			        mBlockTexturesPath;
         Vec2f                                   mFieldCorner;   /**< координаты левого верхнего угла игрового поля*/
         sigc::connection			mListenerConnection;
         bool                                    mPaused;
+        Block*                                  mCurrentBlock;
 };
 
 }
 }
 
 void Game::onRender()
-{
+{       
 	IRender* r = gRender;
 	
 	r->beginScene(sfStandard, NULL);
 int gStandardBlocks[][25] = {
         {0, 0, 0, 0, 0,
          0, 0, 1, 0, 0,
+         0, 1, 0, 1, 0,
+         0, 1, 0, 1, 0,
+         1, 1, 1, 1, 1},
+        {0, 0, 0, 0, 0,
+         0, 0, 1, 0, 0,
          0, 1, 1, 1, 0,
          0, 1, 1, 1, 0,
          1, 1, 1, 1, 1},
 void Level::onInit(StateMachine* machine)
 {
         mListenerConnection = gApplication->subscribeToEvent(SDL_KEYDOWN, sigc::mem_fun(*this, &Level::keyListener));
-
-        createFallingBlock();
-        //createFallingBlock();
         //createFallingBlock();
 }
 
 void Level::onUpdate(StateMachine* machine)
 {
         if (!mPaused) {
+                for (auto it1 = mBlocks.begin(); it1 != mBlocks.end(); ++it1) {
+                        for (auto it2 = mBlocks.begin(); it2 != mBlocks.end(); ++it2) {
+                                //if (check
+                        }
+                }
                 for (auto it = mBlocks.begin(); it != mBlocks.end(); ++it) {
                         if ((*it)->isActive()) {
                                 (*it)->moveDown();
                         renderRect(r, color::green, NULL);
                 }
         }
-
-/*
- *        FloatRect	r(x, y, );
- *
- *        p.setColor(color::green);
- *        p.setRect(r); 
- *
- *        render->renderPrimitive(&p, NULL);
- */
 }
 
 void Level::keyListener(Application::EventData* event)
 {
-        LOG("G game key");
         SDL_Event* ev = event->eventSDL;
 
         if (ev->type == SDL_KEYDOWN) {
-                if (ev->key.keysym.sym == SDLK_ESCAPE) { //Выход в меню по Escape 
+                //Выход в меню по Escape 
+                if (ev->key.keysym.sym == SDLK_ESCAPE) { 
                         getMachine()->setActive("Menu");
                 }
 
-                if (ev->key.keysym.sym == SDLK_p) { //Пауза
+                //Добавление нового блока
+                if (ev->key.keysym.sym == SDLK_SPACE) { 
+                        createFallingBlock();
+                }
+
+                //Пауза
+                if (ev->key.keysym.sym == SDLK_p) { 
                         mPaused = !mPaused;
                         pause(mPaused);
                 }
         mIsActive(true)
 {
         int blocksCount = sizeof(gStandardBlocks) / sizeof(gStandardBlocks[0]);
-        int index = rand() % (blocksCount + 1); //XXX 
+        int index = rand() % (blocksCount + 0); //XXX 
+        assert(index < blocksCount);
 
         std::copy(gStandardBlocks[index], 
                 gStandardBlocks[index] + sizeof(gStandardBlocks[0]) / sizeof(gStandardBlocks[0][0]), 
 {
 }
 
-void SimpleBlock::onCollide(CellsArr* cells, uint num)
+void SimpleBlock::onCollide()
 {
 }
 
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.