Block.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Vec3<int> Block::getLocation() const
  41. {
  42. return location;
  43. }
  44. const BlockType* Block::zBlockType() const
  45. {
  46. return zType;
  47. }
  48. Textur* Block::zEffectTextur()
  49. {
  50. if (hp < maxHP)
  51. return breakTextur;
  52. return 0;
  53. }
  54. float Block::getEffectPercentage()
  55. {
  56. return 1 - hp / maxHP;
  57. }