SprCharWalk::SprCharWalk() { image = HResources::SPR_CHAR_WALK; setOriginTopLeft(); imageCount = 4; setup(); setHitbox(0, 0, 46, 65, HITBOX_RECTANGLE); }
SmallTreeObject::SmallTreeObject(tank::Vectorf pos) : Object(pos) { makeGraphic<tank::Image>(MainState::smallrock); tank::Rectd hb = { 18, static_cast<double>(Tile::TILE_SIZE) - 8, 28, 9 }; hb.y -= hb.h; setHitbox(hb); setSolid(true); }
Meuble::Meuble(sf::Sprite &sprite, sf::Vector2f pos, sf::FloatRect hitBox, sf::FloatRect interactBox, GameContext& context) : m_sn(10), m_hitBox(hitBox), m_interactBox(interactBox) { m_entity = context.entityPool->createEntity(); auto node = context.scene->bindEntity(m_entity); auto body = context.physic->bindEntity(m_entity); body->setNode(node); body->setHitbox(hitBox); node->setAbsolutePosition(pos); m_sn.attachParent(*node); m_sn.setSprite(sprite); }
void Character::loadEntityFromNode(Node& root) { DrawableEntity::loadEntityFromNode(root); Hitbox* hitbox(NULL); try { Node& areaNode = root.firstChild("hitbox"); sf::FloatRect area = static_cast<sf::FloatRect>(loadAreaFromNode(areaNode)); hitbox = new BoundingBoxHitbox(getPosition(), area); Log::write(Log::LOG_INFO, "Entity's hitbox creation : " + toString(area)); } catch(std::runtime_error& e) { Log::write(Log::LOG_WARNING, "No hitbox defined for Entity : " + toString(e.what())); // when there isn't hitbox, we assign the entity's global bounds as a hitbox hitbox = new BoundingBoxHitbox(getPosition(), getGlobalBounds()); Log::write(Log::LOG_INFO, "Entity's hitbox creation : " + toString(getGlobalBounds())); } setHitbox(hitbox); }