From 5fc726bcdb25957a1cd37c92a245b7f9f8b8d16c Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Fri, 8 Feb 2019 14:38:55 -0800 Subject: [PATCH] working on world data interpreter --- WorldData.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++----- WorldData.h | 6 ++++++ mapdata/1.txt | 4 +++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/WorldData.c b/WorldData.c index b64678e..0995266 100644 --- a/WorldData.c +++ b/WorldData.c @@ -117,17 +117,19 @@ int worldBuilder(enum dataChunks chunk) // buildSynergy(propsBuffer); break; case 47: //addPerson -// buildPerson(propsBuffer); + buildPerson(propsBuffer); break; case 88: //addObstruction -// buildObstruction(propsBuffer); + buildObstruction(propsBuffer); break; case 141: //addImg // buildFGImage(propsBuffer); break; case 240: //addTrigger -// buildHyper(propsBuffer); + buildHyper(propsBuffer); break; + case 148: //chainKaos + //chainKaos(propsBuffer); case 238: //addWarp buildWarp(propsBuffer); break; @@ -144,7 +146,7 @@ int buildRoom(char* props) char filename[256]; 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; } @@ -153,18 +155,62 @@ int buildRoom(char* props) 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 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) { return 1; } + printf("Building warp...\n"); addWarp(mapBuffer[r], x, y, w, h, dC, dR, dX, dY); 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 count = 0; diff --git a/WorldData.h b/WorldData.h index 7c23179..bf074f6 100644 --- a/WorldData.h +++ b/WorldData.h @@ -7,6 +7,12 @@ int buildRoom(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); void unloadData(enum dataChunks chunk); diff --git a/mapdata/1.txt b/mapdata/1.txt index 47e341e..2ccc03d 100644 --- a/mapdata/1.txt +++ b/mapdata/1.txt @@ -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 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 -#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