Initial Commit
This commit is contained in:
commit
5314a9d5c5
308 changed files with 190647 additions and 0 deletions
11
include/debug.h
Normal file
11
include/debug.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef __DEBUG_H
|
||||
#define __DEBUG_H
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
#define debug_printf(fmt, ...) \
|
||||
printf((fmt) __VA_OPT__(,) __VA_ARGS__)
|
||||
#else
|
||||
#define debug_printf(fmt, ...)
|
||||
#endif
|
||||
|
||||
#endif /* !__DEBUG_H */
|
||||
18
include/game.h
Normal file
18
include/game.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __GAME_H
|
||||
#define __GAME_H
|
||||
|
||||
void game_init();
|
||||
|
||||
// shape
|
||||
void game_spawn_shape();
|
||||
void game_place_shape();
|
||||
void game_rotate_shape();
|
||||
void game_move_shape(int direction);
|
||||
int game_move_shape_down();
|
||||
void game_reset_shape();
|
||||
|
||||
void game_render();
|
||||
|
||||
int game_is_done();
|
||||
|
||||
#endif /* !__GAME_H */
|
||||
25
include/grid.h
Normal file
25
include/grid.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __GRID_H
|
||||
#define __GRID_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define GRID_WIDTH 10
|
||||
#define GRID_HEIGHT 16
|
||||
|
||||
#define grid_cell(grid, x, y) ((grid)[(x) + ((y) * GRID_WIDTH)])
|
||||
|
||||
typedef uint8_t grid_t[GRID_HEIGHT * GRID_WIDTH];
|
||||
|
||||
void grid_init(grid_t grid);
|
||||
|
||||
int grid_check_collision(grid_t grid, int8_t x, int8_t y);
|
||||
|
||||
// clears all full rows on the board.
|
||||
// Returns the number of rows cleared.
|
||||
uint32_t grid_clear_full_rows(grid_t grid);
|
||||
|
||||
// Clears the row and moves all rows above down one step.
|
||||
void grid_clear_row(grid_t grid, uint8_t row);
|
||||
|
||||
#endif /* __GRID_H */
|
||||
25
include/input.h
Normal file
25
include/input.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __INPUT_H
|
||||
#define __INPUT_H
|
||||
|
||||
typedef enum {
|
||||
ACTION_ROTATE,
|
||||
ACTION_MOVE_LEFT,
|
||||
ACTION_MOVE_RIGHT,
|
||||
ACTION_DROP,
|
||||
ACTION_QUIT,
|
||||
} action_t;
|
||||
|
||||
#define NUM_ACTIONS 5
|
||||
|
||||
void input_init();
|
||||
|
||||
void input_update();
|
||||
|
||||
// check if an action is triggered repeatedly.
|
||||
int input_repeat(action_t action);
|
||||
|
||||
// check if an action is triggered once.
|
||||
// eg. If a key was pressed.
|
||||
int input_once(action_t action);
|
||||
|
||||
#endif /* !__INPUT_H */
|
||||
29
include/render.h
Normal file
29
include/render.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef __RENDER_H
|
||||
#define __RENDER_H
|
||||
|
||||
#include "grid.h"
|
||||
#include "shape.h"
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int render_init(SDL_Window *window);
|
||||
|
||||
void render_shutdown();
|
||||
|
||||
void render_board(const grid_t board);
|
||||
|
||||
void render_board_border();
|
||||
|
||||
void render_shape(const shape_t *shape, uint8_t x, uint8_t y);
|
||||
|
||||
void render_next_shape(const shape_t *shape);
|
||||
|
||||
void render_score(uint32_t score);
|
||||
|
||||
void render_game_over_text();
|
||||
|
||||
void render_clear();
|
||||
|
||||
void render_present();
|
||||
|
||||
#endif /* __RENDER_H */
|
||||
14
include/render/text.h
Normal file
14
include/render/text.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef __RENDER_TEXT_H
|
||||
#define __RENDER_TEXT_H
|
||||
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int text_init(SDL_Renderer *renderer);
|
||||
|
||||
void text_shutdown();
|
||||
|
||||
int text_render(const char *text, size_t len, float x, float y);
|
||||
|
||||
#endif // !__RENDER_TEXT_H
|
||||
|
||||
24
include/render/tile.h
Normal file
24
include/render/tile.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef __RENDER_TILE_H
|
||||
#define __RENDER_TILE_H
|
||||
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
TILE_GRAY,
|
||||
TILE_BLUE,
|
||||
TILE_LIGHTBLUE,
|
||||
TILE_RED,
|
||||
TILE_GREEN,
|
||||
TILE_YELLOW,
|
||||
TILE_ORANGE,
|
||||
TILE_MAGENTA,
|
||||
} tile_t;
|
||||
|
||||
int tile_init(SDL_Renderer *renderer);
|
||||
|
||||
void tile_shutdown();
|
||||
|
||||
void tile_render(SDL_Renderer *renderer, const SDL_FRect* rect, tile_t tile_index);
|
||||
|
||||
#endif // __RENDER_TILE_H
|
||||
31
include/shape.h
Normal file
31
include/shape.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef __SHAPE_H
|
||||
#define __SHAPE_H
|
||||
|
||||
#include "render/tile.h"
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define NUM_SHAPES 7
|
||||
|
||||
typedef enum {
|
||||
SHAPE_O,
|
||||
SHAPE_L,
|
||||
SHAPE_J,
|
||||
SHAPE_T,
|
||||
SHAPE_Z,
|
||||
SHAPE_S,
|
||||
SHAPE_I,
|
||||
} SHAPETYPE;
|
||||
|
||||
typedef struct _shape {
|
||||
uint8_t type;
|
||||
int8_t coordinates[6];
|
||||
} shape_t;
|
||||
|
||||
void shape_create(shape_t* shape, SHAPETYPE type);
|
||||
|
||||
void shape_copy(shape_t* dest, const shape_t* src);
|
||||
|
||||
tile_t shape_color(const shape_t* shape);
|
||||
|
||||
#endif /* __SHAPE_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue