crisp-game-lib-portable
Functions | Variables
cglp.c File Reference

Functions

Collision rect (float x, float y, float w, float h)
 
Collision box (float x, float y, float w, float h)
 Draw a box. Returns information on objects that collided while drawing. More...
 
Collision line (float x1, float y1, float x2, float y2)
 Draw a line. Returns information on objects that collided while drawing. More...
 
Collision bar (float x, float y, float length, float angle)
 Draw a bar. Returns information on objects that collided while drawing. More...
 
Collision arc (float centerX, float centerY, float radius, float angleFrom, float angleTo)
 Draw a arc. Returns information on objects that collided while drawing. More...
 
Collision text (char *msg, float x, float y)
 Draw a text. Returns information on objects that collided while drawing. More...
 
Collision character (char *msg, float x, float y)
 
void play (int type)
 
void enableSound ()
 Enable playing background music and sound effects. More...
 
void disableSound ()
 Disable playing background music and sound effects. More...
 
void toggleSound ()
 Toggle sound playing flag. More...
 
void addScore (float value, float x, float y)
 
void particle (float x, float y, float count, float speed, float angle, float angleWidth)
 Add particles. More...
 
EMSCRIPTEN_KEEPALIVE void setButtonState (bool left, bool right, bool up, bool down, bool b, bool a)
 
float rnd (float low, float high)
 Get a random float value of [low, high). More...
 
int rndi (int low, int high)
 Get a random int value of [low, high - 1]. More...
 
void consoleLog (char *format,...)
 
float clamp (float v, float low, float high)
 Clamp a value to [low, high]. More...
 
float wrap (float v, float low, float high)
 Wrap a value to [low, high). More...
 
char * intToChar (int v)
 Convert a value of type int to a value of type char*. More...
 
void gameOver ()
 Transit to the game-over state. More...
 
void goToMenu ()
 Go to the game selection menu screen. More...
 
void restartGame (int gameIndex)
 Restart another game specified by gameIndex. More...
 
EMSCRIPTEN_KEEPALIVE void initGame ()
 
EMSCRIPTEN_KEEPALIVE void updateFrame ()
 

Variables

int ticks
 A variable incremented by one every 1/60 of a second (readonly). More...
 
float score
 Game score. More...
 
float difficulty
 
int color
 
float thickness
 Set the thickness for drawing line(), bar() and arc(). More...
 
float barCenterPosRatio
 
CharacterOptions characterOptions
 Options for drawing text() and character(). More...
 
bool hasCollision
 
float tempo = 120
 Tempo of background music. More...
 
Input input
 Input state from the buttons (readonly). More...
 
Input currentInput
 Input state (used to get input on title screen) (readonly). More...
 
bool isInMenu
 Set to true when the menu screen is open (readonly). More...
 

Function Documentation

◆ addScore()

void addScore ( float  value,
float  x,
float  y 
)

Add score points and draw additional score on the screen. You can also add score points simply by adding the score variable.

◆ arc()

Collision arc ( float  centerX,
float  centerY,
float  radius,
float  angleFrom,
float  angleTo 
)

Draw a arc. Returns information on objects that collided while drawing.

◆ bar()

Collision bar ( float  x,
float  y,
float  length,
float  angle 
)

Draw a bar. Returns information on objects that collided while drawing.

◆ box()

Collision box ( float  x,
float  y,
float  w,
float  h 
)

Draw a box. Returns information on objects that collided while drawing.

◆ character()

Collision character ( char *  msg,
float  x,
float  y 
)

Draw a pixel art. Returns information on objects that collided while drawing. You can define pixel arts (6x6 dots) of characters with characters array.

◆ clamp()

float clamp ( float  v,
float  low,
float  high 
)

Clamp a value to [low, high].

◆ consoleLog()

void consoleLog ( char *  format,
  ... 
)

Print a message to the console (the same arguments as for printf can be used).

◆ disableSound()

void disableSound ( )

Disable playing background music and sound effects.

◆ enableSound()

void enableSound ( )

Enable playing background music and sound effects.

◆ gameOver()

void gameOver ( )

Transit to the game-over state.

◆ goToMenu()

void goToMenu ( )

Go to the game selection menu screen.

◆ initGame()

EMSCRIPTEN_KEEPALIVE void initGame ( )

Initialize all games and go to the game selection menu screen. This function must be called from the machine dependent setup step.

◆ intToChar()

char * intToChar ( int  v)

Convert a value of type int to a value of type char*.

◆ line()

Collision line ( float  x1,
float  y1,
float  x2,
float  y2 
)

Draw a line. Returns information on objects that collided while drawing.

◆ particle()

void particle ( float  x,
float  y,
float  count,
float  speed,
float  angle,
float  angleWidth 
)

Add particles.

◆ play()

void play ( int  type)

Play a sound effect. Type are COIN, LASER, EXPLOSION, POWER_UP, HIT, JUMP, SELECT, CLICK and RANDOM.

◆ rect()

Collision rect ( float  x,
float  y,
float  w,
float  h 
)

Draw a rectangle. Returns information on objects that collided while drawing.

◆ restartGame()

void restartGame ( int  gameIndex)

Restart another game specified by gameIndex.

◆ rnd()

float rnd ( float  low,
float  high 
)

Get a random float value of [low, high).

◆ rndi()

int rndi ( int  low,
int  high 
)

Get a random int value of [low, high - 1].

◆ setButtonState()

EMSCRIPTEN_KEEPALIVE void setButtonState ( bool  left,
bool  right,
bool  up,
bool  down,
bool  b,
bool  a 
)

Set whether or not each button is pressed. This function must be called from the machine dependent input handling step.

◆ text()

Collision text ( char *  msg,
float  x,
float  y 
)

Draw a text. Returns information on objects that collided while drawing.

◆ toggleSound()

void toggleSound ( )

Toggle sound playing flag.

◆ updateFrame()

EMSCRIPTEN_KEEPALIVE void updateFrame ( )

Update game frames every 1/60 second. This function must be called from the machine dependent update step.

◆ wrap()

float wrap ( float  v,
float  low,
float  high 
)

Wrap a value to [low, high).

Variable Documentation

◆ barCenterPosRatio

float barCenterPosRatio

A value from 0 to 1 that defines where the center coordinates are on the bar(), default: 0.5.

◆ characterOptions

CharacterOptions characterOptions

Options for drawing text() and character().

◆ color

int color

Set the color for drawing rectangles, particles, texts, and characters. Setting the color prior to text() and character() will recolor the pixel art. Use color = BLACK to restore and use the original colors. Colors are WHITE, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, BLACK, LIGHT_* and TRANSPARENT.

◆ currentInput

Input currentInput

Input state (used to get input on title screen) (readonly).

◆ difficulty

float difficulty

A variable that is one at the beginning of the game, two after 1 minute, and increasing by one every minute (readonly).

◆ hasCollision

bool hasCollision

If hasCollision is set to true, the drawn rectangle will have no collision with other rectangles. Used to improve performance.

◆ input

Input input

Input state from the buttons (readonly).

◆ isInMenu

bool isInMenu

Set to true when the menu screen is open (readonly).

◆ score

float score

Game score.

◆ tempo

float tempo = 120

Tempo of background music.

◆ thickness

float thickness

Set the thickness for drawing line(), bar() and arc().

◆ ticks

int ticks

A variable incremented by one every 1/60 of a second (readonly).