From b8aa4602213e360f9d8a65a660e5e4fed4ec3332 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 3 Feb 2018 13:07:56 +0000 Subject: [PATCH] Basic movement. Various bug fixes. --- src/entities/blobs/bob.c | 2 ++ src/entities/structures/door.c | 7 ++++--- src/main.c | 8 +++++--- src/main.h | 1 + src/system/init.c | 26 ++++++++++++++++++++++++++ src/system/init.h | 3 +++ src/world/entities.c | 10 ++++++++-- src/world/hud.c | 11 ++++++++++- src/world/world.c | 8 ++++++++ 9 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/entities/blobs/bob.c b/src/entities/blobs/bob.c index 59a8c93..5843c88 100644 --- a/src/entities/blobs/bob.c +++ b/src/entities/blobs/bob.c @@ -101,6 +101,8 @@ static void init(void) world.bob->checkpoints[0].x = world.bob->x; world.bob->checkpoints[0].y = world.bob->y; + + superAnimate(); } static void tick(void) diff --git a/src/entities/structures/door.c b/src/entities/structures/door.c index b46246e..7038816 100644 --- a/src/entities/structures/door.c +++ b/src/entities/structures/door.c @@ -176,7 +176,7 @@ static void touch(Entity *other) { return; } - + if (s->isLocked && !dev.cheatKeys) { if (isClosed()) @@ -201,7 +201,7 @@ static void touch(Entity *other) return; } } - + if (s->state != DOOR_OPEN) { playSound(SND_DOOR_START, CH_MECHANICAL); @@ -272,7 +272,8 @@ static void load(cJSON *root) s = (Structure*)self; - s->active = cJSON_GetObjectItem(root, "isLocked")->valueint; + s->isLocked = cJSON_GetObjectItem(root, "isLocked")->valueint; + s->active = s->isLocked; if (cJSON_GetObjectItem(root, "requiredKey")) { STRNCPY(s->requiredItem, cJSON_GetObjectItem(root, "requiredKey")->valuestring, MAX_NAME_LENGTH); diff --git a/src/main.c b/src/main.c index 53a4fb5..8b0c9f9 100644 --- a/src/main.c +++ b/src/main.c @@ -21,9 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "main.h" static long capFrameRate(const long then); -static void handleCommandLine(int argc, const char *argv[]); +static void handleCommandLine(int argc, char *argv[]); -int main(int argc, const char *argv[]) +int main(int argc, char *argv[]) { long then, nextSecond, frames; @@ -31,6 +31,8 @@ int main(int argc, const char *argv[]) srand(time(NULL)); + init18N(argc, argv); + initSDL(); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); @@ -90,7 +92,7 @@ static long capFrameRate(const long then) return SDL_GetTicks(); } -static void handleCommandLine(int argc, const char *argv[]) +static void handleCommandLine(int argc, char *argv[]) { int i; diff --git a/src/main.h b/src/main.h index 6d2a9ad..48c2b54 100644 --- a/src/main.h +++ b/src/main.h @@ -28,6 +28,7 @@ extern void handleInput(void); extern void prepareScene(void); extern void presentScene(void); extern void initAtlasTest(void); +extern void init18N(int argc, char *argv[]); App app; Camera camera; diff --git a/src/system/init.c b/src/system/init.c index 45cd469..4ebac9d 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -20,6 +20,32 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "init.h" +void init18N(int argc, char *argv[]) +{ + int i; + int languageId = -1; + + setlocale(LC_NUMERIC, ""); + + for (i = 1 ; i < argc ; i++) + { + if (strcmp(argv[i], "-language") == 0) + { + languageId = i + 1; + + if (languageId >= argc) + { + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "You must specify a language to use with -language. Using default."); + } + } + } + + setLanguage("blobwarsAttrition", languageId == -1 ? NULL : argv[languageId]); + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Numeric is %s", setlocale(LC_NUMERIC, "C")); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "atof(2.75) is %f", atof("2.75")); +} + void initSDL(void) { int rendererFlags, windowFlags; diff --git a/src/system/init.h b/src/system/init.h index 0427ac1..98eaa2c 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -24,7 +24,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "SDL2/SDL_mixer.h" #include "SDL2/SDL_ttf.h" +#include "locale.h" + extern void createSaveFolder(void); +extern void setLanguage(char *applicationName, char *languageCode); extern void initLookups(void); extern void initGraphics(void); extern void initFonts(void); diff --git a/src/world/entities.c b/src/world/entities.c index ccb8327..6e106e6 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -57,7 +57,7 @@ void initEntities(void) void doEntities(void) { - Entity *prev; + Entity *prev, *oldSelf; int camMidX, camMidY, flicker, i; memset(riders, 0, sizeof(Entity*) * MAX_RIDERS); @@ -143,7 +143,13 @@ void doEntities(void) if (touched[i]->isStatic) { - touched[i]->touch(self); /* for objects that never move */ + oldSelf = self; + + self = touched[i]; + + touched[i]->touch(oldSelf); /* for objects that never move */ + + self = oldSelf; } } } diff --git a/src/world/hud.c b/src/world/hud.c index 616414c..0565853 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -44,8 +44,17 @@ void doHud(void) } } -void setGameplayMessage(char *newMessage, int newMessageType) +void setGameplayMessage(int newMessageType, const char *format, ...) { + char newMessage[MAX_DESCRIPTION_LENGTH]; + va_list args; + + memset(&newMessage, '\0', sizeof(newMessage)); + + va_start(args, format); + vsprintf(newMessage, format, args); + va_end(args); + if (newMessageType >= messageType && newMessage != NULL) { STRNCPY(message, newMessage, MAX_DESCRIPTION_LENGTH); diff --git a/src/world/world.c b/src/world/world.c index 71b4bda..aa08516 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -63,6 +63,8 @@ void initWorld(void) app.delegate.logic = logic; app.delegate.draw = draw; + + startMission(); } static void logic(void) @@ -161,6 +163,12 @@ static void doWorldInProgress(void) { cameraTrack(world.entityToTrack); + game.config.control[CONTROL_LEFT] = app.keyboard[SDL_SCANCODE_A]; + game.config.control[CONTROL_RIGHT] = app.keyboard[SDL_SCANCODE_D]; + game.config.control[CONTROL_UP] = app.keyboard[SDL_SCANCODE_W]; + game.config.control[CONTROL_DOWN] = app.keyboard[SDL_SCANCODE_S]; + game.config.control[CONTROL_JUMP] = app.keyboard[SDL_SCANCODE_I]; + if (!world.showingInfoMessage) { doBob();