map data interpreter coming along

This commit is contained in:
Iris Lightshard 2019-02-08 17:23:13 -08:00
parent 4df7ada357
commit 85f5534f1e
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
3 changed files with 178 additions and 25 deletions

View file

@ -54,7 +54,7 @@ int worldBuilder(enum dataChunks chunk)
{ {
char datafile[256]; char datafile[256];
char lineBuffer[1024]; char lineBuffer[1024];
char objBuffer[24]; char cmdBuffer[24];
char cchunk[4]; char cchunk[4];
char propsBuffer[998]; char propsBuffer[998];
int savequery; int savequery;
@ -85,27 +85,27 @@ int worldBuilder(enum dataChunks chunk)
} }
if (!conditional) if (!conditional)
{ {
if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", objBuffer, propsBuffer) < 2) if (sscanf(lineBuffer, "%[^:]: %[^\t\n]", cmdBuffer, propsBuffer) < 2)
{ {
printf("World data line malformed\n"); printf("World data line malformed\n");
return 1; return 1;
} }
else else
{ {
switch (hashCmd(objBuffer)) switch (hashCmd(cmdBuffer))
{ {
case 200: //mkRoom case 200: //mkRoom
if (buildRoom(propsBuffer) != 0) if (buildRoom(propsBuffer) != 0)
return 1; return 1;
break; break;
case 45: //mkKaos case 45: //mkKaos
// buildKaos(propsBuffer); if (buildKaos(propsBuffer) != 0) return 1;
break; break;
case 109: //mkTextBox case 109: //mkTextBox
// buildTextbox(propsBuffer); if (buildTextBox(propsBuffer) != 0) return 1;
break; break;
case 181: //addText case 181: //addText
// modTextBox(propsBuffer); if (modTextBox(propsBuffer) != 0) return 1;
break; break;
case 116: //SFX case 116: //SFX
// buildSFX(propsBuffer); // buildSFX(propsBuffer);
@ -117,21 +117,28 @@ int worldBuilder(enum dataChunks chunk)
// buildSynergy(propsBuffer); // buildSynergy(propsBuffer);
break; break;
case 47: //addPerson case 47: //addPerson
buildPerson(propsBuffer); if (buildPerson(propsBuffer) != 0)
return 1;
break; break;
case 88: //addObstruction case 88: //addObstruction
buildObstruction(propsBuffer); if (buildObstruction(propsBuffer) != 0)
return 1;
break; break;
case 141: //addImg case 141: //addImg
// buildFGImage(propsBuffer); if (buildFGImage(propsBuffer) != 0)
return 1;
break; break;
case 240: //addTrigger case 240: //addTrigger
buildHyper(propsBuffer); if (buildHyper(propsBuffer) != 0)
return 1;
break; break;
case 148: //chainKaos case 148: //chainKaos
//chainKaos(propsBuffer); if (chainKaos(propsBuffer) != 0)
return 1;
break;
case 238: //addWarp case 238: //addWarp
buildWarp(propsBuffer); if (buildWarp(propsBuffer) != 0)
return 1;
break; break;
} }
} }
@ -155,6 +162,117 @@ int buildRoom(char* props)
return 0; 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 buildObstruction(char* props)
{ {
int rm, x, y, w, h; int rm, x, y, w, h;
@ -164,6 +282,7 @@ int buildObstruction(char* props)
{ {
return 1; return 1;
} }
printf("Building obstacle...\n");
addObstacle(mapBuffer[rm], x, y, w, h); addObstacle(mapBuffer[rm], x, y, w, h);
return 0; return 0;
} }
@ -177,7 +296,8 @@ int buildFGImage(char* props)
{ {
return 1; 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; return 0;
} }
@ -208,6 +328,19 @@ int buildHyper(char* props)
return 0; 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 buildPerson(char* props)
{ {
int rm, x, y; int rm, x, y;

View file

@ -15,6 +15,18 @@ int buildObstruction(char* props);
int buildFGImage(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); int countMapThings(char x, enum dataChunks chunk);
void unloadData(enum dataChunks chunk); void unloadData(enum dataChunks chunk);

View file

@ -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 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 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 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 addPerson: room 1, sprite assets/img/characters/kmage.png, x 20, y 30
addObstruction: room 1, x 10, y 16, w 20, h 20 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