all repos — hyperkaos @ b36c9a6d62996fe3726f359cfc429f81e5af076c

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

file feed map builder can do almost everything the hardwired map can do, just a few kaos types missing
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlxfr9wACgkQO3+8IhRO
Y5g6rQ//ay8ay4HLiT5x3Q0q2UmYTVWW7+OLAIy7PLlx5bxY4fExWRqXe1PmOZ5g
MC+6HEoFtkm8+BbkCiiMB9exZuKesVzbey4mU+f/IYL32N++Ju0ooYeUkJyQbLqC
zs01eQTTo1RMegCrIM76RMXkOwSrAZGYdvFW36dlioa//1bp/OuvVtwXS6rFjqGT
M5SrPf9WKP3miH+e/qRTNK8n5zcvbPeHDdtrYnOR7i6kn/g6t60Fu6VWolG9FPWi
HnYjJVqlaquc/IQmOT7A1FkygbhU0l/XjQ01iwb4/W8QxRLAtEcYRhMHvoYzTTph
2IffrBcPQv1CLh4OrtFcUJfxxHDJdQXvT3iyXYtwDCaXwOd/kIRx3052WKhr7XAE
H6QWGYtOH1H+QCq+iV7qGbaFQ/3JydNQksew6SbRFO88yH983AwBnlKXameUeYFn
4nBYNHRms0nuJbT7FtXfRg+iNugH4WhJOjrUbH9iEZ4F7fPTdmNSPnRtKPwY+g06
e7KLyfAJZCISjyrCqx+tACFZXRLQ5whoJYFci72Hfg/e4d5icmE/22oFzlXHcqcC
lQNQ6BoJ/1N2RL3oAuBUjnDxBTsyRK5U9YuoqBTFp/kqeEEXq8KG11Yz59YsqYSb
7+5WPwdaRI1b4u7RDCCGzdsyqfL6um3mickuuDOWJ5UGIvnFxuc=
=KtxE
-----END PGP SIGNATURE-----
commit

b36c9a6d62996fe3726f359cfc429f81e5af076c

parent

85f5534f1e8ed016da0afe2b19a8704f3486960e

2 files changed, 113 insertions(+), 86 deletions(-)

jump to
M WorldData.cWorldData.c

@@ -29,10 +29,11 @@ hasMusic = 0;

applySurface(8,8, loadingTxt, screen, NULL); frameAdvance(); printf("Loading map chunk\n"); - if(worldBuilder(chunk) != 0) + if(!worldBuilder(chunk)) { quit = 1; playing = 0; printf("Fatal map error. Quitting\n"); + return; }; printf("Loaded map chunk\n"); }

@@ -59,6 +60,7 @@ char cchunk[4];

char propsBuffer[998]; int savequery; int conditional = 0; + int (*fp)(char* props); FILE* worldInfo; sprintf(cchunk, "%d", chunk);

@@ -77,7 +79,7 @@ }

