snake_compiler git · main
Snake compiled to a bare-metal RISC-V microcontroller
C 95.2% Markdown 3.3%git clone https://git.christianimmanuel.de/embedded/snake_compiler.gitwget https://git.christianimmanuel.de/embedded/snake_compiler/archive/snake_compiler.tar.gzsnake_SDL/src/snake.h raw
#ifndef SNAKE_H
#define SNAKE_H
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include "defaults.h"
typedef struct {
unsigned char g;
unsigned char r;
unsigned char b;
} Color;
typedef enum {
DIR_UP,
DIR_DOWN,
DIR_LEFT,
DIR_RIGHT
} Direction;
typedef struct {
int x;
int y;
Color color;
Color color_old;
} SnakeTile;
typedef struct {
SnakeTile nodes[MAX_SNAKE_LENGTH];
int head_index;
int tail_index;
Direction direction;
int length;
} Snake;
// Function declarations
void snake_Init(Snake* snake, int start_x, int start_y);
void snake_SetDirection(Snake* snake, Direction new_dir);
bool snake_Move(Snake* snake, bool is_next_step, uint64_t diff_max, uint64_t diff);
bool snake_IsColliding(Snake* snake);
void spawn_apple();
#endif // SNAKE_H