git repos / blockattack-game

commit ce444d3b

sago007 · 2016-04-02 18:59
ce444d3b5cc6f6de20bbbb1038e96bfe56515498 patch · browse files
parent d0c62e33d410fa7ac3c81066be142739061792e3

Added a touch cursor. Fixed a problem with the AI and update. Switch blocks now calls ClearBlocks instead.

Changed files

M Game/data/sprites/blockattack.sprite before
A Game/data/textures/touchcursor.png
M source/code/BlockGame.cpp before
M source/code/main.cpp before
diff --git a/Game/data/sprites/blockattack.sprite b/Game/data/sprites/blockattack.sprite index db83ba8..0e43732 100644 --- a/Game/data/sprites/blockattack.sprite +++ b/Game/data/sprites/blockattack.sprite
@@ -166,6 +166,16 @@
"frame_time" : 400,
"originx" : 4, //This tells the game that the top left corner is placed a little different
"originy" : 4
+},
+
+"touchcursor" : {
+ "texture" : "touchcursor",
+ "topx" : 0,
+ "topy" : 0,
+ "height" : 52,
+ "width" : 52,
+ "originx" : 1,
+ "originy" : 1
}
}
diff --git a/Game/data/textures/touchcursor.png b/Game/data/textures/touchcursor.png new file mode 100644 index 0000000..734cb37
Binary files /dev/null and b/Game/data/textures/touchcursor.png differ
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 85e7cd0..71aadd2 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -1161,8 +1161,11 @@ void BlockGame::MoveCursor(char way) {
//switches the two blocks at the cursor position, unless game over
void BlockGame::SwitchAtCursor() {
- Update(); //Ensure that everything is in a stable state.
- if ((board[cursorx][cursory+1]<7) && (board[cursorx+1][cursory+1]<7) && (!bGameOver) && ((!puzzleMode)||(MovesLeft>0)) && (gameStartedAt<ticks)) {
+ if (bGameOver) {
+ return;
+ }
+ ClearBlocks(); //Ensure that everything that floats are marked as floating
+ if ((board[cursorx][cursory+1]<7) && (board[cursorx+1][cursory+1]<7) && ((!puzzleMode)||(MovesLeft>0)) && (gameStartedAt<ticks)) {
int temp = board[cursorx][cursory+1];
board[cursorx][cursory+1] = board[cursorx+1][cursory+1];
board[cursorx+1][cursory+1] = temp;
diff --git a/source/code/main.cpp b/source/code/main.cpp index 2beb2d7..eed4119 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -223,11 +223,11 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
-void DrawIMG(sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y) {
+void DrawIMG(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y) {
sprite.Draw(target, SDL_GetTicks() ,x,y);
}
-void DrawIMG_Bounded(sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y, int minx, int miny, int maxx, int maxy) {
+void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y, int minx, int miny, int maxx, int maxy) {
SDL_Rect bounds;
bounds.x = minx;
bounds.y = miny;
@@ -551,11 +551,11 @@ public:
topy = ty;
}
- void DrawImgBoard(sago::SagoSprite& img, int x, int y) const {
+ void DrawImgBoard(const sago::SagoSprite& img, int x, int y) const {
DrawIMG(img, screen, x+topx, y+topy);
}
- void DrawImgBoardBounded(sago::SagoSprite& img, int x, int y) const {
+ void DrawImgBoardBounded(const sago::SagoSprite& img, int x, int y) const {
DrawIMG_Bounded(img, screen, x+topx, y+topy, topx, topy, topx + backBoard.GetWidth(), topy + backBoard.GetHeight());
}
@@ -846,7 +846,16 @@ public:
}
#endif
if (!bGameOver) {
- DrawImgBoard(cursor,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
+ bool touched = false;
+ int mx = 0;
+ int my = 0;
+ this->GetMouseCursor(touched, mx, my);
+ if (touched) {
+ DrawImgBoard(spriteHolder->GetSprite("touchcursor"),mx*bsize, 11*bsize-my*bsize-pixels);
+ }
+ else {
+ DrawImgBoard(cursor,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
+ }
}
if (ticks<gameStartedAt) {
int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;