Block.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "Block.h"
  2. #include "Inventory.h"
  3. #include "Globals.h"
  4. Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
  5. : Inventory( pos, hasInventory ),
  6. Model3D(),
  7. zType( zType )
  8. {
  9. transparent = false;
  10. passable = false;
  11. hp = 1;
  12. maxHP = 1;
  13. hardness = 1;
  14. this->zTool = zTool;
  15. speedModifier = 1;
  16. memset( sideVisible, 1, 6 );
  17. Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
  18. }
  19. Block::~Block()
  20. {}
  21. bool Block::isTransparent() const
  22. {
  23. return transparent;
  24. }
  25. bool Block::isPassable() const
  26. {
  27. return passable;
  28. }
  29. void Block::setSideVisible( Direction dir, bool visible )
  30. {
  31. sideVisible[ getDirectionIndex( dir ) ] = visible;
  32. }
  33. const BlockType* Block::zBlockType() const
  34. {
  35. return zType;
  36. }
  37. BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
  38. : Item( zType, name )
  39. {
  40. placeable = 1;
  41. transparent = 0;
  42. passable = 0;
  43. hp = 0;
  44. maxHP = 0;
  45. hardness = 0;
  46. toolId = 0;
  47. speedModifier = 0;
  48. interactable = 0;
  49. }
  50. BasicBlockItemType::BasicBlockItemType( int id, const char* name, const char* texturPath )
  51. : ItemType( id ),
  52. name( name ),
  53. texturPath( texturPath )
  54. {}
  55. void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
  56. {
  57. ItemType::loadSuperItem( zItem, zReader );
  58. BasicBlockItem* item = dynamic_cast<BasicBlockItem*>(zItem);
  59. if( !item )
  60. throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
  61. zReader->lese( (char*)&item->transparent, 1 );
  62. zReader->lese( (char*)&item->passable, 1 );
  63. zReader->lese( (char*)&item->hp, 4 );
  64. zReader->lese( (char*)&item->maxHP, 4 );
  65. zReader->lese( (char*)&item->hardness, 4 );
  66. zReader->lese( (char*)&item->toolId, 4 );
  67. zReader->lese( (char*)&item->speedModifier, 4 );
  68. zReader->lese( (char*)&item->interactable, 1 );
  69. }
  70. Framework::Model3DData* BasicBlockItemType::getItemModel() const
  71. {
  72. return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
  73. }
  74. Item* BasicBlockItemType::createItem() const
  75. {
  76. return new BasicBlockItem( this, name );
  77. }
  78. Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const
  79. {
  80. Model3DTextur* textur = new Model3DTextur();
  81. Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( texturPath, 0 );
  82. textur->setPolygonTextur( 0, dynamic_cast<Textur*>(tex->getThis()) );
  83. textur->setPolygonTextur( 1, dynamic_cast<Textur*>(tex->getThis()) );
  84. textur->setPolygonTextur( 2, dynamic_cast<Textur*>(tex->getThis()) );
  85. textur->setPolygonTextur( 3, dynamic_cast<Textur*>(tex->getThis()) );
  86. textur->setPolygonTextur( 4, dynamic_cast<Textur*>(tex->getThis()) );
  87. textur->setPolygonTextur( 5, tex );
  88. return textur;
  89. }