while (fgets(lineBuffer, 1024, worldInfo)) { - if (lineBuffer[0] == '#') continue; + if (!strcmp(lineBuffer,"\n") || !strcmp(lineBuffer,"\r\n")) continue; if (lineBuffer[0] == '<') { conditional = 0;

@@ -88,63 +90,86 @@ {

if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", cmdBuffer, propsBuffer) < 2) { printf("World data line malformed\n"); - return 1; + return 0; } else { switch (hashCmd(cmdBuffer)) { case 200: //mkRoom - if (buildRoom(propsBuffer) != 0) - return 1; + fp = &buildRoom; break; case 45: //mkKaos - if (buildKaos(propsBuffer) != 0) return 1; + fp = &buildKaos; break; case 109: //mkTextBox - if (buildTextBox(propsBuffer) != 0) return 1; + fp = &buildTextBox; break; case 181: //addText - if (modTextBox(propsBuffer) != 0) return 1; + fp = &modTextBox; break; - case 116: //SFX -// buildSFX(propsBuffer); + case 229: //loadFX + fp = &buildSFX; break; - case 93: //BGM -// buildBGM(propsBuffer); + case 125: //BGM + fp = &buildBGM; break; case 100: //addSigil -// buildSynergy(propsBuffer); + fp = &buildSynergy; break; case 47: //addPerson - if (buildPerson(propsBuffer) != 0) - return 1; + fp = &buildPerson; break; case 88: //addObstruction - if (buildObstruction(propsBuffer) != 0) - return 1; + fp = &buildObstruction; break; case 141: //addImg - if (buildFGImage(propsBuffer) != 0) - return 1; + fp = &buildFGImage; break; case 240: //addTrigger - if (buildHyper(propsBuffer) != 0) - return 1; + fp = &buildHyper; break; case 148: //chainKaos - if (chainKaos(propsBuffer) != 0) - return 1; + fp = &chainKaos; break; case 238: //addWarp - if (buildWarp(propsBuffer) != 0) - return 1; + fp = &buildWarp; break; } + if (!fp(propsBuffer)) + return 0; } }} fclose(worldInfo); - return 0; + return 1; +} + +int buildBGM(char* props) +{ + #ifdef SOUND_ON + int slot; + char filename[256]; + + if (sscanf(props, "slot %u, file %[^\t\n]", &slot, filename) != 2) + return 0; + + bgmData[slot] = loadBGM(filename); + #endif + return 1; +} + +int buildSFX(char* props) +{ + #ifdef SOUND_ON + int slot; + char filename[256]; + + if (sscanf(props, "slot %u, file %[^\t\n]", &slot, filename) != 2) + return 0; + + sfxData[slot] = loadSFX(filename); + #endif + return 1; } int buildRoom(char* props)

@@ -154,12 +179,10 @@ char filename[256];

int breathe; if (sscanf(props, "slot %u, sprite %[^,], spd %u", &slot, filename, &breathe) != 3) - { - return 1; - } + return 0; printf("Building room in map slot %d: bg = %s; spd = %d\n", slot, filename, breathe); mapBuffer[slot] = newRoom(filename, breathe); - return 0; + return 1; } int buildTextBox(char* props)

@@ -169,19 +192,13 @@ char portrait[256];

if (sscanf(props, "slot %u, portrait %[^\n]", &slot, portrait) != 2) - { - return 1; - } + return 0; printf("building textbox...\n"); if (strcmp(portrait, "none") != 0) - { dialogueData[slot] = newTextBox(); - } else - { dialogueData[slot] = newGTextBox(loadImage(portrait)); - } - return 0; + return 1; } int modTextBox(char* props)

@@ -190,35 +207,47 @@ int slot;

char textData[64]; if (sscanf(props, "slot %u, %[^\n]", &slot, textData) != 2) - { - return 1; - } + return 0; + printf("adding line of text to textbox...\n"); addText(dialogueData[slot], textData); - return 0; + return 1; +} + +int buildSynergy(char* props) +{ + int rm, x, y, w, h; + char d; + int spell, effect; + if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, spell %u, dir %c, effect %d", + &rm, &x, &y, &w, &h, &spell, &d, &effect) != 8) + return 0; + + printf("building synergy...\n"); + addSigil(mapBuffer[rm], newSynergy(spell, d, x, y, w, h, mapBuffer[rm]->eventTriggers[effect])); + return 1; } int buildKaos(char* props) { int slot; char kType, kProps[990]; + int (*fp)(int s, char* props); if (sscanf(props, "slot %u, class %c, %[^\n]", &slot, &kType, kProps) != 3) - { - return 1; - } + return 0; printf("building kaos...\n"); switch (kType) { case 'C': - if (buildConvo(slot, kProps) != 0) return 1; + fp = &buildConvo; break; case 'W': - //if (buildWait(slot, kProps) != 0) return 1; +// fp = &buildWait; break; case 'M': - if (buildManip(slot, kProps) != 0) return 1; + fp = &buildManip; break; case 'L': //if (buildLook(slot, kProps) != 0) return 1;

@@ -237,17 +266,19 @@ //if (buildTeleport(slot, kProps) != 0) return 1;

break; } - return 0; + if (!fp(slot, kProps)) + return 0; + return 1; } int buildConvo(int slot, char* kProps) { int tSlot; if (sscanf(kProps, "textbox %u", &tSlot) != 1) - return 1; + return 0; printf(">>convo\n"); kaosData[slot] = newConversation(tSlot); - return 0; + return 1; } int buildManip(int slot, char* kProps)

