source: trunk/src/debugsprite.cpp @ 154

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

Refactor stuff.

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