Skip to content
Permalink
Browse files

eating pills..but glitches

  • Loading branch information...
brovador committed Jul 22, 2015
1 parent aa62702 commit fba4ca70d64ffd743b27116e11a953db883fd547
Showing with 33 additions and 13 deletions.
  1. +33 −13 src/game.c
@@ -35,12 +35,13 @@ static unsigned char levelNamRef[1024];
#define SNAKE_SPRITE_SIZE 8
#define SNAKE_SPRITE 0x42
#define SNAKE_PALETTE 0
#define MAX_SNAKE_SIZE 20
#define MAX_SNAKE_SIZE 50
#define SnakeHead snakeCoords[0]

static unsigned char snakeCoords[MAX_SNAKE_SIZE][2];
static unsigned char snakeSpeed = 1;
static unsigned char snakeSpeed = 8;
static unsigned char snakeSize;
static unsigned char x, y;



@@ -56,19 +57,20 @@ static unsigned char pillsPositions[MAX_PILLS][2];

static unsigned char pad;
static unsigned char gameover;
static unsigned char i, j, k, x, y;
static unsigned char i, j, k, tmp, tmp2;
static unsigned char oamBuffer;
static unsigned char vFrameCount;

void reset()
{
vFrameCount = 0;
snakeSize = 1;
SnakeHead[0] = SCREEN_WIDTH >> 1;
SnakeHead[1] = SCREEN_HEIGHT >> 1;
x = snakeSpeed;
y = 0;
}


void main(void)
{
pal_spr(spritesPal);
@@ -89,6 +91,7 @@ void main(void)
{
ppu_wait_frame();
gameover = 0;
vFrameCount++;

pad = pad_trigger(0);
if (pad & PAD_LEFT) {
@@ -109,12 +112,8 @@ void main(void)
y = snakeSpeed;
}

//Move head
SnakeHead[0] = (SnakeHead[0] + x);
SnakeHead[1] = (SnakeHead[1] + y);




tmp2 = 0;
if (pillsLive == 0) {
pillsCreated = 0;
for (i = 0; i < MAX_PILLS; ++i) {
@@ -132,17 +131,38 @@ void main(void)
&& SnakeHead[1] > (pillsPositions[i][1] - SNAKE_SPRITE_SIZE)
&& SnakeHead[1] < (pillsPositions[i][1] + SNAKE_SPRITE_SIZE)
) {
//Eat pill
pillsPositions[i][0] = -1;
pillsPositions[i][1] = -1;
--pillsLive;

tmp2 = 1;
//Grow snake code
tmp = snakeSize;
++snakeSize;
snakeSize = (snakeSize > MAX_SNAKE_SIZE) ? MAX_SNAKE_SIZE : snakeSize;
if (snakeSize != tmp) {
snakeCoords[snakeSize - 1][0] = SnakeHead[0];
snakeCoords[snakeSize - 1][1] = SnakeHead[1];
SnakeHead[0] += x;
SnakeHead[1] += y;
}
}
}
}


//Move snake
if (vFrameCount > snakeSpeed && tmp2 == 0) {
vFrameCount = 0;
for (i = snakeSize - 1; i > 0; --i) {
snakeCoords[i][0] = snakeCoords[i-1][0];
snakeCoords[i][1] = snakeCoords[i-1][1];
}
SnakeHead[0] += x;
SnakeHead[1] += y;
}



//Check gameover
gameover = gameover || (SnakeHead[0] <= levelBoundaries[0]);
gameover = gameover || (SnakeHead[0] >= levelBoundaries[2]);
gameover = gameover || (SnakeHead[1] <= levelBoundaries[1]);

0 comments on commit fba4ca7

Please sign in to comment.
You can’t perform that action at this time.