source: trunk/src/debugsprite.cpp @ 170

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

Properly implement program termination, including in the GTK program.

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 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{
36    data = new DebugSpriteData();
37    data->game = game;
38    Ticker::Ref(game);
39    data->tiler = Tiler::Register("art/test/character-dress.png");
40    data->x = 320;
41    data->y = 206;
42    data->z = 0;
43}
44
45Entity::Group DebugSprite::GetGroup()
46{
47    return GROUP_DEFAULT;
48}
49
50void DebugSprite::TickGame(float deltams)
51{
52    Entity::TickGame(deltams);
53
54    Float2 axis = Input::GetAxis(0);
55    data->x += 0.1f * sqrtf(2.0f) * deltams * axis.x;
56    data->y += 0.1f * deltams * axis.y;
57}
58
59void DebugSprite::TickDraw(float deltams)
60{
61    Entity::TickDraw(deltams);
62
63    int x = data->x;
64    int y = data->y;
65    int z = data->z;
66
67    data->game->GetScene()->AddTile((data->tiler << 16) | 15,
68                                    x - 16, y - 32, z + 32, 1);
69    data->game->GetScene()->AddTile((data->tiler << 16) | 31,
70                                    x - 16, y - 32, z, 1);
71}
72
73DebugSprite::~DebugSprite()
74{
75    Ticker::Unref(data->game);
76    Tiler::Deregister(data->tiler);
77    delete data;
78}
79
Note: See TracBrowser for help on using the repository browser.