浏览代码

Add a debug sprite to the scene.

legacy
Sam Hocevar sam 14 年前
父节点
当前提交
e16f8d7804
共有 4 个文件被更改,包括 103 次插入1 次删除
  1. +2
    -1
      src/Makefile.am
  2. +64
    -0
      src/debugsprite.cpp
  3. +35
    -0
      src/debugsprite.h
  4. +2
    -0
      src/test-map.cpp

+ 2
- 1
src/Makefile.am 查看文件

@@ -8,7 +8,8 @@ libcommon_a_SOURCES = \
scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \
joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h \
forge.cpp forge.h video.cpp video.h timer.cpp timer.h \
profiler.cpp profiler.h debugfps.cpp debugfps.h
profiler.cpp profiler.h \
debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h
libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`

test_map_SOURCES = test-map.cpp sdlinput.cpp sdlinput.h


+ 64
- 0
src/debugsprite.cpp 查看文件

@@ -0,0 +1,64 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdio>

#include "debugsprite.h"
#include "game.h"
#include "tiler.h"

/*
* DebugSprite implementation class
*/

class DebugSpriteData
{
friend class DebugSprite;

private:
Game *game;
int tiler;
int frame;
};

/*
* Public DebugSprite class
*/

DebugSprite::DebugSprite(Game *game)
{
data = new DebugSpriteData();
data->game = game;
data->tiler = Tiler::Register("art/test/character-dress.png");
}

Asset::Group DebugSprite::GetGroup()
{
return GROUP_DEFAULT;
}

void DebugSprite::TickGame(float delta_time)
{
Asset::TickGame(delta_time);
}

void DebugSprite::TickRender(float delta_time)
{
Asset::TickRender(delta_time);

data->game->GetScene()->AddTile((data->tiler << 16) | 15, 300, 200, 200);
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 300, 232, 200);
}

DebugSprite::~DebugSprite()
{
Tiler::Deregister(data->tiler);
delete data;
}


+ 35
- 0
src/debugsprite.h 查看文件

@@ -0,0 +1,35 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// The DebugSprite class
// ---------------------
//

#if !defined __DH_DEBUGSPRITE_H__
#define __DH_DEBUGSPRITE_H__

#include "asset.h"
#include "game.h"

class DebugSpriteData;

class DebugSprite : public Asset
{
public:
DebugSprite(Game *game);
virtual ~DebugSprite();

protected:
virtual Group GetGroup();
virtual void TickGame(float delta_time);
virtual void TickRender(float delta_time);

private:
DebugSpriteData *data;
};

#endif // __DH_DEBUGSPRITE_H__


+ 2
- 0
src/test-map.cpp 查看文件

@@ -14,6 +14,7 @@

#include "sdlinput.h"
#include "debugfps.h"
#include "debugsprite.h"
#include "game.h"
#include "ticker.h"
#include "profiler.h"
@@ -51,6 +52,7 @@ int main(int argc, char **argv)
/* Register an input driver and some debug stuff */
new SdlInput(game);
new DebugFps();
new DebugSprite(game);

while (!game->Finished())
{


正在加载...
取消
保存