// Constructors BulletCollider::BulletCollider(WorldInterface *world, Private::GenericData *data, btCollisionShape *collisionShape) : ColliderInterface(world, data), collisionShape(collisionShape) { assert(collisionShape != nullptr && "Invalid collision shape"); if (getData()->data == nullptr) { getData()->data = new btRigidBody(static_cast<btScalar>(1.0f), new btDefaultMotionState(), nullptr); assert(getData()->data != nullptr && "Impossible to create actor"); btRigidBody *body = getDataAs<btRigidBody>(); body->setCollisionShape(&BulletRigidBody::EmptyShape); body->setFlags(body->getFlags() | BT_DISABLE_WORLD_GRAVITY); body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); body->setActivationState(DISABLE_DEACTIVATION); static_cast<BulletWorld *>(world)->getWorld()->addRigidBody(body); } else { rigidBody = static_cast<BulletRigidBody *>(getDataAs<btRigidBody>()->getUserPointer()); } btRigidBody *body = getDataAs<btRigidBody>(); body->setUserPointer(this); body->setCollisionShape(collisionShape); setAsTrigger(IsTriggerByDefault()); setFilterGroup(GetDefaultFilterGroup()); }
void Collider::_copyFrom(const ComponentBase *model) { auto m = (Collider*)model; if (m->getColliderType() == Physics::ColliderType::Mesh) { init(m->getColliderType(), m->getMesh()); } else { init(m->getColliderType(), ""); } #ifdef EDITOR_ENABLED editorUpdate(); if (editorStruct) { editorStruct->copyDatas(m); } Link *link = entity.getLinkPtr(); auto p = scaleFromMat4(link->getGlobalTransform()); //scale(p / getSize()); #else setMaterial(m->getMaterial()->getName()); setAsTrigger(m->isATrigger()); setFilterGroup(m->getFilterGroup()); setCenter(m->getCenter()); setHeight(m->getHeight()); setRadius(m->getRadius()); setSize(m->getSize()); setMesh(m->getMesh()); if (m->isConvex()) setAsConvex(); else if (m->isConcave()) setAsConcave(); #endif }
Player::Player(PlatformState& platformState, BoxWorld* world, sf::Vector2f& size, sf::Vector2f& position, ResourceCollection& resource, LightSolver* lightSolver, StatManager& stats) : Entity(world, size, position) , mPlatformState(platformState) , groundCallBack(nullptr) , leftButton(false) , rightButton(false) , downButton(false) , mResource(resource) , flashLight(lightSolver->createLight(FLASHLIGHT_SIZE.x, FLASHLIGHT_SIZE.y)) , maskRight(&resource.getTexture("Assets/Shader/mask.png")) , maskLeft(flipTexture(maskRight)) , activeStreetLight(nullptr) , collisionFixture(body->GetFixtureList()) , mStats(stats) , flashLightBody(world->createEntityBody(sf::Vector2f(0.0f, 0.0f), static_cast<sf::Vector2f>(FLASHLIGHT_SIZE), false)) { flashLight->setColor(sf::Color(255, 255, 0, 150)); int group = flashLight->getFilterGroup(); group |= (1 << 8); flashLight->setFilterGroup(group); setFilterGroup(getFilterGroup() | (1 << 8)); setState(PLAYER_STATE::NORMAL); /* Walking/run animation */ auto &walking = mResource.getTexture("Assets/Characters/Stella Left.png"); sf::Vector2i walkingSize = static_cast<sf::Vector2i>(walking.getSize()); sf::Vector2i frameSize(256, 256); SpriteSheet spritesheet1(frameSize, walkingSize); std::vector<sf::IntRect> frames = spritesheet1.getAllFrames(); mWalking = new Animation(frames,walking); /* Idle animation */ auto &idle = mResource.getTexture("Assets/Characters/Stella idle.png"); sf::Vector2i idleSize = static_cast<sf::Vector2i>(idle.getSize()); SpriteSheet idleSheet(frameSize,idleSize); std::vector<sf::IntRect> idleFrames = idleSheet.getAllFrames(); mIdle = new Animation(idleFrames,idle); /* Jump animation */ auto &jump = mResource.getTexture("Assets/Characters/Stella jump.png"); sf::Vector2i jumpSize = static_cast<sf::Vector2i>(jump.getSize()); SpriteSheet jumpSheet(frameSize,jumpSize); std::vector<sf::IntRect> jumpFrames = jumpSheet.getAllFrames(); mJump = new Animation(jumpFrames,jump); /* Grab animation */ auto &grab = mResource.getTexture("Assets/Characters/Stella grab.png"); sf::Vector2i grabSize = static_cast<sf::Vector2i>(grab.getSize()); SpriteSheet grabSheet (frameSize, grabSize); std::vector<sf::IntRect> grabFrames = grabSheet.getAllFrames(); mGrab = new Animation(grabFrames,grab); /* Fall Animation*/ auto &fall = mResource.getTexture("Assets/Characters/Stella fall.png"); sf::Vector2i fallSize = static_cast<sf::Vector2i>(fall.getSize()); SpriteSheet fallSheet(frameSize, fallSize); std::vector<sf::IntRect> fallFrames = jumpSheet.getAllFrames(); mFall = new Animation(fallFrames,fall); /* Hit Animation*/ auto &hit = mResource.getTexture("Assets/Characters/Stella hit.png"); sf::Vector2i hitSize = static_cast<sf::Vector2i>(hit.getSize()); SpriteSheet hitSheet(frameSize, hitSize); std::vector<sf::IntRect> hitFrames = hitSheet.getAllFrames(); mHit = new Animation(hitFrames,hit); anime.setAnimation(*mIdle); updateSpriteOrigin(); mJumpSound = new sf::Sound; mJumpSound->setBuffer(*mResource.getSound("Assets/Sound/Jump.wav")); mWalkSound = new sf::Sound; mWalkSound->setBuffer(*mResource.getSound("Assets/Sound/Stella_Run_Loop_1.wav")); mWalkSound->setVolume(40); mHurtSound = new sf::Sound; mHurtSound->setBuffer(*mResource.getSound("Assets/Sound/Stella get hurt.wav")); setupSensors(position, size); body->SetLinearDamping(1.0f); /* Set filter for collisions */ b2Filter filter = collisionFixture->GetFilterData(); filter.categoryBits = PLAYER; //filter.maskBits =ALL, ENEMY_CHASE, ENEMY_ATTACK; filter.groupIndex = ALL, ENEMY_CHASE, ENEMY_ATTACK; collisionFixture->SetFilterData(filter); knockForce = 35; toggle = false; }
// Constructors NullCollider::NullCollider(WorldInterface *world, Private::GenericData *data) : ColliderInterface(world, data) { setAsTrigger(IsTriggerByDefault()); setFilterGroup(GetDefaultFilterGroup()); }