From 85f5534f1e8ed016da0afe2b19a8704f3486960e Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Fri, 8 Feb 2019 17:23:13 -0800 Subject: [PATCH] map data interpreter coming along --- WorldData.c | 179 +++++++++++++++++++++++++++++++++++++++++++------- WorldData.h | 12 ++++ mapdata/1.txt | 12 +++- 3 files changed, 178 insertions(+), 25 deletions(-) diff --git a/WorldData.c b/WorldData.c index 2eef2c8..111c3c3 100644 --- a/WorldData.c +++ b/WorldData.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 @@ int worldBuilder(enum dataChunks chunk) } 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 @@ int buildRoom(char* props) 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 @@ int buildObstruction(char* props) { return 1; } + printf("Building obstacle...\n"); addObstacle(mapBuffer[rm], x, y, w, h); return 0; } @@ -177,7 +296,8 @@ int buildFGImage(char* props) { 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; } @@ -208,6 +328,19 @@ int buildHyper(char* props) 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; +} + int buildPerson(char* props) { int rm, x, y; diff --git a/WorldData.h b/WorldData.h index e947388..a74c715 100644 --- a/WorldData.h +++ b/WorldData.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); diff --git a/mapdata/1.txt b/mapdata/1.txt index 2ccc03d..a84c4ce 100644 --- a/mapdata/1.txt +++ b/mapdata/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