all repos — hyperkaos @ main

lightweight modular puzzle/adventure game engine in C with SDL 1.2

fix readme
Derek Stevens
add TextBox.c to README
Derek Stevens
started writing documentation
Derek Stevens

HyperKaos engine


loadImage(char* filename)

returns an SDL_Surface* of the image file at given file path

applySurface(int x, int y, SDL_Surface* src, SDL_Surface dest, SDL_Rect* clip)

wrapper for SDL_BlitSurface, drawing src onto dest with origin (x,y) and clipped according to clip

getPixel(SDL_Surface* surface, int x, int y)

get color value of a pixel on an SDL_Surface as a Uint32


scales the game widow from native resolution of 320x180 to integer multiple according to config.h

loadBGM(char* filename)

sets hasMusic for this map chunk to True and returns the file as a Mix_Music*

loadSFX(char* filename)

returns a Mix_Chunk* of the wav file at given path


paints the current room’s background image and increment its animation


paints the current room’s fg objects and people, and the player


paints the spell selection HUD


grabs keyboard input in the main loop and modifies the game state


checks if spell has been cast; if so, looks up the spell in the spellbook and does a synergy; then unsets the spell lookup; then checks if any eventTriggers have been activated; due to the implementation of hyperKaos, if more than one are activated at the same time, the one later in the array is run

init(int argc, char** args)

initializes SDL subssytems, creates game window, loads UI data and hero data, allocates memory for mapData and mapBuffer, dialogueData, kaosData, theatre (scene data), and builds the spellbook


builds some hyperKaos* and stores them in spellBook


deallocates spellbook Memory


reinvents the wheel with SDL_SetVideoMode


waits with SDL_Delay to keep a constant framerate


scales the internal screen to the game window size, updates the game window, and waits to start the main loop over


enters windowed mode, cleans up all the memory, closes SDL subsystems


builds a couple Scene*s for the intro sequence, plays them, and cleans up the memory.


listens for keyboard input and navigates the main menu. reads save file if continued game, otherwise sets game data to the beginning of the game. or quit. takes control of the main game loop


listens for keyboard input and saves, quits, or continues playing; takes control of the main game loop


bufferData(int chunk)

sets hasMusic to flase, paints loading message on screen, builds world chunk; if there is an error building the world, quit the game

hashCmd(char* x)

return an 8bit hash on a string for interpreting the worldBuilder script (this means there are max 256 commands for map generation, excluding “<” which functions as a closing bracket for “if” and “ifNot” directives)

worldBuilder(int chunk)

allocates memory, opens map data file for current chunk; reads line by line, hashing the first word of the line, then switching on that to execute an action; bubbles up failure (malformed lines) by returning nonzero; returns zero if the whole file is read and processed

buildBGM(char* props)

parses the args of loadBGM worldBuilder command and passes them to loadBGM(); return nonzero if malformed

buildSFX(char* props)

parses the args of loadFX worldBuilder command and passes them to loadSFX(); return nonzero if malformed

buildRoom(char* props)

parses the args of mkRoom worldBuilder command to build a room and place it in mapBuffer; return nonzero if malformed

buildTextBox(char* props)

parses the args of mkTextBox worldBuilder command to build an empty textBox and place it in dialogueData; return nonzero if malformed

modTextBox(char* props)

parses the args of addText worldBuilder command to add text to the indicated textBox in dialogueData; return nonzero if malformed

buildSynergy(char* props)

parses the args of addSigil worldBuilder command to pass to addSigil(); return nonzero if malformed

buildKaos(char* props)

parses the args of mkKaos worldBuilder command, switches on the class to figure out which constructor to pass the subsequent args to returns nonzero if malformed

buildObstruction(char* props)

parses the args of addObstruction worldBuilder command, passes them to addObstacle(); returns nonzero if malformed

buildFGImage(char* props)

parses the args of addImg worldBuilder command and passes them to addFGObj(); returns nonzero if malformed

buildWarp(char* props)

parses the args of addWrap worldBuilder command and passes them to addWarp(); returns nonzer o if malformed

buildHyper(char* props)

parses the args of addTrigger worldBuilder command and passes them to addTrigger(); returns nonzero if malformed

chainKaos(char* props)

parses the args of the chainKaos worldBuilder command and passes them to addKaos(); returns nonzero if malformed

buildPerson(char* props)

parses the args of the addPerson worldBuilder command and passes them to addPerson(); returns nonzero if malformed

countMapThings(int* count, int chunk)

writes counts of global memory objects in this chunk to count based on mapdata file; this means the map data must be read again to count global objects before deletion!

dataPurge(int* counts)

takes counts produced by countMap to free map chunk data

unloadData(int chunk)

allocates count buffer for global map objects, counts the objects with countMapThings(), and passes it to dataPurge()


moves mapBuffer to mapData and allocates new mapBuffer; if music was loaded in the new map chunk, play the first track


if the player is warping to a new map chunk, halt the music (if any), unload the current map chunk before pushing mapBuffer to mapData



returns a pointer to an empty TextBox

newGTextBox(SDL_Surface* image)

returns a pointer to an empty TextBox, with portarit image

deleteTextBox(TextBox* target)

deallocates memory for target

addText(TextBox* self, char* text)

adds the string of text as a line in the TextBox pointed to by self

textBoxInput(TextBox* self, int* textIsRelevent)

increments TextBox cursor, handles keyboard input while TextBox is onscreen

displayTextBox(TextBox* self)

takes control of the main loop and draws the room, foreground, and the TextBox over it all, and passes input to textBoxInput()

git clone