summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--World.cpp25
-rw-r--r--World.h7
-rw-r--r--main.cpp17
3 files changed, 41 insertions, 8 deletions
diff --git a/World.cpp b/World.cpp
index 66b1aba..1a3e9b5 100644
--- a/World.cpp
+++ b/World.cpp
@@ -3,7 +3,7 @@
World::World(int level)
{
- player.speed=1;
+ player.speed=0;
player.x2=player.x=0;
player.anim=0;
// generate level
@@ -18,6 +18,29 @@ void World::sim(double time)
{
player.x2-=1;
player.x+=1;
+
+ player.speed--;
}
}
+void World::mouseclick(int x, int y)
+{
+ for(Brick &brick:bricks[x])
+ {
+ if(brick.type<=1&&brick.altitude==y)
+ {
+ return;
+ }
+ if(brick.type>1&&brick.altitude==y)
+ {
+ brick.type++;
+ if(brick.type>=6)brick.type=2;
+ return;
+ }
+
+
+ }
+ bricks[x].push_back({y,2});
+ player.speed++;
+}
+
diff --git a/World.h b/World.h
index fbd5279..fba93b1 100644
--- a/World.h
+++ b/World.h
@@ -25,9 +25,9 @@ struct World
Player player;
std::vector<std::vector<Brick>> bricks=
{
- { {0,0} },
- { {0,0} },
- { {0,0} },
+ { {0,2} },
+ { {0,2} },
+ { {0,2} },
{ {0,0},{5,1} },
{ {0,0},{5,1} },
{ {0,0},{5,1} },
@@ -45,4 +45,5 @@ struct World
World(int level);
void sim(double);
+ void mouseclick(int x, int y);
};
diff --git a/main.cpp b/main.cpp
index 303e656..c9bfae0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -158,7 +158,7 @@ int main(int, char**){
mouse_x=event.button.x;
mouse_y=event.button.y;
- world.bricks[(mouse_x+50-world.player.x2)/100+world.player.x-5][0].altitude=10-mouse_y/100;
+ world.mouseclick((mouse_x+50-world.player.x2)/100+world.player.x-5,10-mouse_y/100);
}
@@ -193,9 +193,6 @@ int main(int, char**){
switch(world.bricks[i][j].type)
{
- case 1:
- SDL_RenderCopy(ren,textures[4],NULL,&rect);
- break;
case 0:
SDL_RenderCopy(ren,textures[4],NULL,&rect);
SDL_SetRenderDrawColor(ren, 150+19*(i%2),115,70, 255);
@@ -203,6 +200,18 @@ int main(int, char**){
rect.y+=100;
SDL_RenderFillRect(ren,&rect);
break;
+ case 1:
+ SDL_RenderCopy(ren,textures[4],NULL,&rect);
+ break;
+ case 2:
+ SDL_RenderCopy(ren,textures[5],NULL,&rect);
+ break;
+ case 3:
+ SDL_RenderCopy(ren,textures[6],NULL,&rect);
+ break;
+ case 4:
+ SDL_RenderCopyEx(ren,textures[6],NULL,&rect,90,NULL,SDL_FLIP_NONE);
+ break;
}