123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #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;
- }
- BasicBlockType::BasicBlockType( int id, const char* texturPath )
- : BlockType( id ),
- texturPath( texturPath ),
- transparent( 0 ),
- passable( 0 ),
- maxHp( 100.f ),
- hardness( 1.f ),
- zTool( 0 ),
- speedModifier( 1.f ),
- interactable( 1 )
- {}
- Block* BasicBlockType::createBlock( Framework::Vec3<int> position )
- {
- Block* b = new BasicBlock( this, texturPath, 0, position, 0 ); // TODO: add efective tool
- initializeSuperBlock( b );
- return b;
- }
- void BasicBlockType::initializeSuperBlock( Block* zBlock )
- {
- BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
- if( !block )
- throw "BasicBlockType::initializeSuperBlock was called with a block witch is not an instance of BasicBlock";
- block->transparent = transparent;
- block->passable = passable;
- block->hp = maxHp;
- block->maxHP = maxHp;
- block->hardness = hardness;
- block->zTool = zTool;
- block->speedModifier = speedModifier;
- }
- bool BasicBlockType::needsInstance() const
- {
- return 1;
- }
- DirtBlockType::DirtBlockType()
- : BasicBlockType( ID, "blocks.ltdb/dirt.png" )
- {}
- Block* DirtBlockType::createBlock( Framework::Vec3<int> position )
- {
- Block* b = BasicBlockType::createBlock( position );
- b->zTextur()->setPolygonTextur( 4, currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "blocks.ltdb/lawn.png", 0 ) );
- return b;
- }
- DirtBlockItemType::DirtBlockItemType()
- : BasicBlockItemType( ID, "Dirt", "blocks.ltdb/dirt.png" )
- {}
- StoneBlockType::StoneBlockType()
- : BasicBlockType( ID, "blocks.ltdb/stone.png" )
- {
- hardness = 2.f;
- }
- StoneBlockItemType::StoneBlockItemType()
- : BasicBlockItemType( ID, "Stone", "blocks.ltdb/stone.png" )
- {}
- SandBlockType::SandBlockType()
- : BasicBlockType( ID, "blocks.ltdb/sand.png" )
- {
- hardness = 0.5f;
- }
- SandBlockItemType::SandBlockItemType()
- : BasicBlockItemType( ID, "Sand", "blocks.ltdb/sand.png" )
- {}
- OakBlockType::OakBlockType()
- : BasicBlockType( ID, "blocks.ltdb/oak.png" )
- {
- hardness = 1.5f;
- }
- OakBlockItemType::OakBlockItemType()
- : BasicBlockItemType( ID, "Oak Wood", "blocks.ltdb/oak.png" )
- {}
- LeavesBlockType::LeavesBlockType()
- : BasicBlockType( ID, "blocks.ltdb/leaves.png" )
- {
- hardness = 0.1f;
- }
- LeavesBlockItemType::LeavesBlockItemType()
- : BasicBlockItemType( ID, "Leaves", "blocks.ltdb/leaves.png" )
- {}
- GravelBlockType::GravelBlockType()
- : BasicBlockType( ID, "blocks.ltdb/gravel.png" )
- {
- hardness = 0.75f;
- }
- GravelBlockItemType::GravelBlockItemType()
- : BasicBlockItemType( ID, "Gravel", "blocks.ltdb/gravel.png" )
- {}
- GraniteBlockType::GraniteBlockType()
- : BasicBlockType( ID, "blocks.ltdb/granite.png" )
- {
- hardness = 3.f;
- }
- GraniteBlockItemType::GraniteBlockItemType()
- : BasicBlockItemType( ID, "Granite", "blocks.ltdb/granite.png" )
- {}
- CobbleBlockType::CobbleBlockType()
- : BasicBlockType( ID, "blocks.ltdb/cobble.png" )
- {
- hardness = 1.f;
- }
- CobbleBlockItemType::CobbleBlockItemType()
- : BasicBlockItemType( ID, "Cobble", "blocks.ltdb/cobble.png" )
- {}
- BirchBlockType::BirchBlockType()
- : BasicBlockType( ID, "blocks.ltdb/birch.png" )
- {
- hardness = 1.5f;
- }
- BirchBlockItemType::BirchBlockItemType()
- : BasicBlockItemType( ID, "Birch Wood", "blocks.ltdb/birch.png" )
- {}
- BeechBlockType::BeechBlockType()
- : BasicBlockType( ID, "blocks.ltdb/beech.png" )
- {
- hardness = 1.5f;
- }
- BeechBlockItemType::BeechBlockItemType()
- : BasicBlockItemType( ID, "Beech Wood", "blocks.ltdb/beech.png" )
- {}
- BasaltBlockType::BasaltBlockType()
- : BasicBlockType( ID, "blocks.ltdb/basalt.png" )
- {
- hardness = 2.f;
- }
- BasaltBlockItemType::BasaltBlockItemType()
- : BasicBlockItemType( ID, "Basalt", "blocks.ltdb/basalt.png" )
- {}
|