123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "Block.h"
- #include "Inventory.h"
- #include "Globals.h"
- Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
- : Inventory( pos, hasInventory ),
- Model3D(),
- zType( zType )
- {
- transparent = false;
- passable = false;
- hp = 1;
- maxHP = 1;
- hardness = 1;
- this->zTool = zTool;
- speedModifier = 1;
- memset( sideVisible, 1, 6 );
- Model3D::setPosition( (Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f} );
- }
- Block::~Block()
- {}
- bool Block::isTransparent() const
- {
- return transparent;
- }
- bool Block::isPassable() const
- {
- return passable;
- }
- void Block::setSideVisible( Direction dir, bool visible )
- {
- sideVisible[ getDirectionIndex( dir ) ] = visible;
- }
- const BlockType* Block::zBlockType() const
- {
- return zType;
- }
- BasicBlockItem::BasicBlockItem( const ItemType* zType, const char* name )
- : Item( zType, name )
- {
- placeable = 1;
- transparent = 0;
- passable = 0;
- hp = 0;
- maxHP = 0;
- hardness = 0;
- toolId = 0;
- speedModifier = 0;
- interactable = 0;
- }
- BasicBlockItemType::BasicBlockItemType( int id, const char* name, const char* texturPath )
- : ItemType( id ),
- name( name ),
- texturPath( texturPath )
- {}
- void BasicBlockItemType::loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const
- {
- ItemType::loadSuperItem( zItem, zReader );
- BasicBlockItem* item = dynamic_cast<BasicBlockItem*>(zItem);
- if( !item )
- throw "BasicBlockItemType::loadSuperItem was called with an invalid item";
- zReader->lese( (char*)&item->transparent, 1 );
- zReader->lese( (char*)&item->passable, 1 );
- zReader->lese( (char*)&item->hp, 4 );
- zReader->lese( (char*)&item->maxHP, 4 );
- zReader->lese( (char*)&item->hardness, 4 );
- zReader->lese( (char*)&item->toolId, 4 );
- zReader->lese( (char*)&item->speedModifier, 4 );
- zReader->lese( (char*)&item->interactable, 1 );
- }
- Framework::Model3DData* BasicBlockItemType::getItemModel() const
- {
- return window->zBildschirm()->zGraphicsApi()->getModel( "itemCube" );
- }
- Item* BasicBlockItemType::createItem() const
- {
- return new BasicBlockItem( this, name );
- }
- Framework::Model3DTextur* BasicBlockItemType::getItemTextur() const
- {
- Model3DTextur* textur = new Model3DTextur();
- Textur* tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( texturPath, 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;
- }
|