working on world data interpreter

This commit is contained in:
Iris Lightshard 2019-02-08 14:38:55 -08:00
parent 456cba7e6c
commit 5fc726bcdb
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
3 changed files with 60 additions and 6 deletions

View file

@ -117,17 +117,19 @@ int worldBuilder(enum dataChunks chunk)
// buildSynergy(propsBuffer); // buildSynergy(propsBuffer);
break; break;
case 47: //addPerson case 47: //addPerson
// buildPerson(propsBuffer); buildPerson(propsBuffer);
break; break;
case 88: //addObstruction case 88: //addObstruction
// buildObstruction(propsBuffer); buildObstruction(propsBuffer);
break; break;
case 141: //addImg case 141: //addImg
// buildFGImage(propsBuffer); // buildFGImage(propsBuffer);
break; break;
case 240: //addTrigger case 240: //addTrigger
// buildHyper(propsBuffer); buildHyper(propsBuffer);
break; break;
case 148: //chainKaos
//chainKaos(propsBuffer);
case 238: //addWarp case 238: //addWarp
buildWarp(propsBuffer); buildWarp(propsBuffer);
break; break;
@ -144,7 +146,7 @@ int buildRoom(char* props)
char filename[256]; char filename[256];
int breathe; int breathe;
if (sscanf(props, "slot %d, sprite %[^,], spd %d", &slot, filename, &breathe) != 3) if (sscanf(props, "slot %u, sprite %[^,], spd %u", &slot, filename, &breathe) != 3)
{ {
return 1; return 1;
} }
@ -153,18 +155,62 @@ int buildRoom(char* props)
return 0; return 0;
} }
int buildObstruction(char* props)
{
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;
}
addObstacle(mapBuffer[rm], x, y, w, h);
return 0;
}
int buildWarp(char* props) int buildWarp(char* props)
{ {
int r, x, y, w, h, dC, dR, dX, dY; int r, x, y, w, h, dC, dR, dX, dY;
if (sscanf(props, "room %d, x %d, y %d, w %d, h %d, dest %d,%d, dX %d, dY %d", 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) &r, &x, &y, &w, &h, &dC, &dR, &dX, &dY) != 9)
{ {
return 1; return 1;
} }
printf("Building warp...\n");
addWarp(mapBuffer[r], x, y, w, h, dC, dR, dX, dY); addWarp(mapBuffer[r], x, y, w, h, dC, dR, dX, dY);
return 0; return 0;
} }
int buildHyper(char* props)
{
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;
}
printf("Building hyperkaos...\n");
HyperKaos* temp = newHyperKaos(id, tType, x, y, w, h);
addTrigger(mapBuffer[rm], temp);
return 0;
}
int buildPerson(char* props)
{
int rm, x, y;
char filename[256];
if (sscanf(props, "room %u, sprite %[^,], x %d, y%d",
&rm, filename, &x, &y) != 4)
{
return 1;
}
printf("Building person...\n");
Player* temp = newPlayer(filename, x, y);
addPerson(mapBuffer[rm], temp);
return 0;
}
int countMapThings(char x, enum dataChunks chunk) int countMapThings(char x, enum dataChunks chunk)
{ {
int count = 0; int count = 0;

View file

@ -7,6 +7,12 @@ int buildRoom(char* props);
int buildWarp(char* props); int buildWarp(char* props);
int buildHyper(char* props);
int buildPerson(char* props);
int buildObstruction(char* props);
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

@ -2,4 +2,6 @@ mkRoom: slot 0, sprite assets/img/backgrounds/blueroom.png, spd 4
mkRoom: slot 1, sprite assets/img/backgrounds/darkroom.png, spd 4 mkRoom: slot 1, sprite assets/img/backgrounds/darkroom.png, spd 4
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
#addPerson: room 0, sprite assets/img/people/kmage.png, x 20, y 30 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