Skip to content

Commit ae3c208

Browse files
beauty changes of game
1 parent b9078b6 commit ae3c208

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

StackAttack/StackAttack/sketch_dec02a/sketch_dec02a.ino

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public:
2222
class StackAttack
2323
{
2424
private:
25-
static const uint8_t rows = 7;
26-
static const uint8_t cols = 12;
25+
static const uint8_t rows = 9;
26+
static const uint8_t cols = 14;
2727
bool gameover = false;
2828
uint8_t _isPlaying = 0;
2929
//settings
@@ -220,6 +220,7 @@ public:
220220

221221
LCD.print("Score:",0,16);
222222
LCD.printNumI(score,40,16);
223+
score = 0;
223224
LCD.print("Press Any Key",0,24);
224225
LCD.print("To Continue",0,32);
225226
LCD.update();
@@ -472,9 +473,9 @@ public:
472473
delay(gameSpeed);
473474
} while (Update());
474475
LCD.clrScr();
475-
476476
GameOver();
477477

478+
478479
}
479480
//call menu
480481
int ShowMenu()
@@ -568,12 +569,12 @@ public:
568569
{
569570
//change size from 1 to 3
570571
if(digitalRead(RIGHT_pin)==LOW)
571-
if(size == 3)
572-
size = 1;
572+
if(size == 5)
573+
size = 3;
573574
else size++;
574575
else if(digitalRead(LEFT_pin)==LOW)
575-
if(size == 1)
576-
size = 3;
576+
if(size == 3)
577+
size = 5;
577578
else size--;
578579
EEPROM.put(0, size);
579580
}
@@ -652,10 +653,17 @@ void Falling(){
652653
// initilize scene grid with empty space
653654
for (int i = 0; i < rows; ++i)
654655
for (int j = 0; j < cols; ++j)
655-
sceneGrid[i][j] = '*';
656+
if (i == 0 || i == rows - 1 || j == 0 || j == cols - 1)
657+
{
658+
sceneGrid[i][j] = '#';
659+
}
660+
else
661+
{
662+
sceneGrid[i][j] = '*';
663+
}
656664

657665
// spawn play & align it vertically & horizontally (imperfect as grid width is not even)
658-
player = { 6, 6 };
666+
player = { 7, 6 };
659667

660668
// draw player renders
661669
// sceneGrid[6][6] = '%';
@@ -673,15 +681,32 @@ void Falling(){
673681
//rendering only player
674682
void Render()
675683
{
684+
LCD.printNumI(score,72,0);
676685
for (int i = 0; i < rows; i++)
677686
{
678687
for (int j = 0; j < cols; j++)
679688
{
680689

681-
if (sceneGrid[i][j] != '*' || (player.x - 1 == i && player.y == j) ||
690+
if (sceneGrid[i][j] != '*')
691+
{
692+
if((i==0) ||(i== rows-1) || (j==0) || (j==cols-1))
693+
{
694+
for (uint8_t _i = 0; _i < size; ++_i)
695+
for (uint8_t _j = 0; _j < size; ++_j)
696+
if((_i==0) ||(_i== size-1) || (_j==0) || (_j==size-1) ||(_i == _j))
697+
LCD.setPixel(size*j+_j,size*i+_i);
698+
}
699+
else
700+
Print(i,j);
701+
}
702+
else if((player.x - 1 == i && player.y == j) ||
682703
(player.x == i && player.y == j))
683704
{
684-
Print(i,j);
705+
//Print(i,j);
706+
for (uint8_t _i = 0; _i < size; ++_i)
707+
for (uint8_t _j = 0; _j < size; ++_j)
708+
if((_i==0) ||(_i== size-1) || (_j==0) || (_j==size-1))
709+
LCD.setPixel(size*j+_j,size*i+_i);
685710
}
686711
//else
687712
// std::cout << sceneGrid[i][j];
@@ -696,8 +721,8 @@ void Falling(){
696721
void block_rand()
697722
{
698723

699-
int y = rand() % cols;
700-
sceneGrid[0][y] = '#';
724+
int y = rand() % cols - 2;
725+
sceneGrid[1][y + 1] = '#';
701726
}
702727

703728

@@ -712,7 +737,7 @@ void Falling(){
712737
if (player.x - 1 == 0 || player.x - 1 == 1) // if player on top 2 lines he dies
713738
return false;
714739

715-
for (int i = rows - 2; i > -1; --i)
740+
for (int i = rows - 2; i > 0; --i)
716741
{
717742
for (int j = cols - 1; j > -1; --j)
718743
{
@@ -741,16 +766,16 @@ void Falling(){
741766
bool canDelete = true;
742767
for (int i = 0; i < cols; ++i)
743768
{
744-
if (sceneGrid[rows - 1][i] != '#')
769+
if (sceneGrid[rows - 2][i] != '#')
745770
{
746771
canDelete = false;
747772
break;
748773
}
749774
}
750775

751776
if (canDelete) {
752-
for (int i = 0; i < cols; ++i)
753-
sceneGrid[rows - 1][i] = '*';
777+
for (int i = 1; i < cols - 1; ++i)
778+
sceneGrid[rows - 2][i] = '*';
754779
score++;
755780
}
756781
}

0 commit comments

Comments
 (0)