You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

80 line
1.4 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. data->x = 320;
  33. data->y = 206;
  34. data->z = 0;
  35. }
  36. Entity::Group DebugSprite::GetGroup()
  37. {
  38. return GROUP_DEFAULT;
  39. }
  40. void DebugSprite::TickGame(float deltams)
  41. {
  42. Entity::TickGame(deltams);
  43. Float2 axis = Input::GetAxis(0);
  44. data->x += 0.1f * sqrtf(2.0f) * deltams * axis.x;
  45. data->y += 0.1f * deltams * axis.y;
  46. }
  47. void DebugSprite::TickDraw(float deltams)
  48. {
  49. Entity::TickDraw(deltams);
  50. int x = data->x;
  51. int y = data->y;
  52. int z = data->z;
  53. data->game->GetScene()->AddTile((data->tiler << 16) | 31,
  54. x - 16, y, z, 1);
  55. data->game->GetScene()->AddTile((data->tiler << 16) | 15,
  56. x - 16, y, z + 32, 1);
  57. }
  58. DebugSprite::~DebugSprite()
  59. {
  60. Ticker::Unref(data->game);
  61. Tiler::Deregister(data->tiler);
  62. delete data;
  63. }