source: trunk/src/debugsprite.cpp @ 154

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

Refactor stuff.

  • Property svn:keywords set to Id
File size: 1.4 KB
RevLine 
[132]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>
[151]11#include <cmath>
[132]12
[150]13#include "core.h"
[132]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;
[150]27    float x, y, z;
[132]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");
[150]39    data->x = 320;
40    data->y = 206;
41    data->z = 0;
[132]42}
43
[147]44Entity::Group DebugSprite::GetGroup()
[132]45{
46    return GROUP_DEFAULT;
47}
48
[149]49void DebugSprite::TickGame(float deltams)
[132]50{
[149]51    Entity::TickGame(deltams);
[150]52
53    Float2 axis = Input::GetAxis(0);
[151]54    data->x += 0.1f * sqrtf(2.0f) * deltams * axis.x;
[150]55    data->y += 0.1f * deltams * axis.y;
[132]56}
57
[154]58void DebugSprite::TickDraw(float deltams)
[132]59{
[154]60    Entity::TickDraw(deltams);
[132]61
[150]62    int x = data->x;
63    int y = data->y;
64    int z = data->z;
65
[154]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);
[132]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.