diff --git a/src/entities/blobs/bob.c b/src/entities/blobs/bob.c index ca46516..59a8c93 100644 --- a/src/entities/blobs/bob.c +++ b/src/entities/blobs/bob.c @@ -98,6 +98,9 @@ Entity *initBob(void) static void init(void) { changeSprite(walkSprite); + + world.bob->checkpoints[0].x = world.bob->x; + world.bob->checkpoints[0].y = world.bob->y; } static void tick(void) @@ -639,10 +642,10 @@ static SDL_Rect *getCurrentSprite(void) { if (world.bob->alive == ALIVE_ALIVE && world.bob->stunTimer <= 0) { - return &world.bob->sprite[world.bob->facing]->frames[0]->rect; + return &world.bob->sprite[world.bob->facing]->frames[world.bob->spriteFrame]->rect; } - return &world.bob->sprite[FACING_DIE]->frames[0]->rect; + return &world.bob->sprite[FACING_DIE]->frames[world.bob->spriteFrame]->rect; } static void animate(void) diff --git a/src/entities/blobs/bob.h b/src/entities/blobs/bob.h index d4a1ff5..f824623 100644 --- a/src/entities/blobs/bob.h +++ b/src/entities/blobs/bob.h @@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define FLY_ACCEL 0.1 #define FLY_SPEED 8 -extern Unit *createUnit(void); extern Sprite *getSprite(char *name); extern char *getLookupName(const char *prefix, long num); extern long lookup(const char *name); diff --git a/src/entities/boss/blobBoss.c b/src/entities/boss/blobBoss.c index c4cce7e..1dc6785 100644 --- a/src/entities/boss/blobBoss.c +++ b/src/entities/boss/blobBoss.c @@ -182,10 +182,10 @@ static SDL_Rect *getCurrentSprite(void) if (b->stunTimer > 0 || b->health <= 0) { - return &b->sprite[FACING_DIE]->frames[0]->rect; + return &b->sprite[FACING_DIE]->frames[self->spriteFrame]->rect; } - return &b->sprite[b->facing]->frames[0]->rect; + return &b->sprite[b->facing]->frames[self->spriteFrame]->rect; } static void animate(void) diff --git a/src/entities/boss/eyeDroidCommander.c b/src/entities/boss/eyeDroidCommander.c index 90ebac2..88305d6 100644 --- a/src/entities/boss/eyeDroidCommander.c +++ b/src/entities/boss/eyeDroidCommander.c @@ -386,8 +386,8 @@ static SDL_Rect *getCurrentSprite(void) { if (self->health <= 0) { - return &self->sprite[FACING_DIE]->frames[0]->rect; + return &self->sprite[FACING_DIE]->frames[self->spriteFrame]->rect; } - return &self->sprite[self->facing]->frames[0]->rect; + return &self->sprite[self->facing]->frames[self->spriteFrame]->rect; } diff --git a/src/entities/unit.c b/src/entities/unit.c index f60635f..a92eb01 100644 --- a/src/entities/unit.c +++ b/src/entities/unit.c @@ -50,6 +50,7 @@ Unit *createUnit(void) u->health = u->healthMax = rrnd(1, 4); } + u->spriteTime = 0; u->spriteFrame = 0; u->startX = u->startY = -1; @@ -232,10 +233,10 @@ static SDL_Rect *getCurrentSprite(void) { if (self->alive == ALIVE_ALIVE) { - return &self->sprite[self->facing]->frames[0]->rect; + return &self->sprite[self->facing]->frames[self->spriteFrame]->rect; } - return &self->sprite[FACING_DIE]->frames[0]->rect; + return &self->sprite[FACING_DIE]->frames[self->spriteFrame]->rect; } static void load(cJSON *root) diff --git a/src/system/init.c b/src/system/init.c index 4e27847..45cd469 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -30,7 +30,7 @@ void initSDL(void) app.winWidth = SCREEN_WIDTH; app.winHeight = SCREEN_HEIGHT; - rendererFlags = SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC; + rendererFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC; windowFlags = 0; diff --git a/src/system/sprites.c b/src/system/sprites.c index 2003ad2..4e80bfa 100644 --- a/src/system/sprites.c +++ b/src/system/sprites.c @@ -72,7 +72,7 @@ static void animateSprite(Sprite *s) if (s->currentTime <= 0) { - s->currentFrame = wrap(++s->currentFrame, 0, s->numFrames - 1); + s->currentFrame = wrap(s->currentFrame + 1, 0, s->numFrames - 1); s->currentTime = s->times[s->currentFrame]; } } diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index e34a6b5..d60bac6 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -20,20 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "atlasTest.h" -static void logic(void); -static void draw(void); - -static Texture *background; - void initAtlasTest(void) { initGame(); initHub(); - app.delegate.logic = &logic; - app.delegate.draw = &draw; - loadWorld("data/maps/beachApproach.json"); initWorld(); @@ -41,50 +33,4 @@ void initAtlasTest(void) initMap(); initEntities(); - - background = getTexture(world.background); - - cameraTrack(findEntity("Transmitter")); -} - -static void logic(void) -{ - doWorld(); - - doEntities(); - - doParticles(); - - if (app.keyboard[SDL_SCANCODE_UP]) - { - camera.y -= CAMERA_SCROLL_SPEED; - } - - if (app.keyboard[SDL_SCANCODE_DOWN]) - { - camera.y += CAMERA_SCROLL_SPEED; - } - - if (app.keyboard[SDL_SCANCODE_LEFT]) - { - camera.x -= CAMERA_SCROLL_SPEED; - } - - if (app.keyboard[SDL_SCANCODE_RIGHT]) - { - camera.x += CAMERA_SCROLL_SPEED; - } - - clipCamera(); -} - -static void draw(void) -{ - blitScaled(background->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); - - drawEntities(PLANE_BACKGROUND); - - drawMap(); - - drawEntities(PLANE_FOREGROUND); } diff --git a/src/test/atlasTest.h b/src/test/atlasTest.h index 2479142..e830add 100644 --- a/src/test/atlasTest.h +++ b/src/test/atlasTest.h @@ -20,25 +20,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" -#define CAMERA_SCROLL_SPEED 16 - extern void initWorld(void); extern void initMap(void); extern void initHub(void); extern void initGame(void); extern void initEntities(void); extern void loadWorld(char *filename); -extern void drawMap(void); -extern void drawEntities(int plane); -extern void cameraTrack(Entity *e); -extern void doEntities(void); -extern void doParticles(void); -extern void doWorld(void); -extern Entity *findEntity(char *name); -extern void clipCamera(void); -extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h, int center); -extern Texture *getTexture(const char *filename); -extern App app; -extern Camera camera; -extern World world; diff --git a/src/world/entities.c b/src/world/entities.c index 1a79426..b946760 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -44,11 +44,15 @@ void doEntities(void) void drawEntities(int plane) { - int x, y; + int x, y, draw; for (self = world.entityHead.next ; self != NULL ; self = self->next) { - if (self->plane == plane) + self->isOnScreen = 1; + + draw = self->isOnScreen && !(self->flags & EF_GONE) && self->plane == plane; + + if (draw) { x = (-camera.x + self->x); y = (-camera.y + self->y); diff --git a/src/world/world.c b/src/world/world.c index 809844d..51786d0 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "world.h" +static void logic(void); +static void draw(void); static void doWorldStart(void); static void doWorldInProgress(void); static void doWorldObserving(void); @@ -57,12 +59,19 @@ void initWorld(void) { game.missionsPlayed++; } + + world.bob->flags |= EF_GONE; + + app.delegate.logic = logic; + app.delegate.draw = draw; } -void doWorld(void) +static void logic(void) { - if (world.betweenTimer == 0) + if (--world.betweenTimer <= 0) { + world.betweenTimer = 0; + switch (world.state) { case WS_START: @@ -97,17 +106,47 @@ void doWorld(void) } } +static void draw(void) +{ + clearScreen(); + + if (world.betweenTimer == 0) + { + blitScaled(background->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); + + drawEntities(PLANE_BACKGROUND); + + drawMap(); + + drawEntities(PLANE_FOREGROUND); + } +} + void startMission(void) { world.state = WS_IN_PROGRESS; world.betweenTimer = FPS / 2; resetAtCheckpoint(); world.entityToTrack = (Entity*)world.bob; + world.bob->flags &= ~EF_GONE; } static void doWorldStart(void) { - if (world.entityToTrack == NULL) + float dist; + + if (world.entityToTrack != NULL) + { + dist = cameraChase(world.entityToTrack, 5); + + if ((dist <= world.entityToTrack->w && dist <= world.entityToTrack->h) || world.entityChaseTimer <= 0) + { + world.entityToTrack = getRandomObjectiveEntity(); + + world.entityChaseTimer = FPS * 5; + } + } + else { world.entityToTrack = getRandomObjectiveEntity(); @@ -115,12 +154,14 @@ static void doWorldStart(void) } world.entityChaseTimer = MAX(world.entityChaseTimer - 1, 0); - + doCommon(); } static void doWorldInProgress(void) { + cameraTrack(world.entityToTrack); + if (!world.showingInfoMessage) { doBob(); diff --git a/src/world/world.h b/src/world/world.h index 1c86d35..3950753 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -31,6 +31,7 @@ extern void dropCarriedItems(void); extern void playSound(int snd, int ch); extern void initEnding(void); extern void initTitle(void); +extern float cameraChase(Entity *e, int maxSpeed); extern int rrnd(int low, int high); extern void hideAllWidgets(void); extern void resetAtCheckpoint(void); @@ -48,7 +49,13 @@ extern void doHud(void); extern Entity *createEntity(char *typeStr); extern void dropRandomCherry(int x, int y); extern void addRandomWeapon(int x, int y); +extern void drawEntities(int plane); +extern void drawMap(void); +extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h, int center); +extern void clearScreen(void); +extern App app; +extern Camera camera; extern Dev dev; extern Game game; extern World world; diff --git a/src/world/worldLoader.c b/src/world/worldLoader.c index b111e9e..016b552 100644 --- a/src/world/worldLoader.c +++ b/src/world/worldLoader.c @@ -134,6 +134,8 @@ static void loadBob(cJSON *root) world.bob->load(root); world.bob->init(); + + world.bob->animate(); } static void loadEntities(cJSON *root) @@ -155,6 +157,8 @@ static void loadEntities(cJSON *root) self->load(node); self->init(); + + self->animate(); } }