82 lines
No EOL
976 B
C
82 lines
No EOL
976 B
C
#include "snake.h"
|
|
|
|
static Body snake[40] = {{0, 0}, 0};
|
|
static unsigned char len = 0;
|
|
void snake_init()
|
|
{
|
|
snake[len].d.x = 63;
|
|
snake[len].d.y = 31;
|
|
snake[len].m = R;
|
|
len++;
|
|
}
|
|
|
|
void body_move(Body b)
|
|
{
|
|
switch(b.m)
|
|
{
|
|
case R:
|
|
b.d.x++;
|
|
break;
|
|
|
|
case L:
|
|
b.d.x--;
|
|
break;
|
|
|
|
case U:
|
|
b.d.y--;
|
|
break;
|
|
|
|
case D:
|
|
b.d.y++;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void snake_move()
|
|
{
|
|
int i = 0;
|
|
for(; i <= len; i++)
|
|
{
|
|
body_move(snake[i]);
|
|
}
|
|
for(i = 1; i <= len; i++)
|
|
{
|
|
snake[i].m = snake[i - 1].m;
|
|
}
|
|
|
|
}
|
|
|
|
void body_add()
|
|
{
|
|
len++
|
|
snake[len].m = snake[len - 1].m;
|
|
snake[len].d.x = snake[len - 1].d.x;
|
|
snake[len].d.x = snake[len - 1].d.x;
|
|
switch(snake[len].m)
|
|
{
|
|
case R:
|
|
snake[len].d.x--;
|
|
break;
|
|
|
|
case L:
|
|
snake[len].d.x++;
|
|
break;
|
|
|
|
case U:
|
|
snake[len].d.y++;
|
|
break;
|
|
|
|
case D:
|
|
snake[len].d.y--;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void test()
|
|
{
|
|
int i = 0;
|
|
for(; i < 15; i++)
|
|
body_add();
|
|
|
|
} |