all repos — hyperkaos @ 85f5534f1e8ed016da0afe2b19a8704f3486960e

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

map data interpreter coming along
Derek Stevens nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlxeK4EACgkQO3+8IhRO
Y5guyA/9H8le5i4Uh+y9eGOsTQl5eVzqW+Rn7Ylui+uRmtOy9NvgVyDB1Qq5KA24
HVolLxdRVh5pm9ZfZOW8je3Xj0rmla6vCY0jKWSGek3cI+4DJY/lpTEVd/UoAhXu
M+3wdsVFl4scwuZ+V45MSV1YtWp1jBHswoiwx9uEH1cQtvIb73mig/oU2AqF0h6l
CALzysw8WSOl2wsoJvMKqHM31Wz6SPQunb+2eGqw4qnuOUSrr0uKO00XnKQvhtrn
jm4WXitF4+B+t7UicuqwTiAu30fw7H3ZmzLfmtPvbS1VcqoXXOhsVMvkcq9a7F92
zVkyA2fLT1b473vnjzaj1WNSCf4iPG9SgvZ2p9oHj31mUEb6LeEvuTMIbci9zdTr
ErxhoAkCGJUpoLa7km+FiEOz7nX6BeFVbaHzdDd8zqLlo0Q/7qOynRYnoh4q3NMC
qjIpcqitsjGcoLU35Rpj7Ipun+1G5+p+pXGWfFdFz9RZf1/Q7B510bENqoaiytlE
XAxrB8vQr262us1PAPSaK60gCwvYrplqWqc3NagUMeJqgdgGmrLQXqIpVONT5A+d
Un+Ovar0U6WpL/hd5p5AYJY1NuNsbQc+6QgBBXlSKy3JebemmIiGVTtSI/OuupfC
PCbhfOIIncq0LgiSbITljMy5Pq0a/CyLRFqyvzFea+U8C8EWCS0=
=IrZM
-----END PGP SIGNATURE-----
commit

85f5534f1e8ed016da0afe2b19a8704f3486960e

parent

4df7ada3578b391fb9ad38f74288403639d65c2d

3 files changed, 178 insertions(+), 25 deletions(-)

jump to
M WorldData.cWorldData.c

@@ -54,7 +54,7 @@ int worldBuilder(enum dataChunks chunk)

{ char datafile[256]; char lineBuffer[1024]; - char objBuffer[24]; + char cmdBuffer[24]; char cchunk[4]; char propsBuffer[998]; int savequery;

@@ -85,54 +85,61 @@ continue;

} if (!conditional) { - if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", objBuffer, propsBuffer) < 2) + if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", cmdBuffer, propsBuffer) < 2) { printf("World data line malformed\n"); return 1; } else { - switch (hashCmd(objBuffer)) + switch (hashCmd(cmdBuffer)) { case 200: //mkRoom if (buildRoom(propsBuffer) != 0) - return 1; - break; + return 1; + break; case 45: //mkKaos -// buildKaos(propsBuffer); + if (buildKaos(propsBuffer) != 0) return 1; break; case 109: //mkTextBox -// buildTextbox(propsBuffer); + if (buildTextBox(propsBuffer) != 0) return 1; break; case 181: //addText -// modTextBox(propsBuffer); + if (modTextBox(propsBuffer) != 0) return 1; break; case 116: //SFX // buildSFX(propsBuffer); - break; + break; case 93: //BGM // buildBGM(propsBuffer); - break; + break; case 100: //addSigil // buildSynergy(propsBuffer); - break; + break; case 47: //addPerson - buildPerson(propsBuffer); - break; + if (buildPerson(propsBuffer) != 0) + return 1; + break; case 88: //addObstruction - buildObstruction(propsBuffer); - break; + if (buildObstruction(propsBuffer) != 0) + return 1; + break; case 141: //addImg -// buildFGImage(propsBuffer); - break; + if (buildFGImage(propsBuffer) != 0) + return 1; + break; case 240: //addTrigger - buildHyper(propsBuffer); - break; + if (buildHyper(propsBuffer) != 0) + return 1; + break; case 148: //chainKaos - //chainKaos(propsBuffer); + if (chainKaos(propsBuffer) != 0) + return 1; + break; case 238: //addWarp - buildWarp(propsBuffer); - break; + if (buildWarp(propsBuffer) != 0) + return 1; + break; } } }}

@@ -155,6 +162,117 @@ mapBuffer[slot] = newRoom(filename, breathe);

return 0; } +int buildTextBox(char* props) +{ + int slot; + char portrait[256]; + + if (sscanf(props, "slot %u, portrait %[^\n]", + &slot, portrait) != 2) + { + return 1; + } + printf("building textbox...\n"); + if (strcmp(portrait, "none") != 0) + { + dialogueData[slot] = newTextBox(); + } + else + { + dialogueData[slot] = newGTextBox(loadImage(portrait)); + } + return 0; +} + +int modTextBox(char* props) +{ + int slot; + char textData[64]; + + if (sscanf(props, "slot %u, %[^\n]", &slot, textData) != 2) + { + return 1; + } + printf("adding line of text to textbox...\n"); + addText(dialogueData[slot], textData); + return 0; +} + +int buildKaos(char* props) +{ + int slot; + char kType, kProps[990]; + + if (sscanf(props, "slot %u, class %c, %[^\n]", + &slot, &kType, kProps) != 3) + { + return 1; + } + printf("building kaos...\n"); + switch (kType) + { + case 'C': + if (buildConvo(slot, kProps) != 0) return 1; + break; + case 'W': + //if (buildWait(slot, kProps) != 0) return 1; + break; + case 'M': + if (buildManip(slot, kProps) != 0) return 1; + break; + case 'L': + //if (buildLook(slot, kProps) != 0) return 1; + break; + case 'F': +// if (buildFaceEachother(slot, kProps) != 0) return 1; + break; + case 'Y': + //if (buildChoice(slot, kProps) != 0) return 1; + break; + case 'S': + // if (buildSound(slot, kProps) != 0) return 1; + break; + case 'T': + //if (buildTeleport(slot, kProps) != 0) return 1; + break; + + } + return 0; +} + +int buildConvo(int slot, char* kProps) +{ + int tSlot; + if (sscanf(kProps, "textbox %u", &tSlot) != 1) + return 1; + printf(">>convo\n"); + kaosData[slot] = newConversation(tSlot); + return 0; +} + +int buildManip(int slot, char* kProps) +{ + int rm, pSlot, x, y; + 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 (pSlot >= 0) + { + target = mapBuffer[rm]->people[pSlot]; + } + printf(">>manip\n"); + kaosData[slot] = newManip(target, x, y); + return 0; +} + int buildObstruction(char* props) { int rm, x, y, w, h;

@@ -164,6 +282,7 @@ &rm, &x, &y, &w, &h) != 5)

{ return 1; } + printf("Building obstacle...\n"); addObstacle(mapBuffer[rm], x, y, w, h); return 0; }

