6#define EXTERNC extern "C"
13#include "machineDependent.h"
27 DEFAULT_COLOR = LIGHT1,
40 SOUND_EFFECT_TYPE_COUNT,
41 BGM = SOUND_EFFECT_TYPE_COUNT,
44#define CHARACTER_WIDTH 6
45#define CHARACTER_HEIGHT 6
47#define TEXT_PATTERN_COUNT 94
48#define MAX_CHARACTER_PATTERN_COUNT 26
50#define HIT_BOX_INDEX_COLOR_BASE 0
51#define HIT_BOX_INDEX_TEXT_BASE (HIT_BOX_INDEX_COLOR_BASE + COLOR_COUNT)
52#define HIT_BOX_INDEX_CHARACTER_BASE (HIT_BOX_INDEX_TEXT_BASE + TEXT_PATTERN_COUNT)
55#define M_PI 3.14159265358979323846
67 uint8_t grid[CHARACTER_WIDTH];
72 uint16_t isColliding[8];
76EXTERNC uint16_t
ticks;
88EXTERNC
Collision box(
float x,
float y,
float w,
float h);
89EXTERNC
Collision line(
float x1,
float y1,
float x2,
float y2);
90EXTERNC
Collision bar(
float x,
float y,
float length,
float angle);
91EXTERNC
Collision arc(
float centerX,
float centerY,
float radius,
92 float angleFrom,
float angleTo);
96EXTERNC
void play(uint8_t type);
97EXTERNC
void addScore(
float value,
float x,
float y);
98EXTERNC
float rnd(
float high,
float low);
99EXTERNC int16_t
rndi(int16_t high, int16_t low);
101EXTERNC
void particle(
float x,
float y,
float count,
float speed,
float angle,
103EXTERNC
bool btn(uint8_t button);
104EXTERNC
bool btnp(uint8_t button);
105EXTERNC
bool btnr(uint8_t button);
107EXTERNC
float clamp(
float v,
float low,
float high);
108EXTERNC
float wrap(
float v,
float low,
float high);
113EXTERNC
void setupGame(
const char *title,
const char *description,
115 void (*update)(
void));
121#define FOR_EACH(array, index) \
122 for (uint8_t index = 0; index < sizeof(array) / sizeof(array[0]); index++)
124#define ASSIGN_ARRAY_ITEM(array, index, type, item) type *item = &array[index]
126#define SKIP_IS_NOT_ALIVE(item) \
127 if (!item->isAlive) continue
129#define TIMES(count, index) for (uint8_t index = 0; index < count; index++)
132#define COUNT_IS_ALIVE(array, counter) \
133 uint8_t counter = 0; \
135 for (uint8_t i = 0; i < sizeof(array) / sizeof(array[0]); i++) { \
136 if (array[i].isAlive) { \
142#define INIT_UNALIVED_ARRAY(array) \
144 for (uint8_t i = 0; i < sizeof(array) / sizeof(array[0]); i++) { \
145 array[i].isAlive = false; \
149#define RNDPM() (rndi(0, 2) * 2 - 1)
Collision line(float x1, float y1, float x2, float y2)
Draw a line. Returns information on objects that collided while drawing.
Definition: cglab.c:197
bool updateGame(void)
Update game frames if it's every 1/60 second timing.
Definition: cglab.c:736
void particle(float x, float y, float count, float speed, float angle, float angleWidth)
Add particles.
Definition: cglab.c:515
float difficulty
Definition: cglab.c:21
void initGame(void)
Initialize game.
Definition: cglab.c:724
float clamp(float v, float low, float high)
Clamp a value to [low, high].
Definition: cglab.c:554
float barCenterPosRatio
Definition: cglab.c:31
bool colCharacter(Collision *cl, char character)
Whether it's colliding with characters.
Definition: cglab.c:109
float wrap(float v, float low, float high)
Wrap a value to [low, high).
Definition: cglab.c:559
int8_t color
Definition: cglab.c:26
Collision character(char character, float x, float y)
Definition: cglab.c:344
bool btn(uint8_t button)
Whether the button is being pressed. Button are INPUT_*.
Definition: cglab.c:530
uint16_t ticks
A variable incremented by one every 1/60 of a second (readonly).
Definition: cglab.c:16
void play(uint8_t type)
Definition: cglab.c:378
bool colText(Collision *cl, char text)
Whether it's colliding with texts.
Definition: cglab.c:100
void addScore(float value, float x, float y)
Definition: cglab.c:479
void gameOver(void)
Transit to the game-over state.
Definition: cglab.c:705
float score
Game score.
Definition: cglab.c:18
bool btnp(uint8_t button)
Whether the button is just pressed now. Button are INPUT_*.
Definition: cglab.c:535
float thickness
Set the thickness for drawing line(), bar() and arc().
Definition: cglab.c:28
Collision bar(float x, float y, float length, float angle)
Draw a bar. Returns information on objects that collided while drawing.
Definition: cglab.c:207
Collision box(float x, float y, float w, float h)
Draw a box. Returns information on objects that collided while drawing.
Definition: cglab.c:170
bool colRect(Collision *cl, uint8_t color)
Whether it's colliding with rects.
Definition: cglab.c:91
bool btnr(uint8_t button)
Whether the button is just released now. Button are INPUT_*.
Definition: cglab.c:540
float rnd(float low, float high)
Get a random float value of [low, high).
Definition: cglab.c:546
Collision arc(float centerX, float centerY, float radius, float angleFrom, float angleTo)
Draw a arc. Returns information on objects that collided while drawing.
Definition: cglab.c:221
Collision rect(float x, float y, float w, float h)
Draw a rectangle. Returns information on objects that collided while drawing.
Definition: cglab.c:160
void setupGame(const char *_title, const char *_description, const CharacterData *_characters, const uint8_t **_sounds, void(*_update)(void))
Setup game.
Definition: cglab.c:711
void enableSound(void)
Enable playing background music and sound effects.
Definition: cglab.c:383
void toggleSound(void)
Toggle sound playing flag.
Definition: cglab.c:393
bool hasCollision
Definition: cglab.c:34
void disableSound(void)
Disable playing background music and sound effects.
Definition: cglab.c:388
int16_t rndi(int16_t low, int16_t high)
Get a random int value of [low, high - 1].
Definition: cglab.c:551
Collision constText(const char *msg, float x, float y)
Draw a const text. Returns information on objects that collided while drawing.
Definition: cglab.c:337
Collision text(char *msg, float x, float y)
Draw a text. Returns information on objects that collided while drawing.
Definition: cglab.c:332
uint8_t x
Definition: cglab.h:60
CharacterHitBox hitBox
Definition: cglab.h:68
uint8_t w
Definition: cglab.h:62
uint8_t y
Definition: cglab.h:61
uint8_t h
Definition: cglab.h:63
float angleTo(Vector *vec, float x, float y)
Definition: vector.c:36