adding menu and game support
This commit is contained in:
parent
8c33123de1
commit
ce5ac2ef9a
18 changed files with 480 additions and 190 deletions
|
|
@ -128,122 +128,3 @@ void snake(){
|
|||
}
|
||||
}
|
||||
|
||||
void snake_game() {
|
||||
pixel pixels[64] = {{4, 14},{4, 13}};
|
||||
pixel * head = &pixels[1];
|
||||
pixel * tail = &pixels[0];
|
||||
pixel old_head;
|
||||
pixel apples[10];
|
||||
uint8_t joy, joy_old=0xff, joy_cmd=0xff;
|
||||
|
||||
unsigned char x, y, dead = 0;
|
||||
unsigned char apple_num = 0;
|
||||
direction dir = up;
|
||||
|
||||
unsigned char apple_found = 0;
|
||||
unsigned char j;
|
||||
|
||||
clear_screen(0);
|
||||
|
||||
// zeichne Rahmen
|
||||
for (x = 0; x < NUM_COLS; x++) {
|
||||
for (y = 0; y < NUM_ROWS; y++) {
|
||||
if (((x == 0) || (x == NUM_COLS-1)) ||
|
||||
((y == 0) || (y == NUM_ROWS-1))) {
|
||||
setpixel((pixel) {x, y}, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
while (1) {
|
||||
|
||||
x++;
|
||||
old_head = *head;
|
||||
++head;
|
||||
if (head == pixels + 64)
|
||||
head = pixels;
|
||||
|
||||
if (joy_cmd == right) {
|
||||
dir = direction_r(dir);
|
||||
joy_cmd = 0xff;
|
||||
} else if (joy_cmd == left) {
|
||||
dir = direction_r(dir);
|
||||
dir = direction_r(dir);
|
||||
dir = direction_r(dir);
|
||||
joy_cmd = 0xff;
|
||||
}
|
||||
|
||||
// kopf einen weiter bewegen
|
||||
*head = next_pixel(old_head, dir);
|
||||
|
||||
apple_found = 0;
|
||||
|
||||
// prfen ob man auf nen Apfel drauf ist
|
||||
for (j = 0; j < apple_num; j++) {
|
||||
if ( ( head->x == apples[j].x) &&
|
||||
(head->y == apples[j].y) ){
|
||||
apple_found = 1;
|
||||
for(; j < apple_num - 1; j++) {
|
||||
apples[j] = apples[j+1];
|
||||
}
|
||||
apple_num--;
|
||||
goto apple_se;
|
||||
}
|
||||
}
|
||||
if (get_pixel(*head)) {
|
||||
dead = 1;
|
||||
}
|
||||
apple_se:
|
||||
|
||||
if (!dead) {
|
||||
setpixel(*head, 3);
|
||||
|
||||
// setze neue pfel
|
||||
if ( (apple_num < 9) && (random8() < 10) ) {
|
||||
pixel new_apple = (pixel) {(random8() % (NUM_COLS-2))+1,
|
||||
(random8() % (NUM_ROWS-2))+1};
|
||||
if (!get_pixel(new_apple)){
|
||||
apples[apple_num++] = new_apple;
|
||||
}
|
||||
}
|
||||
// lsche Ende
|
||||
if (!apple_found && !dead) {
|
||||
clearpixel(*tail);
|
||||
if (++tail == pixels + 64)
|
||||
tail = pixels;
|
||||
}
|
||||
} else {
|
||||
while (tail != head) {
|
||||
clearpixel(*tail);
|
||||
if ((++tail) > pixels + 64)
|
||||
tail = pixels;
|
||||
wait (60);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (j = 0; j < apple_num; j++) {
|
||||
if (x % 2) {
|
||||
setpixel(apples[j], 3);
|
||||
} else {
|
||||
clearpixel(apples[j]);
|
||||
}
|
||||
}
|
||||
for(j=0;j<20;j++){
|
||||
if(JOYISLEFT){
|
||||
joy = left;
|
||||
}else if(JOYISRIGHT){
|
||||
joy = right;
|
||||
}else{
|
||||
joy = 0xff;
|
||||
}
|
||||
if(joy != joy_old){
|
||||
joy_cmd = joy;
|
||||
}
|
||||
joy_old = joy;
|
||||
wait (5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue