Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 241 → Rev 242

/PIC Stuff/Cerebot_32MX7_LED_Cube/SNAKE.c
3,6 → 3,7
#include "SNAKE.h"
 
static SNAKE_DATA *data_p;
static uint32_t rand_value __attribute__((persistent));
 
void Snake_Init(SNAKE_DATA *data) {
data_p = data;
16,6 → 17,8
data_p->level = 1;
data_p->delay = 800;
 
srand(rand_value);
 
// Generate a starting location for the candy
data_p->candy_loc = Snake_Generate_Candy();
 
35,6 → 38,9
// Main function, loops and delays while updating the frame every x milliseconds
Delay_MS(2000);
while (1) {
// Regenerate the seed upon each update so that the candy starts somewhere new every time
rand_value = rand();
Snake_Update_Frame();
Delay_MS(data_p->delay);
}
90,8 → 96,10
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);
Cube_Set_Pixel(data_p->direction.z, data_p->direction.x, data_p->direction.y, SNAKE_COLLISION_COLOR);
Delay_MS(3000);
Cube_Overlay_Clear();
Animation_Cube_In_Out(200, ORANGE);
Reset_Board(BOARD_MODE_IDLE);
}
pos = (pos == CUBE_PIXELS - 1) ? 0 : pos + 1;