BasicBlocks.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. Block* DirtBlockType::createBlock( Framework::Vec3<int> position )
  86. {
  87. Block* b = BasicBlockType::createBlock( position );
  88. b->zTextur()->setPolygonTextur( 4, currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/lawn.png", 0 ) );
  89. return b;
  90. }
  91. DirtBlockItemType::DirtBlockItemType()
  92. : BasicBlockItemType( ID, "Dirt", "blocks.ltdb/dirt.png" )
  93. {}
  94. StoneBlockType::StoneBlockType()
  95. : BasicBlockType( ID, "blocks.ltdb/stone.png" )
  96. {
  97. hardness = 2.f;
  98. }
  99. StoneBlockItemType::StoneBlockItemType()
  100. : BasicBlockItemType( ID, "Stone", "blocks.ltdb/stone.png" )
  101. {}
  102. SandBlockType::SandBlockType()
  103. : BasicBlockType( ID, "blocks.ltdb/sand.png" )
  104. {
  105. hardness = 0.5f;
  106. }
  107. SandBlockItemType::SandBlockItemType()
  108. : BasicBlockItemType( ID, "Sand", "blocks.ltdb/sand.png" )
  109. {}
  110. OakBlockType::OakBlockType()
  111. : BasicBlockType( ID, "blocks.ltdb/oak.png" )
  112. {
  113. hardness = 1.5f;
  114. }
  115. OakBlockItemType::OakBlockItemType()
  116. : BasicBlockItemType( ID, "Oak Wood", "blocks.ltdb/oak.png" )
  117. {}
  118. LeavesBlockType::LeavesBlockType()
  119. : BasicBlockType( ID, "blocks.ltdb/leaves.png" )
  120. {
  121. hardness = 0.1f;
  122. }
  123. LeavesBlockItemType::LeavesBlockItemType()
  124. : BasicBlockItemType( ID, "Leaves", "blocks.ltdb/leaves.png" )
  125. {}
  126. GravelBlockType::GravelBlockType()
  127. : BasicBlockType( ID, "blocks.ltdb/gravel.png" )
  128. {
  129. hardness = 0.75f;
  130. }
  131. GravelBlockItemType::GravelBlockItemType()
  132. : BasicBlockItemType( ID, "Gravel", "blocks.ltdb/gravel.png" )
  133. {}
  134. GraniteBlockType::GraniteBlockType()
  135. : BasicBlockType( ID, "blocks.ltdb/granite.png" )
  136. {
  137. hardness = 3.f;
  138. }
  139. GraniteBlockItemType::GraniteBlockItemType()
  140. : BasicBlockItemType( ID, "Granite", "blocks.ltdb/granite.png" )
  141. {}
  142. CobbleBlockType::CobbleBlockType()
  143. : BasicBlockType( ID, "blocks.ltdb/cobble.png" )
  144. {
  145. hardness = 1.f;
  146. }
  147. CobbleBlockItemType::CobbleBlockItemType()
  148. : BasicBlockItemType( ID, "Cobble", "blocks.ltdb/cobble.png" )
  149. {}
  150. BirchBlockType::BirchBlockType()
  151. : BasicBlockType( ID, "blocks.ltdb/birch.png" )
  152. {
  153. hardness = 1.5f;
  154. }
  155. BirchBlockItemType::BirchBlockItemType()
  156. : BasicBlockItemType( ID, "Birch Wood", "blocks.ltdb/birch.png" )
  157. {}
  158. BeechBlockType::BeechBlockType()
  159. : BasicBlockType( ID, "blocks.ltdb/beech.png" )
  160. {
  161. hardness = 1.5f;
  162. }
  163. BeechBlockItemType::BeechBlockItemType()
  164. : BasicBlockItemType( ID, "Beech Wood", "blocks.ltdb/beech.png" )
  165. {}
  166. BasaltBlockType::BasaltBlockType()
  167. : BasicBlockType( ID, "blocks.ltdb/basalt.png" )
  168. {
  169. hardness = 2.f;
  170. }
  171. BasaltBlockItemType::BasaltBlockItemType()
  172. : BasicBlockItemType( ID, "Basalt", "blocks.ltdb/basalt.png" )
  173. {}