all repos — hyperkaos @ 20fbac8ed1ac18bbcb91b84602bf0cee7037797b

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

README.md (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#HyperKaos engine

##Engine.c

###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

###scaleScreen()

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

###renderBackground()

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

###renderForeground()

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

###renderHUD()

paints the spell selection HUD


###interact()

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

###kListen()

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

###writeSpellbook()

builds some hyperKaos* and stores them in spellBook

###burnSpellbook()

deallocates spellbook Memory

###toggleFullscreen()

reinvents the wheel with SDL_SetVideoMode

###timeDilation()

waits with SDL_Delay to keep a constant framerate

###frameAdvance()

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

###cleanup()

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

###intro()

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

###mainmenu()

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

###pausemenu()

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

##WorldData.c

###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()

###pushBufferData()

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

###pager()

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

##TextBox.c

###newTextBox()

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()