@@ -257,20 +288,16 @@ pSlot = -1;

Player* target = hero; if (sscanf(kProps, "room %u, person %u, xSpd %d, ySpd %d", &rm, &pSlot, &x, &y) != 4) - { - } - else if (sscanf(kProps, "player, xSpd %d, ySpd %d", - &x, &y) != 2) - { - return 1; - } + if (sscanf(kProps, "player, xSpd %d, ySpd %d", + &x, &y) != 2) + return 0; + if (pSlot >= 0) - { target = mapBuffer[rm]->people[pSlot]; - } + printf(">>manip\n"); kaosData[slot] = newManip(target, x, y); - return 0; + return 1; } int buildObstruction(char* props)

@@ -279,12 +306,11 @@ int rm, x, y, w, h;

if (sscanf(props, "room %u, x %d, y %d, w %u, h %u", &rm, &x, &y, &w, &h) != 5) - { - return 1; - } + return 0; + printf("Building obstacle...\n"); addObstacle(mapBuffer[rm], x, y, w, h); - return 0; + return 1; } int buildFGImage(char* props)

@@ -293,12 +319,11 @@ int rm, x, y, w, h, f, d, a;

char filename[256]; if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, sprite %[^,], frames %u, dual %u, alpha %u", &rm, &x, &y, &w, &h, filename, &f, &d, &a) !=9) - { - return 1; - } + return 0; + printf("Building FG Image...\n"); addFgObj(mapBuffer[rm], x, y, w, h, filename, f, d, a); - return 0; + return 1; } int buildWarp(char* props)

@@ -306,12 +331,11 @@ {

int r, x, y, w, h, dC, dR, dX, dY; if (sscanf(props, "room %u, x %d, y %d, w %u, h %u, dest %u,%u, dX %d, dY %d", &r, &x, &y, &w, &h, &dC, &dR, &dX, &dY) != 9) - { - return 1; - } + return 0; + printf("Building warp...\n"); addWarp(mapBuffer[r], x, y, w, h, dC, dR, dX, dY); - return 0; + return 1; } int buildHyper(char* props)

@@ -319,13 +343,12 @@ {

int rm, id, tType, x, y, w, h; if (sscanf(props, "room %u, id %u, type %u, x %d, y %d, w %u, h %u", &rm, &id, &tType, &x, &y, &w, &h) != 7) - { - return 1; - } + return 0; + printf("Building hyperkaos...\n"); HyperKaos* temp = newHyperKaos(id, tType, x, y, w, h); addTrigger(mapBuffer[rm], temp); - return 0; + return 1; } int chainKaos(char* props)

@@ -333,12 +356,11 @@ {

int rm, trig, k; if (sscanf(props, "room %u, trigger %u, kaos %u", &rm, &trig, &k) != 3) - { - return 1; - } + return 0; + printf("Chaining kaos...\n"); addKaos(mapBuffer[rm]->eventTriggers[trig], kaosData[k]); - return 0; + return 1; } int buildPerson(char* props)

@@ -348,16 +370,15 @@ char filename[256];

if (sscanf(props, "room %u, sprite %[^,], x %d, y%d", &rm, filename, &x, &y) != 4) - { - return 1; - } + return 0; + printf("Building person...\n"); Player* temp = newPlayer(filename, x, y); addPerson(mapBuffer[rm], temp); - return 0; + return 1; } -int countMapThings(char x, enum dataChunks chunk) +int countMapThings(enum dataChunks chunk) { int count = 0;
M WorldData.hWorldData.h

@@ -3,6 +3,12 @@ void bufferData(enum dataChunks chunk);

int worldBuilder(enum dataChunks chunk); +int buildSFX(char* props); + +int buildBGM(char* props); + +int buildSynergy(char* props); + int buildRoom(char* props); int buildWarp(char* props);