Block.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <Textur.h>
  2. #include "Block.h"
  3. #include "Globals.h"
  4. Block::Block(const BlockType* zType, Framework::Vec3<int> pos, Model3DData* model, Model3DTextur* texture, int maxHP)
  5. : Model3D(),
  6. zType(zType),
  7. location(pos),
  8. maxHP((float)maxHP)
  9. {
  10. transparent = 0;
  11. hp = (float)maxHP;
  12. memset(sideVisible, 1, 6);
  13. Model3D::setPosition((Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f});
  14. setModelDaten(model);
  15. setModelTextur(texture);
  16. breakTextur = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTextur("blocks.ltdb/crack.png", 0);
  17. }
  18. Block::~Block()
  19. {
  20. breakTextur->release();
  21. }
  22. void Block::api(char* message)
  23. {
  24. // TODO: implement api
  25. switch (message[0])
  26. {
  27. case 0: // hp change
  28. hp = *(float*)(message + 1);
  29. break;
  30. }
  31. }
  32. bool Block::isTransparent() const
  33. {
  34. return transparent;
  35. }
  36. void Block::setSideVisible(Direction dir, bool visible)
  37. {
  38. sideVisible[getDirectionIndex(dir)] = visible;
  39. }
  40. void setLightData(Direction dir, char* data)
  41. {
  42. }
  43. Vec3<int> Block::getLocation() const
  44. {
  45. return location;
  46. }
  47. const BlockType* Block::zBlockType() const
  48. {
  49. return zType;
  50. }
  51. Textur* Block::zEffectTextur()
  52. {
  53. if (hp < maxHP)
  54. return breakTextur;
  55. return 0;
  56. }
  57. float Block::getEffectPercentage()
  58. {
  59. return 1 - hp / maxHP;
  60. }