Nimbin[12]?Embedded / snake_compiler / snake_SDL/src/snake.h

snake_compiler git · main

Snake compiled to a bare-metal RISC-V microcontroller

riscv embedded bare-metal c snake · first commit 2026-01-18 · last commit 2026-01-18 (8 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/compilerbau/snake_compiler

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.gz
snake_SDL/src/snake.h 832 B · 48 lines 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