123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include "BasicBlocks.h"
- #include <Model3D.h>
- #include <Globals.h>
- #include <GraphicsApi.h>
- #include <Bild.h>
- #include <Model3DList.h>
- #include "Globals.h"
- BasicBlock::BasicBlock( const BlockType* zType, const char* texture, ItemType* zTool, Framework::Vec3<int> pos, Framework::Textur* t )
- : Block( zType, zTool, pos, false )
- {
- Model3DData* data = window->zBildschirm()->zGraphicsApi()->getModel( "cube" );
- setModelDaten( data );
- Bild* b = new Bild();
- b->neuBild( 10, 10, 0xFFFFFFFF );
- Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( texture, 0 );
- if( !tex->zBild() )
- tex->setBildZ( b );
- else
- b->release();
- Model3DTextur* textur = new Model3DTextur();
- textur->setPolygonTextur( 0, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 1, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 2, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 3, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 4, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 5, tex );
- setModelTextur( textur );
- breakTextur = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/crack.png", 0 );
- }
- BasicBlock::~BasicBlock()
- {
- breakTextur->release();
- }
- bool BasicBlock::needRenderPolygon( int index )
- {
- return sideVisible[ index ];
- }
- Textur* BasicBlock::zEffectTextur()
- {
- if( hp < maxHP )
- return breakTextur;
- return 0;
- }
- float BasicBlock::getEffectPercentage()
- {
- return 1 - hp / maxHP;
- }
- DirtBlockType::DirtBlockType()
- : BlockType( ID )
- {}
- void DirtBlockType::loadSuperBlock( Block* zBlock, Framework::StreamReader* zReader )
- {
- BlockType::loadSuperBlock( zBlock, zReader );
- }
- Block* DirtBlockType::createBlock( Framework::Vec3<int> position )
- {
- Block* b = new BasicBlock( DirtBlockType::INSTANCE, "blocks.ltdb/dirt.png", 0, position, 0 ); // TODO: add efective tool
- initializeSuperBlock( b );
- return b;
- }
- void DirtBlockType::initializeSuperBlock( Block* zBlock )
- {
- BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
- if( !block )
- throw "DirtBlockType::createSuperBlock was called with a block witch is not an instance of BasicBlock";
- block->transparent = 0;
- block->passable = 0;
- block->hp = 100;
- block->maxHP = 100;
- block->hardness = 1;
- block->zTool = 0;
- block->speedModifier = 1;
- }
- bool DirtBlockType::needsInstance() const
- {
- return 1;
- }
- DirtBlockItemType::DirtBlockItemType()
- : BasicBlockItemType( ID )
- {}
- Item* DirtBlockItemType::createItem() const
- {
- BasicBlockItem* item = new BasicBlockItem( (ItemType*)this, "Dirt" );
- return item;
- }
- Framework::Model3DTextur* DirtBlockItemType::getItemTextur() const
- {
- Model3DTextur* textur = new Model3DTextur();
- Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/dirt.png", 0 );
- textur->setPolygonTextur( 0, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 1, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 2, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 3, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 4, dynamic_cast<Textur*>(tex->getThis()) );
- textur->setPolygonTextur( 5, tex );
- return textur;
- }
|