You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB
C

#pragma once
#include <SDL2/SDL.h>
// Convenience: also get many stdlibs, so that we do not need to care in the program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
typedef unsigned char byte;
typedef struct color {
byte r;
byte g;
byte b;
} color_t;
/* These are mutable, so that it is easy to change them from the code, before runing init() */
int TILE_SIZE = 5;
int GRID_HEIGHT = 20;
int GRID_WIDTH = 20;
color_t ** grid;
/* We wrap SDL as a whole, so this is our API. */
void init(void);
void redraw(void);
void wait(int msec); // Not a regular usleep, since we want SDL to still get inputs
char **getkeys(int count); // Get up to `count` keys pressed since last call. These are strings like 'a', 'shift', 'up', &c.
// We only report keydowns, and we report them in order they were pressed.
/* low-level Grid API */
void grid_set(int x, int y, color_t color);
color_t grid_get(int x, int y);
// Of course, this is fourth quadrant, i.e. the origin is top left corner.
/* I thought of providing a growing array here, but my implementation is too
* ugly (e.g. too many void pointers). Use reallocarray(3) instead, or just a
* regular array big enough. */