Banjo API 1.1.0-alpha
Low-level C99 game development API
Loading...
Searching...
No Matches
maze.c File Reference
#include <banjo/app.h>
#include <banjo/bitmap.h>
#include <banjo/draw.h>
#include <banjo/event.h>
#include <banjo/log.h>
#include <banjo/main.h>
#include <banjo/maze.h>
#include <banjo/maze_builder.h>
#include <banjo/pixel.h>
#include <banjo/random.h>
#include <banjo/system.h>
#include <banjo/time.h>
#include <banjo/window.h>
Include dependency graph for maze.c:

Go to the source code of this file.

Macros

#define WINDOW_W   800
#define WINDOW_H   600
#define MAZE_CELL_PER_SIDE   15
#define MAZE_PIXEL_PER_CELL   5
#define MAZE_BMP_SIZE   (MAZE_CELL_PER_SIDE * MAZE_PIXEL_PER_CELL + (MAZE_CELL_PER_SIDE + 1))
#define MAZE_MARGIN   10
#define LABEL_H   32
#define LABEL_FONT_H   18
#define ANIMATION_HZ   30

Functions

static void draw_maze (bj_bitmap *target, const bj_maze *maze, const struct bj_maze_marks *marks)
static void on_draw (struct bj_window *w, struct bj_render_target *target, const struct bj_rect *dirty, void *user_data)
static struct bj_rect grid_rect_place (int n, int win_w, int win_h)
static void on_resize (struct bj_window *w, int width, int height, void *user_data)
static void regenerate (void)
static void on_key (struct bj_window *w, const struct bj_key_event *event, void *user_data)
static void * setup (struct bj_app *app, void *init_data)
static void step (struct bj_app *app, struct bj_tick_info tick, void *user_data)
static void teardown (struct bj_app *app, void *user_data)
int main (int argc, char *argv[])

Variables

bj_window * window = 0
static int window_w = 0
struct { 
const char * name
struct bj_maze_algorithm(* algorithm )(void)
bj_maze * maze
struct bj_maze_marks * marks
bj_maze_builder * builder
bj_bitmap * bitmap
bj_rect blit_dest
} mazes []
static const size_t n_mazes = sizeof(mazes) / sizeof(mazes[0])

Macro Definition Documentation

◆ ANIMATION_HZ

#define ANIMATION_HZ   30
Examples
maze.c.

Definition at line 124 of file maze.c.

Referenced by setup().

◆ LABEL_FONT_H

#define LABEL_FONT_H   18
Examples
maze.c.

Definition at line 120 of file maze.c.

Referenced by on_draw().

◆ LABEL_H

#define LABEL_H   32
Examples
maze.c.

Definition at line 119 of file maze.c.

Referenced by grid_rect_place(), and on_draw().

◆ MAZE_BMP_SIZE

#define MAZE_BMP_SIZE   (MAZE_CELL_PER_SIDE * MAZE_PIXEL_PER_CELL + (MAZE_CELL_PER_SIDE + 1))
Examples
maze.c.

Definition at line 116 of file maze.c.

Referenced by setup().

◆ MAZE_CELL_PER_SIDE

#define MAZE_CELL_PER_SIDE   15
Examples
maze.c.

Definition at line 111 of file maze.c.

Referenced by draw_maze(), and setup().

◆ MAZE_MARGIN

#define MAZE_MARGIN   10
Examples
maze.c.

Definition at line 118 of file maze.c.

Referenced by grid_rect_place(), and on_draw().

◆ MAZE_PIXEL_PER_CELL

#define MAZE_PIXEL_PER_CELL   5
Examples
maze.c.

Definition at line 115 of file maze.c.

Referenced by draw_maze().

◆ WINDOW_H

#define WINDOW_H   600

Definition at line 108 of file maze.c.

◆ WINDOW_W

#define WINDOW_W   800

Definition at line 107 of file maze.c.

Function Documentation

◆ draw_maze()

void draw_maze ( bj_bitmap * target,
const bj_maze * maze,
const struct bj_maze_marks * marks )
static
Examples
maze.c.

Definition at line 155 of file maze.c.

Referenced by regenerate(), and step().

◆ grid_rect_place()

struct bj_rect grid_rect_place ( int n,
int win_w,
int win_h )
static
Examples
maze.c.

Definition at line 279 of file maze.c.

Referenced by grid_rect_place(), and on_resize().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 408 of file maze.c.

◆ on_draw()

void on_draw ( struct bj_window * w,
struct bj_render_target * target,
const struct bj_rect * dirty,
void * user_data )
static

Definition at line 237 of file maze.c.

◆ on_key()

void on_key ( struct bj_window * w,
const struct bj_key_event * event,
void * user_data )
static
Examples
maze.c.

Definition at line 326 of file maze.c.

Referenced by setup().

◆ on_resize()

void on_resize ( struct bj_window * w,
int width,
int height,
void * user_data )
static
Examples
maze.c.

Definition at line 298 of file maze.c.

Referenced by setup().

◆ regenerate()

void regenerate ( void )
static
Examples
maze.c.

Definition at line 317 of file maze.c.

Referenced by on_key().

◆ setup()

void * setup ( struct bj_app * app,
void * init_data )
static

Definition at line 337 of file maze.c.

◆ step()

void step ( struct bj_app * app,
struct bj_tick_info tick,
void * user_data )
static

Definition at line 373 of file maze.c.

◆ teardown()

void teardown ( struct bj_app * app,
void * user_data )
static

Definition at line 394 of file maze.c.

Variable Documentation

◆ [struct]

struct { ... } mazes[]
Initial value:
= {
{.name = "B-Tree", .algorithm = bj_maze_algorithm_btree},
{.name = "Sidewinder", .algorithm = bj_maze_algorithm_sidewinder},
{.name = "Aldous-Broder", .algorithm = bj_maze_algorithm_aldous_broder},
{.name = "Wilson", .algorithm = bj_maze_algorithm_wilson},
{.name = "Hunt-and-Kill", .algorithm = bj_maze_algorithm_hunt_and_kill},
{.name = "Backtracker", .algorithm = bj_maze_algorithm_backtracker},
}
struct bj_maze_algorithm bj_maze_algorithm_wilson(void)
Wilson's algorithm.
struct bj_maze_algorithm bj_maze_algorithm_backtracker(void)
The backtracker, known in the literature as the recursive backtracker.
struct bj_maze_algorithm bj_maze_algorithm_sidewinder(void)
The sidewinder algorithm.
struct bj_maze_algorithm bj_maze_algorithm_hunt_and_kill(void)
The hunt-and-kill algorithm.
struct bj_maze_algorithm bj_maze_algorithm_btree(void)
The binary tree algorithm.
struct bj_maze_algorithm bj_maze_algorithm_aldous_broder(void)
The Aldous-Broder algorithm.
Examples
maze.c.

Referenced by on_draw(), on_resize(), regenerate(), setup(), step(), and teardown().

◆ n_mazes

const size_t n_mazes = sizeof(mazes) / sizeof(mazes[0])
static
Examples
maze.c.

Definition at line 151 of file maze.c.

Referenced by grid_rect_place(), on_draw(), on_resize(), regenerate(), setup(), step(), and teardown().

◆ window

bj_window* window = 0

Definition at line 126 of file maze.c.

◆ window_w

int window_w = 0
static
Examples
maze.c.

Definition at line 129 of file maze.c.

Referenced by on_draw(), and on_resize().