source: trunk/deushax/debugsprite.cpp @ 633

Last change on this file since 633 was 633, checked in by sam, 10 years ago

TileSets can now be initialised either using the tile size, or the
known number of tiles in a row and a column. Necessary for ticket #24.

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11#include <cmath>
12
13#include "core.h"
14#include "debugsprite.h"
15
16/*
17 * DebugSprite implementation class
18 */
19
20class DebugSpriteData
21{
22    friend class DebugSprite;
23
24private:
25    Game *game;
26    int tiler;
27    float3 pos;
28};
29
30/*
31 * Public DebugSprite class
32 */
33
34DebugSprite::DebugSprite(Game *game)
35  : data(new DebugSpriteData())
36{
37    data->game = game;
38    Ticker::Ref(game);
39    data->tiler = Tiler::Register("art/test/character-dress.png",
40                                  32, 0, sqrtf(2));
41    data->pos = float3(320, 206, 0);
42}
43
44void DebugSprite::TickGame(float deltams)
45{
46    Entity::TickGame(deltams);
47
48    float3 move = deltams * (float3)Input::GetAxis(0);
49    data->pos = data->pos + move * float3(0.1f * sqrtf(2.0f), .1f, 0.1f);
50}
51
52void DebugSprite::TickDraw(float deltams)
53{
54    Entity::TickDraw(deltams);
55
56    int3 pos = (int3)data->pos;
57
58    Scene::GetDefault()->AddTile((data->tiler << 16) | 31,
59                                 pos.x - 16, pos.y, pos.z, 1);
60    Scene::GetDefault()->AddTile((data->tiler << 16) | 15,
61                                 pos.x - 16, pos.y, pos.z + 32, 1);
62}
63
64DebugSprite::~DebugSprite()
65{
66    Ticker::Unref(data->game);
67    Tiler::Deregister(data->tiler);
68    delete data;
69}
70
Note: See TracBrowser for help on using the repository browser.