all repos — hyperkaos @ f53665d989065b7e6a7314b904050357698fb048

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

checking save state in worldbuilder, converting Kaos constructors to accept char* args
Derek Stevens nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlyFwtoACgkQO3+8IhRO
Y5hS1RAAmVCHNWuz5OUkUkYZTMnbX7jSZjndqIHL2xE8a4FOFrZOntchAOSBhBie
bQfZwE7ETiQgrN7w/8adpUa7fCCHlHXOkb69gLhgzfpN019zlqA3ChheQrlA+Pjp
NkOSp2V6H18nNih3V3QsauX+gWTLSVv0sRWI+d6WuRYdM9O7+0dnGmy3n5ZqRoTP
s7Rjjty/VG8y+T04LW4lnFeY7gLFXeGxMp1Gt9uTuv5N/F9qgRp8l8Ii/sP1iDFF
Lo76bWnWGHarZ2MlWYEkcnzF/hGJTxI/YMVzoeBpxgMY4gz0sHaw+QzdFz3FnB0i
KWbkEQtaeO/KXmKh6UZ1oc/Z8IYFnb6Ub4/YfOqj7BjitN6eRoRLrKHIsa6a3YHb
2t4Kvlr20oSDrl8h85jzi92lfT4Zf6juWqg7DA1aLK2BASfmDm3VvyI8TCa9ywF6
cOxBDF3hvpesNQ7rymjBBya548Facu3afxNyf9XrhDhHcP2EbOQ0F6iveag1dMkj
Z12YKinWi8XWsd10ViDx1QuJmvv6G/CKc1ZsWqQoIzFTUI/gbKCcnq8mRM94OEnX
3hmFvrNWThV6H+Q0jmn/ZsSuunBNkj0VwFX5qxdM0bJj+J3ICFAssoOvCWddTduE
lWL4Tir1wzJOkbgxZFNoIbjmuz1WxC0CgapkzQZtJNHAkIL4pRw=
=XHRN
-----END PGP SIGNATURE-----
commit

f53665d989065b7e6a7314b904050357698fb048

parent

a99cabc018383476143cea2952c9d58b2ef83c95

4 files changed, 102 insertions(+), 38 deletions(-)

jump to
M Kaos.cKaos.c

@@ -63,11 +63,11 @@

