Various bug fixes.
This commit is contained in:
parent
3c7b3b5170
commit
383c8c19a3
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
@ -121,6 +160,8 @@ static void doWorldStart(void)
|
|||
|
||||
static void doWorldInProgress(void)
|
||||
{
|
||||
cameraTrack(world.entityToTrack);
|
||||
|
||||
if (!world.showingInfoMessage)
|
||||
{
|
||||
doBob();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue