git repos / blockattack-game

commit 1176ee18

sago007 · 2017-08-19 16:10
1176ee18a5484bf36dc3738c43f273688b321b06 patch · browse files
parent c01ed678e2ce8176c83e059abc4b43c20cf565eb

Added comment about the horrible base 10 packing system and formatted the source

Changed files

M source/code/BlockGame.cpp before
M source/code/ReplayPlayer.cpp before
M source/code/ScoresDisplay.cpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index a407b3e..b4e7f68 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -31,6 +31,34 @@ http://blockattack.net
#define GARBAGE 1000000
#define CHAINPLACE 10000000
+// The game uses a very special base-10 pack system
+// int 999999999999
+// YYYYYGWBHTTC
+// YYYY = Chain
+// G = Garbage, 1= NORMAL, 2=GRAY
+// W = Waiting (A bomb is on it)
+// B = 1 if the block is falling
+// H = Block is hanging after garbage (Get Ready text on it)
+// TT = Time (in steps) until something happens
+// C = color
+
+static bool block_isFalling(int block) {
+ return (block/BLOCKFALL)%10;
+}
+
+static void block_setFalling(int& block, bool value) {
+ if (value) {
+ if (!block_isFalling(block)) {
+ block += BLOCKFALL;
+ }
+ }
+ else {
+ if (block_isFalling(block)) {
+ block -= BLOCKFALL;
+ }
+ }
+}
+
#include "BlockGame.hpp"
#include "puzzlehandler.hpp"
#include "stageclearhandler.hpp"
@@ -724,10 +752,10 @@ void BlockGame::ClearBlocks() {
bool faaling = false;
for (int j=0; j<30; j++) {
if ((faaling)&&(board[i][j]>-1)&&(board[i][j]%10000000<7)) {
- board[i][j]+=BLOCKFALL;
+ block_setFalling(board[i][j], true);
}
if ((!faaling)&&((board[i][j]/BLOCKFALL)%10==1)) {
- board[i][j]-=BLOCKFALL;
+ block_setFalling(board[i][j], false);
}
if (!((board[i][j]>-1)&&(board[i][j]%10000000<7))) {
faaling=true;
@@ -985,10 +1013,10 @@ void BlockGame::ClearBlocks() {
bool faaling = false; //In the beginning we are NOT falling
for (int j=0; j<30; j++) {
if ((faaling)&&(board[i][j]>-1)&&(board[i][j]<7)) {
- board[i][j]+=BLOCKFALL;
+ block_setFalling(board[i][j], true);
}
- if ((!faaling)&&((board[i][j]/BLOCKFALL)%10==1)) {
- board[i][j]-=BLOCKFALL;
+ if (!faaling) {
+ block_setFalling(board[i][j], false);
}
if ((!faaling)&&(board[i][j]>0)&&(board[i][j]/10000000!=0)&&((board[i][j]/BLOCKWAIT)%10!=1)&&((board[i][j]/BLOCKHANG)%10!=1)) {
if (chainSize[board[i][j]/10000000]>chainSize[chain]) {
diff --git a/source/code/ReplayPlayer.cpp b/source/code/ReplayPlayer.cpp index 94dc131..71edd4c 100644 --- a/source/code/ReplayPlayer.cpp +++ b/source/code/ReplayPlayer.cpp
@@ -30,8 +30,8 @@ http://www.blockattack.net
/*static void MoveBlockGameSdls( BlockGameSdl& game1, BlockGameSdl& game2 ) {
- game1.SetTopXY(50, globalData.ysize/2-284);
- game2.SetTopXY(globalData.xsize-500, globalData.ysize/2-284);
+ game1.SetTopXY(50, globalData.ysize/2-284);
+ game2.SetTopXY(globalData.xsize-500, globalData.ysize/2-284);
}*/
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 196b176..a952dae 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp
@@ -159,7 +159,7 @@ void ScoresDisplay::Draw(SDL_Renderer*) {
//Draw buttons:
globalData.bHighScore.Draw(globalData.screen, 0, scoreX,scoreY);
globalData.bBack.Draw(globalData.screen, 0, backX, backY);
- globalData.nf_button_font.draw(globalData.screen, backX+60,backY+10, NFont::CENTER ,_("Back"));
+ globalData.nf_button_font.draw(globalData.screen, backX+60,backY+10, NFont::CENTER,_("Back"));
globalData.bNext.Draw(globalData.screen, 0, nextX, nextY);
globalData.nf_button_font.draw(globalData.screen, nextX+60,nextY+10, NFont::CENTER,_("Next"));
diff --git a/source/code/main.cpp b/source/code/main.cpp index f916857..40f58c9 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -226,7 +226,7 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
void DrawIMG(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y) {
- sprite.Draw(target, SDL_GetTicks() ,x,y);
+ sprite.Draw(target, SDL_GetTicks(),x,y);
}
void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y, int minx, int miny, int maxx, int maxy) {