75 lines
1.3 KiB

  1. //
  2. // Deus Hax (working title)
  3. // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
  4. //
  5. #if defined HAVE_CONFIG_H
  6. # include "config.h"
  7. #endif
  8. #include <cstdio>
  9. #include <cmath>
  10. #include "core.h"
  11. #include "debugsprite.h"
  12. /*
  13. * DebugSprite implementation class
  14. */
  15. class DebugSpriteData
  16. {
  17. friend class DebugSprite;
  18. private:
  19. Game *game;
  20. int tiler;
  21. float x, y, z;
  22. };
  23. /*
  24. * Public DebugSprite class
  25. */
  26. DebugSprite::DebugSprite(Game *game)
  27. {
  28. data = new DebugSpriteData();
  29. data->game = game;
  30. Ticker::Ref(game);
  31. data->tiler = Tiler::Register("art/test/character-dress.png", 32);
  32. data->x = 320;
  33. data->y = 206;
  34. data->z = 0;
  35. }
  36. void DebugSprite::TickGame(float deltams)
  37. {
  38. Entity::TickGame(deltams);
  39. Float2 axis = Input::GetAxis(0);
  40. data->x += 0.1f * sqrtf(2.0f) * deltams * axis.x;
  41. data->y += 0.1f * deltams * axis.y;
  42. }
  43. void DebugSprite::TickDraw(float deltams)
  44. {
  45. Entity::TickDraw(deltams);
  46. int x = data->x;
  47. int y = data->y;
  48. int z = data->z;
  49. data->game->GetScene()->AddTile((data->tiler << 16) | 31,
  50. x - 16, y, z, 1);
  51. data->game->GetScene()->AddTile((data->tiler << 16) | 15,
  52. x - 16, y, z + 32, 1);
  53. }
  54. DebugSprite::~DebugSprite()
  55. {
  56. Ticker::Unref(data->game);
  57. Tiler::Deregister(data->tiler);
  58. delete data;
  59. }