Skip to content

Commit

Permalink
v0.3b
Browse files Browse the repository at this point in the history
Known bugs :
- Blocks that are out of screen draws in the opposite side (up->down)
- Image is wrongly rotated (90° clockwise)
- Colors doesn't match the right block

Changes :
- Fixed colors partially (Thanks to Tjessx from gbatemp.net)
- Added support for L and R rotate buttons
  • Loading branch information
UltiNaruto committed Sep 27, 2015
1 parent a2a82b8 commit 0c01ed2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void drawImage(gfxScreen_t screen, const void * image, int width, int height, in
for(i = 0; i < height; i++) {
for(j = 0; j < width; j++) {
v = (height * i + width) * 3;
color_pixel(x + j, y + i, toFB[v], toFB[v++], toFB[v++], fb);
color_pixel(x + j, y + i, toFB[v++], toFB[v++], toFB[v++], fb);
}
}
}
Expand Down
36 changes: 26 additions & 10 deletions include/cBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class cBlock
}

// This function is explained in the tutorial. //
void Rotate()
void Rotate(Direction dir)
{
int x1, y1, x2, y2;

Expand All @@ -178,10 +178,18 @@ class cBlock

x1 -= m_CenterX;
y1 -= m_CenterY;

x2 = - y1;
y2 = x1;


if(dir == RIGHT)
{
x2 = - y1;
y2 = x1;
}
else if(dir == LEFT)
{
x2 = y1;
y2 = - x1;
}

x2 += m_CenterX;
y2 += m_CenterY;

Expand All @@ -192,7 +200,7 @@ class cBlock

// This function gets the locations of the squares after //
// a rotation and returns an array of those values. //
int* GetRotatedSquares()
int* GetRotatedSquares(Direction dir)
{
int* temp_array = new int[8];
int x1, y1, x2, y2;
Expand All @@ -204,10 +212,18 @@ class cBlock

x1 -= m_CenterX;
y1 -= m_CenterY;

x2 = - y1;
y2 = x1;


if(dir == RIGHT)
{
x2 = - y1;
y2 = x1;
}
else if(dir == LEFT)
{
x2 = y1;
y2 = - x1;
}

x2 += m_CenterX;
y2 += m_CenterY;

Expand Down
24 changes: 19 additions & 5 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool CheckEntityCollisions(cSquare* square, Direction dir);
bool CheckWallCollisions(cSquare* square, Direction dir);
bool CheckEntityCollisions(cBlock* block, Direction dir);
bool CheckWallCollisions(cBlock* block, Direction dir);
bool CheckRotationCollisions(cBlock* block);
bool CheckRotationCollisions(cBlock* block, Direction dir);
void CheckWin();
void CheckLoss();
void HandleBottomCollision();
Expand Down Expand Up @@ -236,11 +236,25 @@ void HandleGameInput()
u32 kUp = hidKeysUp();
if(!paused)
{
if(kDown & KEY_L)
{
if (!CheckRotationCollisions(g_FocusBlock, LEFT))
{
g_FocusBlock->Rotate(LEFT);
}
}
if(kDown & KEY_R)
{
if (!CheckRotationCollisions(g_FocusBlock, RIGHT))
{
g_FocusBlock->Rotate(RIGHT);
}
}
if(kDown & KEY_UP)
{
if (!CheckRotationCollisions(g_FocusBlock))
if (!CheckRotationCollisions(g_FocusBlock, RIGHT))
{
g_FocusBlock->Rotate();
g_FocusBlock->Rotate(RIGHT);
}
}
if(kDown & KEY_LEFT)
Expand Down Expand Up @@ -436,10 +450,10 @@ bool CheckWallCollisions(cBlock* block, Direction dir)
return false;
}

bool CheckRotationCollisions(cBlock* block)
bool CheckRotationCollisions(cBlock* block, Direction dir)
{
// Get an array of values for the locations of the rotated block's squares
int* temp_array = block->GetRotatedSquares();
int* temp_array = block->GetRotatedSquares(dir);

// Distance between two touching squares
int distance = SQUARE_MEDIAN * 2;
Expand Down

0 comments on commit 0c01ed2

Please sign in to comment.