increase snake size
This commit is contained in:
@@ -8,8 +8,8 @@ byte frame[8][12] = {
|
|||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||||
@@ -22,19 +22,25 @@ const uint32_t game_over[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// snake initial coordinates
|
// snake initial coordinates
|
||||||
int snake_x[4]= {4, 3, 2, 1};
|
int snake_x[96]= {4, 3, 2, 1};
|
||||||
int snake_y[4]= {3, 3, 3, 3};
|
int snake_y[96]= {3, 3, 3, 3};
|
||||||
int snake_len= 4;
|
int snake_len= 4;
|
||||||
|
//int *snake_x;
|
||||||
|
//int *snake_y;
|
||||||
|
//snake_x= (int *)malloc(snake_len * sizeof(int));
|
||||||
|
//snake_y= (int *)malloc(snake_len * sizeof(int));
|
||||||
|
|
||||||
char direction= 'r';
|
char direction= 'r';
|
||||||
|
|
||||||
int points= 0;
|
int points= 0;
|
||||||
|
|
||||||
// apple initial position
|
// apple initial position
|
||||||
int apple_x= 9;
|
int apple_x= 9;
|
||||||
int apple_y= 4;
|
int apple_y= 3;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
//Serial.begin(115200);
|
||||||
|
Serial.begin(9600);
|
||||||
// stard LED matrix
|
// stard LED matrix
|
||||||
matrix.begin();
|
matrix.begin();
|
||||||
// btn up
|
// btn up
|
||||||
@@ -47,6 +53,12 @@ void setup() {
|
|||||||
pinMode(10, INPUT);
|
pinMode(10, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_tail_block() {
|
||||||
|
snake_len++;
|
||||||
|
snake_y[snake_len-1]= snake_y[snake_len-2];
|
||||||
|
snake_x[snake_len-1]= snake_x[snake_len-2];
|
||||||
|
}
|
||||||
|
|
||||||
void eat_apple() {
|
void eat_apple() {
|
||||||
points++;
|
points++;
|
||||||
//XXX new apple coordinates
|
//XXX new apple coordinates
|
||||||
@@ -54,6 +66,8 @@ void eat_apple() {
|
|||||||
apple_x= random(11);
|
apple_x= random(11);
|
||||||
apple_y= random(7);
|
apple_y= random(7);
|
||||||
frame[apple_y][apple_x]= 1;
|
frame[apple_y][apple_x]= 1;
|
||||||
|
|
||||||
|
add_tail_block();
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_snake() {
|
void move_snake() {
|
||||||
@@ -119,6 +133,7 @@ void change_direction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
Serial.println(points);
|
||||||
change_direction();
|
change_direction();
|
||||||
matrix.renderBitmap(frame, 8, 12);
|
matrix.renderBitmap(frame, 8, 12);
|
||||||
delay(300);
|
delay(300);
|
||||||
@@ -126,6 +141,7 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
// XXX to remove, test only
|
// XXX to remove, test only
|
||||||
direction= 'b';
|
//direction= 'b';
|
||||||
eat_apple();
|
//eat_apple();
|
||||||
|
//add_tail_block();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user