Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
pong.c File Reference
#include <banjo/app.h>
#include <banjo/main.h>
#include <banjo/bitmap.h>
#include <banjo/draw.h>
#include <banjo/event.h>
#include <banjo/log.h>
#include <banjo/memory.h>
#include <banjo/rect.h>
#include <banjo/system.h>
#include <banjo/time.h>
#include <banjo/window.h>
Include dependency graph for pong.c:

Go to the source code of this file.

Data Structures

struct  pong_t

Macros

#define W   800
#define H   600
#define PAD_W   16
#define PAD_H   80
#define PAD_MARGIN   32
#define BALL_R   8
#define PAD_SPEED   360.0f /* pixels per second */
#define BALL_SPEED   280.0f /* pixels per second (initial) */
#define BOUNCE_SPEEDUP   1.05f /* paddle hit accelerates the ball */
#define MAX_DT   0.05f /* clamp delta to avoid teleporting */

Functions

static void reset_ball (pong_t *p, int last_winner)
static void update (pong_t *p, float dt)
static void draw (pong_t *p, bj_bitmap *fb)
static void on_draw (struct bj_window *window, struct bj_render_target *target, const struct bj_rect *dirty, 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[])

Data Structure Documentation

◆ pong_t

struct pong_t
Examples
pong.c.

Definition at line 127 of file pong.c.

Collaboration diagram for pong_t:
Data Fields
float ball_vx
float ball_vy
float ball_x
float ball_y
float pad_left_y
float pad_right_y
bj_stopwatch sw
bj_window * window

Macro Definition Documentation

◆ BALL_R

#define BALL_R   8

Definition at line 121 of file pong.c.

◆ BALL_SPEED

#define BALL_SPEED   280.0f /* pixels per second (initial) */
Examples
pong.c.

Definition at line 123 of file pong.c.

Referenced by reset_ball().

◆ BOUNCE_SPEEDUP

#define BOUNCE_SPEEDUP   1.05f /* paddle hit accelerates the ball */
Examples
pong.c.

Definition at line 124 of file pong.c.

Referenced by update().

◆ H

#define H   600
Examples
pong.c.

Definition at line 117 of file pong.c.

Referenced by draw(), reset_ball(), setup(), and update().

◆ MAX_DT

#define MAX_DT   0.05f /* clamp delta to avoid teleporting */
Examples
pong.c.

Definition at line 125 of file pong.c.

Referenced by step().

◆ PAD_H

#define PAD_H   80
Examples
pong.c.

Definition at line 119 of file pong.c.

Referenced by draw(), setup(), and update().

◆ PAD_MARGIN

#define PAD_MARGIN   32
Examples
pong.c.

Definition at line 120 of file pong.c.

Referenced by draw(), and update().

◆ PAD_SPEED

#define PAD_SPEED   360.0f /* pixels per second */
Examples
pong.c.

Definition at line 122 of file pong.c.

Referenced by update().

◆ PAD_W

#define PAD_W   16
Examples
pong.c.

Definition at line 118 of file pong.c.

Referenced by draw(), and update().

◆ W

#define W   800
Examples
pong.c, and random_distribution.c.

Definition at line 116 of file pong.c.

Referenced by draw(), draw(), reset_ball(), setup(), and update().

Function Documentation

◆ draw()

void draw ( pong_t * p,
bj_bitmap * fb )
static

Definition at line 197 of file pong.c.

◆ main()

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

Definition at line 277 of file pong.c.

◆ on_draw()

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

Definition at line 221 of file pong.c.

◆ reset_ball()

void reset_ball ( pong_t * p,
int last_winner )
static

Definition at line 137 of file pong.c.

◆ setup()

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

Definition at line 231 of file pong.c.

◆ step()

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

Definition at line 253 of file pong.c.

◆ teardown()

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

Definition at line 269 of file pong.c.

◆ update()

void update ( pong_t * p,
float dt )
static

Definition at line 145 of file pong.c.