Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 240 → Rev 241

/PIC Stuff/Cerebot_32MX7_LED_Cube/SNAKE.c
7,13 → 7,8
void Snake_Init(SNAKE_DATA *data) {
data_p = data;
 
// Disable watchdog timer
WDTCON = 0x00000000;
 
// Set starting point
data_p->body[0].x = 0;
data_p->body[0].y = 0;
data_p->body[0].z = 0;
data_p->body[0] = (SNAKE_POINT){0,0,7};
 
data_p->pos_head = 0;
data_p->pos_tail = 0;
37,6 → 32,7
}
 
void Snake_Main(void) {
// Main function, loops and delays while updating the frame every x milliseconds
Delay_MS(2000);
while (1) {
Snake_Update_Frame();
93,6 → 89,7
if (data_p->direction.x == data_p->body[pos].x &&
data_p->direction.y == data_p->body[pos].y &&
data_p->direction.z == data_p->body[pos].z) {
// Indicate the overlapping pixel, delay, then return to idle state
Cube_Overlay_Set_Pixel(data_p->direction.z, data_p->direction.x, data_p->direction.y, SNAKE_HEAD_COLOR);
Delay_MS(3000);
Reset_Board(BOARD_MODE_IDLE);
123,12 → 120,16
 
// If we ate a candy, delay for a bit to rest
if (om_nom_nom) {
data_p->level += 1; // Increase the level by one
// Increase the level by one, show on controller if necessary
data_p->level += 1;
if (data_p->level % SNAKE_LEVEL_STEP == 0) {
uint8_t tier = data_p->level / SNAKE_LEVEL_STEP;
Controller_Set_Leds(tier, tier);
}
data_p->delay -= 5; // Decrease the delay between frame updates by 5ms
// Decrease the delay between frame updates by 5ms
data_p->delay -= 5;
// Clear the watchdog timer to prevent resets in a middle of a game
ClearWDT();
}
}