@@ -22,8 +22,8 @@ public:
22
22
class StackAttack
23
23
{
24
24
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 ;
27
27
bool gameover = false ;
28
28
uint8_t _isPlaying = 0 ;
29
29
// settings
@@ -220,6 +220,7 @@ public:
220
220
221
221
LCD.print (" Score:" ,0 ,16 );
222
222
LCD.printNumI (score,40 ,16 );
223
+ score = 0 ;
223
224
LCD.print (" Press Any Key" ,0 ,24 );
224
225
LCD.print (" To Continue" ,0 ,32 );
225
226
LCD.update ();
@@ -472,9 +473,9 @@ public:
472
473
delay (gameSpeed);
473
474
} while (Update ());
474
475
LCD.clrScr ();
475
-
476
476
GameOver ();
477
477
478
+
478
479
}
479
480
// call menu
480
481
int ShowMenu ()
@@ -568,12 +569,12 @@ public:
568
569
{
569
570
// change size from 1 to 3
570
571
if (digitalRead (RIGHT_pin)==LOW)
571
- if (size == 3 )
572
- size = 1 ;
572
+ if (size == 5 )
573
+ size = 3 ;
573
574
else size++;
574
575
else if (digitalRead (LEFT_pin)==LOW)
575
- if (size == 1 )
576
- size = 3 ;
576
+ if (size == 3 )
577
+ size = 5 ;
577
578
else size--;
578
579
EEPROM.put (0 , size);
579
580
}
@@ -652,10 +653,17 @@ void Falling(){
652
653
// initilize scene grid with empty space
653
654
for (int i = 0 ; i < rows; ++i)
654
655
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
+ }
656
664
657
665
// spawn play & align it vertically & horizontally (imperfect as grid width is not even)
658
- player = { 6 , 6 };
666
+ player = { 7 , 6 };
659
667
660
668
// draw player renders
661
669
// sceneGrid[6][6] = '%';
@@ -673,15 +681,32 @@ void Falling(){
673
681
// rendering only player
674
682
void Render ()
675
683
{
684
+ LCD.printNumI (score,72 ,0 );
676
685
for (int i = 0 ; i < rows; i++)
677
686
{
678
687
for (int j = 0 ; j < cols; j++)
679
688
{
680
689
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) ||
682
703
(player.x == i && player.y == j))
683
704
{
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);
685
710
}
686
711
// else
687
712
// std::cout << sceneGrid[i][j];
@@ -696,8 +721,8 @@ void Falling(){
696
721
void block_rand ()
697
722
{
698
723
699
- int y = rand () % cols;
700
- sceneGrid[0 ][y] = ' #' ;
724
+ int y = rand () % cols - 2 ;
725
+ sceneGrid[1 ][y + 1 ] = ' #' ;
701
726
}
702
727
703
728
@@ -712,7 +737,7 @@ void Falling(){
712
737
if (player.x - 1 == 0 || player.x - 1 == 1 ) // if player on top 2 lines he dies
713
738
return false ;
714
739
715
- for (int i = rows - 2 ; i > - 1 ; --i)
740
+ for (int i = rows - 2 ; i > 0 ; --i)
716
741
{
717
742
for (int j = cols - 1 ; j > -1 ; --j)
718
743
{
@@ -741,16 +766,16 @@ void Falling(){
741
766
bool canDelete = true ;
742
767
for (int i = 0 ; i < cols; ++i)
743
768
{
744
- if (sceneGrid[rows - 1 ][i] != ' #' )
769
+ if (sceneGrid[rows - 2 ][i] != ' #' )
745
770
{
746
771
canDelete = false ;
747
772
break ;
748
773
}
749
774
}
750
775
751
776
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] = ' *' ;
754
779
score++;
755
780
}
756
781
}
0 commit comments