Kaos* newChoice(char* args) { char q[32], a1[32], a2[32]; - int p1, p2; + int rm, p1, p2; Kaos* core = rawKaos(); Choice* self = malloc(sizeof(Choice)); - if (sscanf(args, "q %[^,], a1 %[^,], a2 %[^,], p1 %d, p2 %d", q, a1, a2, &p1, &p2) != 5) + if (sscanf(args, "q %[^,], a1 %[^,], a2 %[^,], rm %d, p1 %d, p2 %d", q, a1, a2, &rm, &p1, &p2) != 5) { free(core); free(self);

@@ -79,8 +79,8 @@

self->question = TTF_RenderText_Solid(font, q, textColor); self->answ1 = TTF_RenderText_Solid(font, a1, textColor); self->answ2 = TTF_RenderText_Solid(font, a2, textColor); - self->path1 = p1; - self->path2 = p2; + self->path1 = mapBuffer[rm]->eventTriggers[p1]; + self->path2 = mapBuffer[rm]->eventTriggers[p2]; core->kType = self; self->core = core;

@@ -202,12 +202,31 @@ free(target->kType);

free(target); } -Kaos* newLook(Player* t, char d) +Kaos* newLook(char* args) { Kaos* core = rawKaos(); Look* self = malloc(sizeof(Look)); - self->target = t; + int rm, pSlot; + char d; + pSlot = -1; + + if (sscanf(args, "room %u, person %u, dir %c", + &rm, &pSlot, &d) != 3) + if (sscanf(args, "hero, dir %c", + &d) != 1) + { + free(core); + core = NULL; + free(self); + self = NULL; + return core; + } + + if (pSlot >= 0) + self->target = mapBuffer[rm]->people[pSlot]; + else self->target = hero; + self->dir = d; self->core = core;

@@ -243,15 +262,32 @@ free(target->kType);

free(target); } -Kaos* newTeleport(Player* p, int x, int y, int o) +Kaos* newTeleport(char* args) { Kaos* core = rawKaos(); Teleport* self = malloc(sizeof(Teleport)); - self->target = p; + int rm, pSlot, x, y; + pSlot = -1; + + if (sscanf(args, "room %u, person %u, x %d, y %d", + &rm, &pSlot, &x, &y) != 4) + if (sscanf(args, "hero, x %d, y %d", + &x, &y) != 2) + { + free(core); + core = NULL; + free(self); + self = NULL; + return core; + } + + if (pSlot >= 0) + self->target = mapBuffer[rm]->people[pSlot]; + else + self->target = hero; self->x = x; self->y = y; - self->out = o; self->aura = loadImage("assets/img/fx/blkthunder.png"); self->core = core;

@@ -270,16 +306,8 @@ for (i = 0; i < 16; i++)

{ if (i == 11) { - if (kSelf->out) - { - kSelf->target->point.x = -16; - kSelf->target->point.y = -16; - } - else - { - kSelf->target->point.x = kSelf->x; - kSelf->target->point.y = kSelf->y; - } + kSelf->target->point.x = kSelf->x; + kSelf->target->point.y = kSelf->y; } clip.x = (i%4)*32; timeStart(&fps);

@@ -298,13 +326,29 @@ free(target->kType);

free(target); } -Kaos* newFaceEachother(Player* p1, Player* p2) +Kaos* newFaceEachother(char* args) { Kaos* core = rawKaos(); FaceEachother* self = malloc(sizeof(FaceEachother)); + int r1, r2; + int p1, p2; + p1 = -1; + if (sscanf(args, "rm %d, person %d, rm %d, person %d", &r1, &p1, &r2, &p2) != 4) + if (sscanf(args, "hero, rm %d, person %d", &r2, &p2) != 2) + { + free(core); + core = NULL; + free(self); + self = NULL; + return core; + } - self->p1 = p1; - self->p2 = p2; + if (p1 >= 0) + { + self->p1 = mapBuffer[r1]->people[p1]; + } + else self->p1 = hero; + self->p2 = mapBuffer[r2]->people[p2]; core->kType = self; self->core = core;
M Kaos.hKaos.h

@@ -59,7 +59,6 @@ {

Kaos* core; Player* target; int x, y; - int out; SDL_Surface* aura; } Teleport;

@@ -103,20 +102,20 @@ Kaos* newManip(char* args);

void runManip(Kaos* self); void deleteManip(Kaos* target); -Kaos* newLook(Player* t, char d); +Kaos* newLook(char* args); void runLook(Kaos* self); void deleteLook(Kaos* target); -Kaos* newTeleport(Player* p, int x, int y, int o); +Kaos* newTeleport(char* args); void runTeleport(Kaos* self); void deleteTeleport(Kaos* target); -Kaos* newFaceEachother(Player* p1, Player* p2); +Kaos* newFaceEachother(char* args); void runFaceEachother(Kaos* self); void deleteFaceEachother(Kaos* target); #ifdef SOUND_ON -Kaos* newPlaySound(int i); +Kaos* newPlaySound(char* args); void runPlaySound(Kaos* self); void deletePlaySound(Kaos* target); #endif
M WorldData.cWorldData.c

@@ -96,6 +96,20 @@ else

{ switch (hashCmd(cmdBuffer)) { + case 106: //if + if ((sscanf(propsBuffer, "%d", &savequery) == 1) && notCompleted(savequery)) + { + conditional = 1; + continue; + } + break; + case 15: //ifNot + if ((sscanf(propsBuffer, "%d", &savequery) == 1) && hasCompleted(savequery)) + { + conditional = 1; + continue; + } + break; case 200: //mkRoom fp = &buildRoom; break;

@@ -233,7 +247,7 @@ {

int slot; char kType, kProps[990]; Kaos* (*fp)(char* args); - + fp = NULL; if (sscanf(props, "slot %u, class %c, %[^\n]", &slot, &kType, kProps) != 3) return 0;

@@ -244,30 +258,37 @@ case 'C':

fp = &newConversation; break; case 'W': -// fp = &buildWait; +// fp = &newWait; break; case 'M': fp = &newManip; break; case 'L': - //if (buildLook(slot, kProps) != 0) return 1; + fp = &newLook; break; case 'F': -// if (buildFaceEachother(slot, kProps) != 0) return 1; + fp = &newFaceEachother; break; case 'Y': - //if (buildChoice(slot, kProps) != 0) return 1; + fp = &newChoice; break; case 'S': - // if (buildSound(slot, kProps) != 0) return 1; +#ifdef SOUND_ON + //fp = &newPlaySound; break; +#endif case 'T': - //if (buildTeleport(slot, kProps) != 0) return 1; + fp = &newTeleport; break; - + case 'E': + //fp = &newErase; + break; } - if (!(kaosData[slot] = fp(kProps))) + if (fp && !(kaosData[slot] = fp(kProps))) + { + printf("Malformed args to Kaos or no memory!"); return 0; + } return 1; }
M mapdata/1.txtmapdata/1.txt

@@ -7,8 +7,8 @@ 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 +mkKaos: slot 0, class M, hero, 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