Animation and drawing updates.
This commit is contained in:
parent
aba616b085
commit
0872a3b82b
|
@ -53,6 +53,9 @@ void initEntity(Entity *e)
|
||||||
|
|
||||||
e->thinkTime = 0;
|
e->thinkTime = 0;
|
||||||
|
|
||||||
|
e->spriteFrame = -1;
|
||||||
|
e->spriteTime = 0;
|
||||||
|
|
||||||
e->init = init;
|
e->init = init;
|
||||||
e->reset = reset;
|
e->reset = reset;
|
||||||
e->action = action;
|
e->action = action;
|
||||||
|
@ -109,7 +112,7 @@ static void animate(void)
|
||||||
|
|
||||||
self->spriteFrame++;
|
self->spriteFrame++;
|
||||||
|
|
||||||
if (self->spriteFrame > s->numFrames)
|
if (self->spriteFrame >= s->numFrames)
|
||||||
{
|
{
|
||||||
self->spriteFrame = 0;
|
self->spriteFrame = 0;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +165,7 @@ static void touch(Entity *other)
|
||||||
|
|
||||||
static SDL_Rect *getCurrentSprite(void)
|
static SDL_Rect *getCurrentSprite(void)
|
||||||
{
|
{
|
||||||
return &self->sprite[self->facing]->frames[0]->rect;
|
return &self->sprite[self->facing]->frames[self->spriteFrame]->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load(cJSON *root)
|
static void load(cJSON *root)
|
||||||
|
|
|
@ -449,6 +449,7 @@ typedef struct {
|
||||||
int isReturnVisit;
|
int isReturnVisit;
|
||||||
int missionCompleteTimer;
|
int missionCompleteTimer;
|
||||||
int betweenTimer;
|
int betweenTimer;
|
||||||
|
int mapAnimTimer;
|
||||||
Quadtree quadtree;
|
Quadtree quadtree;
|
||||||
Entity entityHead, *entityTail;
|
Entity entityHead, *entityTail;
|
||||||
Particle particleHead, *particleTail;
|
Particle particleHead, *particleTail;
|
||||||
|
|
|
@ -20,15 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "atlasTest.h"
|
#include "atlasTest.h"
|
||||||
|
|
||||||
static Entity *track;
|
|
||||||
static void logic(void);
|
static void logic(void);
|
||||||
static void draw(void);
|
static void draw(void);
|
||||||
static int timeout;
|
|
||||||
static void trackRandomEntity(void);
|
static Texture *background;
|
||||||
|
|
||||||
void initAtlasTest(void)
|
void initAtlasTest(void)
|
||||||
{
|
{
|
||||||
initGame();
|
initGame();
|
||||||
|
|
||||||
initHub();
|
initHub();
|
||||||
|
|
||||||
app.delegate.logic = &logic;
|
app.delegate.logic = &logic;
|
||||||
|
@ -36,45 +36,55 @@ void initAtlasTest(void)
|
||||||
|
|
||||||
loadWorld("data/maps/beachApproach.json");
|
loadWorld("data/maps/beachApproach.json");
|
||||||
|
|
||||||
|
initWorld();
|
||||||
|
|
||||||
initMap();
|
initMap();
|
||||||
|
|
||||||
initEntities();
|
initEntities();
|
||||||
|
|
||||||
timeout = FPS;
|
background = getTexture(world.background);
|
||||||
|
|
||||||
track = &world.entityHead;
|
cameraTrack(findEntity("Transmitter"));
|
||||||
|
|
||||||
cameraTrack(track);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void logic(void)
|
static void logic(void)
|
||||||
{
|
{
|
||||||
|
doWorld();
|
||||||
|
|
||||||
doEntities();
|
doEntities();
|
||||||
|
|
||||||
doParticles();
|
doParticles();
|
||||||
|
|
||||||
if (--timeout <= 0)
|
if (app.keyboard[SDL_SCANCODE_UP])
|
||||||
{
|
{
|
||||||
trackRandomEntity();
|
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)
|
static void draw(void)
|
||||||
{
|
{
|
||||||
|
blitScaled(background->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
|
||||||
|
|
||||||
|
drawEntities(PLANE_BACKGROUND);
|
||||||
|
|
||||||
drawMap();
|
drawMap();
|
||||||
|
|
||||||
drawEntities();
|
drawEntities(PLANE_FOREGROUND);
|
||||||
}
|
|
||||||
|
|
||||||
static void trackRandomEntity(void)
|
|
||||||
{
|
|
||||||
track = track->next;
|
|
||||||
|
|
||||||
if (track == NULL)
|
|
||||||
{
|
|
||||||
track = (Entity*)world.bob;
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraTrack(track);
|
|
||||||
timeout = FPS;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
|
#define CAMERA_SCROLL_SPEED 16
|
||||||
|
|
||||||
|
extern void initWorld(void);
|
||||||
extern void initMap(void);
|
extern void initMap(void);
|
||||||
extern void initHub(void);
|
extern void initHub(void);
|
||||||
extern void initGame(void);
|
extern void initGame(void);
|
||||||
extern void initEntities(void);
|
extern void initEntities(void);
|
||||||
extern void loadWorld(char *filename);
|
extern void loadWorld(char *filename);
|
||||||
extern void drawMap(void);
|
extern void drawMap(void);
|
||||||
extern void drawEntities(void);
|
extern void drawEntities(int plane);
|
||||||
extern void cameraTrack(Entity *e);
|
extern void cameraTrack(Entity *e);
|
||||||
extern void doEntities(void);
|
extern void doEntities(void);
|
||||||
extern void doParticles(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 App app;
|
||||||
|
extern Camera camera;
|
||||||
extern World world;
|
extern World world;
|
||||||
|
|
|
@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
|
||||||
static void clip(void);
|
void clipCamera(void);
|
||||||
|
|
||||||
void cameraTrack(Entity *e)
|
void cameraTrack(Entity *e)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ void cameraTrack(Entity *e)
|
||||||
camera.x -= (SCREEN_WIDTH / 2);
|
camera.x -= (SCREEN_WIDTH / 2);
|
||||||
camera.y -= (SCREEN_HEIGHT / 2);
|
camera.y -= (SCREEN_HEIGHT / 2);
|
||||||
|
|
||||||
clip();
|
clipCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
float cameraChase(Entity *e, int maxSpeed)
|
float cameraChase(Entity *e, int maxSpeed)
|
||||||
|
@ -77,12 +77,12 @@ float cameraChase(Entity *e, int maxSpeed)
|
||||||
camera.x = (int) x;
|
camera.x = (int) x;
|
||||||
camera.y = (int) y;
|
camera.y = (int) y;
|
||||||
|
|
||||||
clip();
|
clipCamera();
|
||||||
|
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clip(void)
|
void clipCamera(void)
|
||||||
{
|
{
|
||||||
camera.x = (int) limit(camera.x, world.map.bounds.x, world.map.bounds.w);
|
camera.x = (int) limit(camera.x, world.map.bounds.x, world.map.bounds.w);
|
||||||
camera.y = (int) limit(camera.y, world.map.bounds.y, world.map.bounds.h);
|
camera.y = (int) limit(camera.y, world.map.bounds.y, world.map.bounds.h);
|
||||||
|
|
|
@ -31,25 +31,30 @@ void doEntities(void)
|
||||||
{
|
{
|
||||||
for (self = world.entityHead.next ; self != NULL ; self = self->next)
|
for (self = world.entityHead.next ; self != NULL ; self = self->next)
|
||||||
{
|
{
|
||||||
self->tick();
|
|
||||||
|
|
||||||
if (--self->thinkTime <= 0)
|
if (--self->thinkTime <= 0)
|
||||||
{
|
{
|
||||||
self->action();
|
self->action();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->tick();
|
||||||
|
|
||||||
|
self->animate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawEntities(void)
|
void drawEntities(int plane)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
for (self = world.entityHead.next ; self != NULL ; self = self->next)
|
for (self = world.entityHead.next ; self != NULL ; self = self->next)
|
||||||
{
|
{
|
||||||
x = (-camera.x + self->x);
|
if (self->plane == plane)
|
||||||
y = (-camera.y + self->y);
|
{
|
||||||
|
x = (-camera.x + self->x);
|
||||||
|
y = (-camera.y + self->y);
|
||||||
|
|
||||||
blitRect(atlasTexture->texture, x, y, self->getCurrentSprite(), 0);
|
blitRect(atlasTexture->texture, x, y, self->getCurrentSprite(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,3 +99,18 @@ void teleport(Entity *e, float tx, float ty)
|
||||||
|
|
||||||
addTeleportStars(e);
|
addTeleportStars(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entity *findEntity(char *name)
|
||||||
|
{
|
||||||
|
Entity *e;
|
||||||
|
|
||||||
|
for (e = world.entityHead.next ; e != NULL ; e = e->next)
|
||||||
|
{
|
||||||
|
if (strcmp(e->name, name) == 0)
|
||||||
|
{
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ static void loadTileset(void);
|
||||||
static void loadDecals(void);
|
static void loadDecals(void);
|
||||||
static SDL_Rect *loadTile(char *filename);
|
static SDL_Rect *loadTile(char *filename);
|
||||||
|
|
||||||
static int animTimer;
|
|
||||||
static int MAX_Y;
|
static int MAX_Y;
|
||||||
static Texture *atlasTexture;
|
static Texture *atlasTexture;
|
||||||
static SDL_Rect *tiles[MAP_TILE_MAX];
|
static SDL_Rect *tiles[MAP_TILE_MAX];
|
||||||
|
@ -41,8 +40,6 @@ void initMap(void)
|
||||||
world.map.bounds.w = 0;
|
world.map.bounds.w = 0;
|
||||||
world.map.bounds.h = 0;
|
world.map.bounds.h = 0;
|
||||||
|
|
||||||
animTimer = 0;
|
|
||||||
|
|
||||||
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
|
||||||
loadMapData();
|
loadMapData();
|
||||||
|
@ -77,7 +74,7 @@ void drawMap(void)
|
||||||
{
|
{
|
||||||
tile = world.map.data[mx][my];
|
tile = world.map.data[mx][my];
|
||||||
|
|
||||||
if (animTimer == 0)
|
if (world.mapAnimTimer == 0)
|
||||||
{
|
{
|
||||||
if (tile >= MAP_TILE_ANIMATED_WATER && tile < MAP_TILE_ANIMATED_SLIME)
|
if (tile >= MAP_TILE_ANIMATED_WATER && tile < MAP_TILE_ANIMATED_SLIME)
|
||||||
{
|
{
|
||||||
|
@ -97,6 +94,11 @@ void drawMap(void)
|
||||||
|
|
||||||
if (tile != MAP_TILE_AIR)
|
if (tile != MAP_TILE_AIR)
|
||||||
{
|
{
|
||||||
|
if (tile >= MAP_TILE_SOLID && tile < MAP_TILE_NON_SOLID)
|
||||||
|
{
|
||||||
|
blitRect(atlasTexture->texture, x + 2, y + 2, tiles[MAP_TILE_OUTSIDE], 0);
|
||||||
|
}
|
||||||
|
|
||||||
blitRect(atlasTexture->texture, x, y, tiles[tile], 0);
|
blitRect(atlasTexture->texture, x, y, tiles[tile], 0);
|
||||||
|
|
||||||
decal = world.map.decal[mx][my];
|
decal = world.map.decal[mx][my];
|
||||||
|
@ -120,14 +122,6 @@ void drawMap(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void animateMap(void)
|
|
||||||
{
|
|
||||||
if (--animTimer < 0)
|
|
||||||
{
|
|
||||||
animTimer = 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int isWithinMap(int x, int y)
|
int isWithinMap(int x, int y)
|
||||||
{
|
{
|
||||||
return (x >= 0 && y >= 0 && x < MAP_WIDTH && y < MAP_HEIGHT);
|
return (x >= 0 && y >= 0 && x < MAP_WIDTH && y < MAP_HEIGHT);
|
||||||
|
|
|
@ -20,6 +20,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
|
static Texture *background;
|
||||||
|
|
||||||
|
void initWorld(void)
|
||||||
|
{
|
||||||
|
background = getTexture(world.background);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doWorld(void)
|
||||||
|
{
|
||||||
|
if (--world.mapAnimTimer < 0)
|
||||||
|
{
|
||||||
|
world.mapAnimTimer = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void observeActivation(Entity *e)
|
void observeActivation(Entity *e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,3 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
|
extern Texture *getTexture(const char *filename);
|
||||||
|
|
||||||
|
extern World world;
|
||||||
|
|
Loading…
Reference in New Issue