BasicBlocks.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #include "BasicBlocks.h"
  2. #include <Model3D.h>
  3. #include <Globals.h>
  4. #include <GraphicsApi.h>
  5. #include <Bild.h>
  6. #include <Model3DList.h>
  7. #include "Globals.h"
  8. BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* zTool, Framework::Vec3<int> pos, Framework::Textur* t )
  9. : Block( zType, zTool, pos, false )
  10. {
  11. Model3DData* data = window->zBildschirm()->zGraphicsApi()->getModel( "cube" );
  12. setModelDaten( data );
  13. Bild* b = new Bild();
  14. b->neuBild( 10, 10, 0xFFFFFFFF );
  15. Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( texture, 0 );
  16. if( !tex->zBild() )
  17. tex->setBildZ( b );
  18. else
  19. b->release();
  20. Model3DTextur* textur = new Model3DTextur();
  21. textur->setPolygonTextur( 0, dynamic_cast<Textur*>(tex->getThis()) );
  22. textur->setPolygonTextur( 1, dynamic_cast<Textur*>(tex->getThis()) );
  23. textur->setPolygonTextur( 2, dynamic_cast<Textur*>(tex->getThis()) );
  24. textur->setPolygonTextur( 3, dynamic_cast<Textur*>(tex->getThis()) );
  25. textur->setPolygonTextur( 4, dynamic_cast<Textur*>(tex->getThis()) );
  26. textur->setPolygonTextur( 5, tex );
  27. setModelTextur( textur );
  28. breakTextur = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/crack.png", 0 );
  29. }
  30. BasicBlock::~BasicBlock()
  31. {
  32. breakTextur->release();
  33. }
  34. bool BasicBlock::needRenderPolygon( int index )
  35. {
  36. return sideVisible[ index ];
  37. }
  38. Textur* BasicBlock::zEffectTextur()
  39. {
  40. if( hp < maxHP )
  41. return breakTextur;
  42. return 0;
  43. }
  44. float BasicBlock::getEffectPercentage()
  45. {
  46. return 1 - hp / maxHP;
  47. }
  48. BasicBlockType::BasicBlockType( int id, const char* texturPath )
  49. : BlockType( id ),
  50. texturPath( texturPath ),
  51. transparent( 0 ),
  52. passable( 0 ),
  53. maxHp( 100.f ),
  54. hardness( 1.f ),
  55. zTool( 0 ),
  56. speedModifier( 1.f ),
  57. interactable( 1 )
  58. {}
  59. Block* BasicBlockType::createBlock( Framework::Vec3<int> position )
  60. {
  61. Block* b = new BasicBlock( this, texturPath, 0, position, 0 ); // TODO: add efective tool
  62. initializeSuperBlock( b );
  63. return b;
  64. }
  65. void BasicBlockType::initializeSuperBlock( Block* zBlock )
  66. {
  67. BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
  68. if( !block )
  69. throw "BasicBlockType::initializeSuperBlock was called with a block witch is not an instance of BasicBlock";
  70. block->transparent = transparent;
  71. block->passable = passable;
  72. block->hp = maxHp;
  73. block->maxHP = maxHp;
  74. block->hardness = hardness;
  75. block->zTool = zTool;
  76. block->speedModifier = speedModifier;
  77. }
  78. bool BasicBlockType::needsInstance() const
  79. {
  80. return 1;
  81. }
  82. DirtBlockType::DirtBlockType()
  83. : BasicBlockType( ID, "blocks.ltdb/dirt.png" )
  84. {}
  85. DirtBlockItemType::DirtBlockItemType()
  86. : BasicBlockItemType( ID, "Dirt", "blocks.ltdb/dirt.png" )
  87. {}
  88. StoneBlockType::StoneBlockType()
  89. : BasicBlockType( ID, "blocks.ltdb/stone.png" )
  90. {
  91. hardness = 2.f;
  92. }
  93. StoneBlockItemType::StoneBlockItemType()
  94. : BasicBlockItemType( ID, "Stone", "blocks.ltdb/stone.png" )
  95. {}
  96. SandBlockType::SandBlockType()
  97. : BasicBlockType( ID, "blocks.ltdb/sand.png" )
  98. {
  99. hardness = 0.5f;
  100. }
  101. SandBlockItemType::SandBlockItemType()
  102. : BasicBlockItemType( ID, "Sand", "blocks.ltdb/sand.png" )
  103. {}
  104. OakBlockType::OakBlockType()
  105. : BasicBlockType( ID, "blocks.ltdb/oak.png" )
  106. {
  107. hardness = 1.5f;
  108. }
  109. OakBlockItemType::OakBlockItemType()
  110. : BasicBlockItemType( ID, "Oak Wood", "blocks.ltdb/oak.png" )
  111. {}
  112. LeavesBlockType::LeavesBlockType()
  113. : BasicBlockType( ID, "blocks.ltdb/leaves.png" )
  114. {
  115. hardness = 0.1f;
  116. }
  117. LeavesBlockItemType::LeavesBlockItemType()
  118. : BasicBlockItemType( ID, "Leaves", "blocks.ltdb/leaves.png" )
  119. {}
  120. GravelBlockType::GravelBlockType()
  121. : BasicBlockType( ID, "blocks.ltdb/gravel.png" )
  122. {
  123. hardness = 0.75f;
  124. }
  125. GravelBlockItemType::GravelBlockItemType()
  126. : BasicBlockItemType( ID, "Gravel", "blocks.ltdb/gravel.png" )
  127. {}
  128. GraniteBlockType::GraniteBlockType()
  129. : BasicBlockType( ID, "blocks.ltdb/granite.png" )
  130. {
  131. hardness = 3.f;
  132. }
  133. GraniteBlockItemType::GraniteBlockItemType()
  134. : BasicBlockItemType( ID, "Granite", "blocks.ltdb/granite.png" )
  135. {}
  136. CobbleBlockType::CobbleBlockType()
  137. : BasicBlockType( ID, "blocks.ltdb/cobble.png" )
  138. {
  139. hardness = 1.f;
  140. }
  141. CobbleBlockItemType::CobbleBlockItemType()
  142. : BasicBlockItemType( ID, "Cobble", "blocks.ltdb/cobble.png" )
  143. {}
  144. BirchBlockType::BirchBlockType()
  145. : BasicBlockType( ID, "blocks.ltdb/birch.png" )
  146. {
  147. hardness = 1.5f;
  148. }
  149. BirchBlockItemType::BirchBlockItemType()
  150. : BasicBlockItemType( ID, "Birch Wood", "blocks.ltdb/birch.png" )
  151. {}
  152. BeechBlockType::BeechBlockType()
  153. : BasicBlockType( ID, "blocks.ltdb/beech.png" )
  154. {
  155. hardness = 1.5f;
  156. }
  157. BeechBlockItemType::BeechBlockItemType()
  158. : BasicBlockItemType( ID, "Beech Wood", "blocks.ltdb/beech.png" )
  159. {}
  160. BasaltBlockType::BasaltBlockType()
  161. : BasicBlockType( ID, "blocks.ltdb/basalt.png" )
  162. {
  163. hardness = 2.f;
  164. }
  165. BasaltBlockItemType::BasaltBlockItemType()
  166. : BasicBlockItemType( ID, "Basalt", "blocks.ltdb/basalt.png" )
  167. {}