@@ -177,7 +296,8 @@ &rm, &x, &y, &w, &h, filename, &f, &d, &a) !=9)

{ return 1; } - addFGObj(mapBuffer[rm], x, y, w, h, filename, f, d, a); + printf("Building FG Image...\n"); + addFgObj(mapBuffer[rm], x, y, w, h, filename, f, d, a); return 0; }

@@ -205,6 +325,19 @@ }

printf("Building hyperkaos...\n"); HyperKaos* temp = newHyperKaos(id, tType, x, y, w, h); addTrigger(mapBuffer[rm], temp); + return 0; +} + +int chainKaos(char* props) +{ + int rm, trig, k; + if (sscanf(props, "room %u, trigger %u, kaos %u", + &rm, &trig, &k) != 3) + { + return 1; + } + printf("Chaining kaos...\n"); + addKaos(mapBuffer[rm]->eventTriggers[trig], kaosData[k]); return 0; }
M WorldData.hWorldData.h

@@ -15,6 +15,18 @@ int buildObstruction(char* props);

int buildFGImage(char* props); +int buildKaos(char* props); + +int buildTextBox(char* props); + +int modTextBox(char* props); + +int chainKaos(char* props); + +int buildConvo(int slot, char* kProps); + +int buildManip(int slot, char* kProps); + int countMapThings(char x, enum dataChunks chunk); void unloadData(enum dataChunks chunk);
M mapdata/1.txtmapdata/1.txt

@@ -1,7 +1,15 @@

-mkRoom: slot 0, sprite assets/img/backgrounds/blueroom.png, spd 4 +mkRoom: slot 0, sprite assets/img/backgrounds/blueroom.png, spd 10 mkRoom: slot 1, sprite assets/img/backgrounds/darkroom.png, spd 4 +addTrigger: room 1, id 0, type 1, x 12, y 22, w 16, h 16 +mkTextBox: slot 0, portrait assets/img/kmage.gif +addText: slot 0, We have made a dynamic text box! +addText: slot 0, Go figure, huh? +mkKaos: slot 0, class M, player, xSpd 0, ySpd 0 +mkKaos: slot 1, class C, textbox 0 +chainKaos: room 1, trigger 0, kaos 0 +chainKaos: room 1, trigger 0, kaos 1 addWarp: room 0, x 0, y 0, w 320, h 8, dest 1,1, dX 160, dY 164 addWarp: room 1, x 0, y 172, w 320, h 8, dest 1,0, dX 160, dY 16 -addTrigger: room 1, id 0, type 0, x 0, y 0, w 320, h 180 addPerson: room 1, sprite assets/img/characters/kmage.png, x 20, y 30 addObstruction: room 1, x 10, y 16, w 20, h 20 +addImg: room 0, x 64, y 64, w 22, h 55, sprite assets/img/objects/floatingChips.png, frames 4, dual 1, alpha 255