with the Monsterz tiles.legacy
@@ -11,7 +11,7 @@ libcommon_a_SOURCES = \ | |||
profiler.cpp profiler.h input.h input.cpp world.cpp world.h \ | |||
debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \ | |||
debugrecord.cpp debugrecord.h debugstats.cpp debugstats.h \ | |||
debugsphere.cpp debugsphere.h | |||
debugsphere.cpp debugsphere.h debugboard.cpp debugboard.h | |||
libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | |||
test_map_SOURCES = test-map.cpp sdlinput.cpp sdlinput.h | |||
@@ -0,0 +1,74 @@ | |||
// | |||
// Deus Hax (working title) | |||
// Copyright (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
// | |||
#if defined HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include <cstdio> | |||
#include <cmath> | |||
#include "core.h" | |||
#include "debugboard.h" | |||
/* | |||
* DebugBoard implementation class | |||
*/ | |||
class DebugBoardData | |||
{ | |||
friend class DebugBoard; | |||
private: | |||
Game *game; | |||
int tiler; | |||
float x, y, z; | |||
}; | |||
/* | |||
* Public DebugBoard class | |||
*/ | |||
DebugBoard::DebugBoard(Game *game) | |||
{ | |||
data = new DebugBoardData(); | |||
data->game = game; | |||
Ticker::Ref(game); | |||
data->tiler = Tiler::Register("monsterz/tiles.png", 48); | |||
data->x = 32; | |||
data->y = 0; | |||
data->z = 112; | |||
} | |||
void DebugBoard::TickGame(float deltams) | |||
{ | |||
Entity::TickGame(deltams); | |||
} | |||
void DebugBoard::TickDraw(float deltams) | |||
{ | |||
Entity::TickDraw(deltams); | |||
int x = data->x; | |||
int y = data->y; | |||
int z = data->z; | |||
for (int j = 0; j < 8; j++) | |||
for (int i = 0; i < 8; i++) | |||
{ | |||
int id = 28 + ((i + 3) * (j + 1) % 10) * 3 + ((i ^ (j + 2)) % 5); | |||
id += (id % 5) / 4; | |||
data->game->GetScene()->AddTile((data->tiler << 16) | id, | |||
x + i * 48 - 16, y + j * 48, z, 1); | |||
} | |||
} | |||
DebugBoard::~DebugBoard() | |||
{ | |||
Ticker::Unref(data->game); | |||
Tiler::Deregister(data->tiler); | |||
delete data; | |||
} | |||
@@ -0,0 +1,34 @@ | |||
// | |||
// Deus Hax (working title) | |||
// Copyright (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
// | |||
// | |||
// The DebugBoard class | |||
// -------------------- | |||
// | |||
#if !defined __DH_DEBUGBOARD_H__ | |||
#define __DH_DEBUGBOARD_H__ | |||
#include "entity.h" | |||
#include "game.h" | |||
class DebugBoardData; | |||
class DebugBoard : public Entity | |||
{ | |||
public: | |||
DebugBoard(Game *game); | |||
virtual ~DebugBoard(); | |||
protected: | |||
virtual void TickGame(float deltams); | |||
virtual void TickDraw(float deltams); | |||
private: | |||
DebugBoardData *data; | |||
}; | |||
#endif // __DH_DEBUGBOARD_H__ | |||
@@ -36,7 +36,7 @@ DebugSprite::DebugSprite(Game *game) | |||
data = new DebugSpriteData(); | |||
data->game = game; | |||
Ticker::Ref(game); | |||
data->tiler = Tiler::Register("art/test/character-dress.png"); | |||
data->tiler = Tiler::Register("art/test/character-dress.png", 32); | |||
data->x = 320; | |||
data->y = 206; | |||
data->z = 0; | |||
@@ -121,7 +121,7 @@ Map::Map(char const *path) | |||
else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1) | |||
{ | |||
/* This is a tileset image file. Associate it with firstgid. */ | |||
data->tilers[data->ntilers] = Tiler::Register(str); | |||
data->tilers[data->ntilers] = Tiler::Register(str, 32); | |||
data->ntilers++; | |||
//fprintf(stderr, "new tiler %s\n", str); | |||
} | |||
@@ -9,12 +9,16 @@ | |||
#include <cstdio> | |||
#include <cmath> | |||
#if defined _WIN32 | |||
# include <direct.h> | |||
#endif | |||
#include <SDL.h> | |||
#include "core.h" | |||
#include "sdlinput.h" | |||
#include "debugfps.h" | |||
#include "debugboard.h" | |||
#include "debugsprite.h" | |||
#include "debugsphere.h" | |||
#include "debugrecord.h" | |||
@@ -49,12 +53,17 @@ int main(int argc, char **argv) | |||
Video::Setup(video->w, video->h); | |||
/* Create a game */ | |||
#if defined _WIN32 | |||
_chdir(".."); /* Temporary Win32 hack */ | |||
#endif | |||
Game *game = new Game("maps/testmap.tmx"); | |||
game->SetMouse(160, 96); | |||
/* Register an input driver and some debug stuff */ | |||
new SdlInput(); | |||
new DebugFps(); | |||
new DebugSprite(game); | |||
new DebugBoard(game); | |||
new DebugSphere(); | |||
//new DebugRecord("lolengine.ogg"); | |||
new DebugStats("stats.txt"); | |||
@@ -28,13 +28,13 @@ static TilerData * const data = &tilerdata; | |||
* Public Tiler class | |||
*/ | |||
int Tiler::Register(char const *path) | |||
int Tiler::Register(char const *path, int size) | |||
{ | |||
int id = data->tilesets.MakeSlot(path); | |||
if (!data->tilesets.GetEntity(id)) | |||
{ | |||
TileSet *tileset = new TileSet(path); | |||
TileSet *tileset = new TileSet(path, size); | |||
data->tilesets.SetEntity(id, tileset); | |||
} | |||
@@ -17,7 +17,7 @@ | |||
class Tiler | |||
{ | |||
public: | |||
static int Register(char const *path); | |||
static int Register(char const *path, int size); | |||
static void Deregister(int id); | |||
static void BlitTile(uint32_t code, int x, int y, int z, int o); | |||
@@ -37,7 +37,7 @@ class TileSetData | |||
private: | |||
char *name; | |||
int *tiles; | |||
int nw, nh, ntiles; | |||
int size, nw, nh, ntiles; | |||
float tx, ty; | |||
SDL_Surface *img; | |||
@@ -48,7 +48,7 @@ private: | |||
* Public TileSet class | |||
*/ | |||
TileSet::TileSet(char const *path) | |||
TileSet::TileSet(char const *path, int size) | |||
{ | |||
data = new TileSetData(); | |||
data->name = strdup(path); | |||
@@ -66,11 +66,15 @@ TileSet::TileSet(char const *path) | |||
exit(1); | |||
} | |||
data->nw = data->img->w / 32; | |||
data->nh = data->img->h / 32; | |||
if (size <= 0) | |||
size = 32; | |||
data->size = size; | |||
data->nw = data->img->w / size; | |||
data->nh = data->img->h / size; | |||
data->ntiles = data->nw * data->nh; | |||
data->tx = 32.0f / data->img->w; | |||
data->ty = 32.0f / data->img->h; | |||
data->tx = (float)size / data->img->w; | |||
data->ty = (float)size / data->img->h; | |||
drawgroup = DRAWGROUP_BEFORE; | |||
} | |||
@@ -120,20 +124,23 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o) | |||
float ty = data->ty * ((id & 0xffff) / data->nw); | |||
float sqrt2 = sqrtf(2.0f); | |||
int off = o ? 32 : 0; | |||
int off = o ? data->size : 0; | |||
int dx = data->size; | |||
int dy = data->size * 38 / 32; /* Magic... fix this one day */ | |||
int dy2 = data->size * 70 / 32; | |||
if (!data->img) | |||
{ | |||
glBindTexture(GL_TEXTURE_2D, data->texture); | |||
glBegin(GL_QUADS); | |||
glTexCoord2f(tx, ty); | |||
glVertex3f(x, sqrt2 * (y - 38 - off), sqrt2 * (z + off)); | |||
glVertex3f(x, sqrt2 * (y - dy - off), sqrt2 * (z + off)); | |||
glTexCoord2f(tx + data->tx, ty); | |||
glVertex3f(x + 32, sqrt2 * (y - 38 - off), sqrt2 * (z + off)); | |||
glVertex3f(x + dx, sqrt2 * (y - dy - off), sqrt2 * (z + off)); | |||
glTexCoord2f(tx + data->tx, ty + data->ty); | |||
glVertex3f(x + 32, sqrt2 * (y - 70), sqrt2 * z); | |||
glVertex3f(x + dx, sqrt2 * (y - dy2), sqrt2 * z); | |||
glTexCoord2f(tx, ty + data->ty); | |||
glVertex3f(x, sqrt2 * (y - 70), sqrt2 * z); | |||
glVertex3f(x, sqrt2 * (y - dy2), sqrt2 * z); | |||
glEnd(); | |||
} | |||
} | |||
@@ -23,7 +23,7 @@ class TileSetData; | |||
class TileSet : public Entity | |||
{ | |||
public: | |||
TileSet(char const *path); | |||
TileSet(char const *path, int size); | |||
virtual ~TileSet(); | |||
protected: | |||