source: trunk/deushax/debugsprite.cpp @ 289

Last change on this file since 289 was 289, checked in by sam, 11 years ago

Change the way the Scene object works.

  • 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    float x, y, z;
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, 32, sqrtf(2));
41    data->x = 320;
42    data->y = 206;
43    data->z = 0;
44}
45
46void DebugSprite::TickGame(float deltams)
47{
48    Entity::TickGame(deltams);
49
50    Float2 axis = Input::GetAxis(0);
51    data->x += 0.1f * sqrtf(2.0f) * deltams * axis.x;
52    data->y += 0.1f * deltams * axis.y;
53}
54
55void DebugSprite::TickDraw(float deltams)
56{
57    Entity::TickDraw(deltams);
58
59    int x = data->x;
60    int y = data->y;
61    int z = data->z;
62
63    Scene::GetDefault()->AddTile((data->tiler << 16) | 31,
64                                 x - 16, y, z, 1);
65    Scene::GetDefault()->AddTile((data->tiler << 16) | 15,
66                                 x - 16, y, z + 32, 1);
67}
68
69DebugSprite::~DebugSprite()
70{
71    Ticker::Unref(data->game);
72    Tiler::Deregister(data->tiler);
73    delete data;
74}
75
Note: See TracBrowser for help on using the repository browser.