Atlas loading and testing.
This commit is contained in:
parent
0bbff1cb85
commit
28e7cbabd9
|
@ -15,7 +15,9 @@ SEARCHPATH += src/entities/structures
|
||||||
SEARCHPATH += src/entities/traps
|
SEARCHPATH += src/entities/traps
|
||||||
SEARCHPATH += src/game
|
SEARCHPATH += src/game
|
||||||
SEARCHPATH += src/hub
|
SEARCHPATH += src/hub
|
||||||
|
SEARCHPATH += src/json
|
||||||
SEARCHPATH += src/system
|
SEARCHPATH += src/system
|
||||||
|
SEARCHPATH += src/test
|
||||||
SEARCHPATH += src/util
|
SEARCHPATH += src/util
|
||||||
SEARCHPATH += src/widgets
|
SEARCHPATH += src/widgets
|
||||||
SEARCHPATH += src/world
|
SEARCHPATH += src/world
|
||||||
|
@ -25,7 +27,7 @@ vpath %.h $(SEARCHPATH)
|
||||||
|
|
||||||
DEPS += defs.h structs.h
|
DEPS += defs.h structs.h
|
||||||
|
|
||||||
OBJS += atlas.o
|
OBJS += atlas.o atlasTest.o
|
||||||
OBJS += battery.o blaze.o bob.o boss.o blobBoss.o
|
OBJS += battery.o blaze.o bob.o boss.o blobBoss.o
|
||||||
OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o consumable.o
|
OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o consumable.o
|
||||||
OBJS += debris.o destructable.o door.o draw.o
|
OBJS += debris.o destructable.o door.o draw.o
|
||||||
|
@ -34,6 +36,7 @@ OBJS += fleshChunk.o frost.o
|
||||||
OBJS += game.o
|
OBJS += game.o
|
||||||
OBJS += heart.o horizontalDoor.o horizontalLaserTrap.o hub.o hud.o
|
OBJS += heart.o horizontalDoor.o horizontalLaserTrap.o hub.o hud.o
|
||||||
OBJS += init.o infoPoint.o input.o io.o item.o items.o itemPad.o
|
OBJS += init.o infoPoint.o input.o io.o item.o items.o itemPad.o
|
||||||
|
OBJS += cJSON.o
|
||||||
OBJS += key.o keycard.o
|
OBJS += key.o keycard.o
|
||||||
OBJS += laserTrap.o lift.o lookup.o
|
OBJS += laserTrap.o lift.o lookup.o
|
||||||
OBJS += main.o map.o maths.o mia.o
|
OBJS += main.o map.o maths.o mia.o
|
||||||
|
|
|
@ -91,5 +91,5 @@ static void handleCommandLine(int argc, const char *argv[])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initTitle();
|
initAtlasTest();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern void handleInput(void);
|
||||||
extern void prepareScene(void);
|
extern void prepareScene(void);
|
||||||
extern void presentScene(void);
|
extern void presentScene(void);
|
||||||
extern void initTitle(void);
|
extern void initTitle(void);
|
||||||
|
extern void initAtlasTest(void);
|
||||||
|
|
||||||
App app;
|
App app;
|
||||||
Camera camera;
|
Camera camera;
|
||||||
|
|
|
@ -22,13 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
static void loadAtlasTexture(void);
|
static void loadAtlasTexture(void);
|
||||||
static void loadAtlasData(void);
|
static void loadAtlasData(void);
|
||||||
|
static void loadImageData(cJSON *root);
|
||||||
|
|
||||||
static Atlas atlasHead;
|
static Atlas atlasHead;
|
||||||
static Atlas *atlasTail;
|
static Atlas *atlasTail;
|
||||||
/*
|
static Texture *atlasTexture;
|
||||||
static Texture atlasTexture;
|
|
||||||
static int atlasSize;
|
static int atlasSize;
|
||||||
*/
|
|
||||||
|
|
||||||
void initAtlas(void)
|
void initAtlas(void)
|
||||||
{
|
{
|
||||||
|
@ -58,21 +57,50 @@ Atlas *getImageFromAtlas(char *filename)
|
||||||
|
|
||||||
static void loadAtlasTexture(void)
|
static void loadAtlasTexture(void)
|
||||||
{
|
{
|
||||||
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
|
||||||
|
SDL_QueryTexture(atlasTexture->texture, NULL, NULL, &atlasSize, &atlasSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadAtlasData(void)
|
static void loadAtlasData(void)
|
||||||
{
|
{
|
||||||
|
cJSON *root, *node;
|
||||||
|
char *text;
|
||||||
|
|
||||||
}
|
text = readFile("data/atlas/atlas.json");
|
||||||
|
|
||||||
void loadImageData(cJSON *root)
|
root = cJSON_Parse(text);
|
||||||
|
|
||||||
|
for (node = cJSON_GetObjectItem(root, "images")->child ; node != NULL ; node = node->next)
|
||||||
{
|
{
|
||||||
|
loadImageData(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createRectangle(char *filename, int x, int y, int w, int h)
|
cJSON_Delete(root);
|
||||||
|
|
||||||
|
free(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void loadImageData(cJSON *root)
|
||||||
{
|
{
|
||||||
|
Atlas *atlas;
|
||||||
|
char *filename;
|
||||||
|
int x, y, w, h;
|
||||||
|
|
||||||
|
filename = cJSON_GetObjectItem(root, "filename")->valuestring;
|
||||||
|
x = cJSON_GetObjectItem(root, "x")->valueint;
|
||||||
|
y = cJSON_GetObjectItem(root, "y")->valueint;
|
||||||
|
w = cJSON_GetObjectItem(root, "w")->valueint;
|
||||||
|
h = cJSON_GetObjectItem(root, "h")->valueint;
|
||||||
|
|
||||||
|
atlas = malloc(sizeof(Atlas));
|
||||||
|
memset(atlas, 0, sizeof(Atlas));
|
||||||
|
atlasTail->next = atlas;
|
||||||
|
atlasTail = atlas;
|
||||||
|
|
||||||
|
STRNCPY(atlas->filename, filename, MAX_FILENAME_LENGTH);
|
||||||
|
atlas->rect.x = x;
|
||||||
|
atlas->rect.y = y;
|
||||||
|
atlas->rect.w = w;
|
||||||
|
atlas->rect.h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../json/cJSON.h"
|
#include "../json/cJSON.h"
|
||||||
|
|
||||||
|
extern Texture *getTexture(const char *filename);
|
||||||
|
extern char *readFile(const char *filename);
|
||||||
|
|
|
@ -77,6 +77,24 @@ void blit(SDL_Texture *texture, int x, int y, int center)
|
||||||
SDL_RenderCopy(app.renderer, texture, NULL, &dstRect);
|
SDL_RenderCopy(app.renderer, texture, NULL, &dstRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center)
|
||||||
|
{
|
||||||
|
SDL_Rect dstRect;
|
||||||
|
|
||||||
|
dstRect.x = x;
|
||||||
|
dstRect.y = y;
|
||||||
|
dstRect.w = srcRect->w;
|
||||||
|
dstRect.h = srcRect->h;
|
||||||
|
|
||||||
|
if (center)
|
||||||
|
{
|
||||||
|
dstRect.x -= (dstRect.w / 2);
|
||||||
|
dstRect.y -= (dstRect.h / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderCopy(app.renderer, texture, srcRect, &dstRect);
|
||||||
|
}
|
||||||
|
|
||||||
void blitFlip(SDL_Texture *texture, int x, int y, int center, SDL_RendererFlip flip)
|
void blitFlip(SDL_Texture *texture, int x, int y, int center, SDL_RendererFlip flip)
|
||||||
{
|
{
|
||||||
SDL_Rect dstRect;
|
SDL_Rect dstRect;
|
||||||
|
|
|
@ -69,7 +69,8 @@ void initGameSystem(void)
|
||||||
void (*initFuncs[]) (void) = {
|
void (*initFuncs[]) (void) = {
|
||||||
initLookups,
|
initLookups,
|
||||||
initGraphics,
|
initGraphics,
|
||||||
initFonts
|
initFonts,
|
||||||
|
initAtlas
|
||||||
};
|
};
|
||||||
|
|
||||||
numInitFuns = sizeof(initFuncs) / sizeof(void*);
|
numInitFuns = sizeof(initFuncs) / sizeof(void*);
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern void createSaveFolder(void);
|
||||||
extern void initLookups(void);
|
extern void initLookups(void);
|
||||||
extern void initGraphics(void);
|
extern void initGraphics(void);
|
||||||
extern void initFonts(void);
|
extern void initFonts(void);
|
||||||
|
extern void initAtlas(void);
|
||||||
extern void destroyLookups(void);
|
extern void destroyLookups(void);
|
||||||
extern void destroyFonts(void);
|
extern void destroyFonts(void);
|
||||||
extern void destroyTextures(void);
|
extern void destroyTextures(void);
|
||||||
|
|
|
@ -67,7 +67,6 @@ static Texture *loadTexture(const char *filename)
|
||||||
return addTextureToCache(filename, texture);
|
return addTextureToCache(filename, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Texture *getTexture(const char *filename)
|
Texture *getTexture(const char *filename)
|
||||||
{
|
{
|
||||||
Texture *t;
|
Texture *t;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2018 Parallel Realities
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "atlasTest.h"
|
||||||
|
|
||||||
|
static void logic(void);
|
||||||
|
static void draw(void);
|
||||||
|
|
||||||
|
static Atlas *testImage;
|
||||||
|
static Texture *atlasTexture;
|
||||||
|
|
||||||
|
void initAtlasTest(void)
|
||||||
|
{
|
||||||
|
app.delegate.logic = &logic;
|
||||||
|
app.delegate.draw = &draw;
|
||||||
|
|
||||||
|
testImage = getImageFromAtlas("gfx/sprites/evilblobs/machineGunBlobRight1.png");
|
||||||
|
|
||||||
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void logic(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw(void)
|
||||||
|
{
|
||||||
|
blitRect(atlasTexture->texture, 0, 0, &testImage->rect, 0);
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2018 Parallel Realities
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
extern Atlas *getImageFromAtlas(char *filename);
|
||||||
|
extern Texture *getTexture(const char *filename);
|
||||||
|
extern void blit(SDL_Texture *texture, int x, int y, int center);
|
||||||
|
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||||
|
extern void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
|
||||||
|
|
||||||
|
extern App app;
|
|
@ -19,4 +19,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,6 @@ void addFlameParticles(float x, float y)
|
||||||
p->destroyAfterAnim = 1;
|
p->destroyAfterAnim = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void addExplosionParticles(float x, float y, float radius, int amount)
|
void addExplosionParticles(float x, float y, float radius, int amount)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -19,4 +19,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue