Character::Character(const std::string& name, World* world, const geometry::Point& position, const geometry::AABB& rect, float weight)
        : Entity(name, world, position, b2_dynamicBody, Entity::Type::Character, (uint16)~Entity::Type::Character),
        m_world(world), m_id(4)
    {
        createFixture("body", rect, weight, 1);

        geometry::AABB feet(rect.width - 0.1f, rect.height * 0.05f);
        geometry::Point pos(0, -rect.height / 2);
        b2Fixture* sens = createFixture("feet", feet, 1, 1, Type::ThisType, Type::ThisCollideWith, pos, true);
        world->setCallback(this, sens, character_foot_callback, NULL, false);
    }
Exemple #2
0
void TrapBox::init(CCLayer *layer, b2World *world, float PTM_RATIO){
	if(debug){
		createSprite();
		layer->addChild(boxSprite);
	}
	createBody(world, PTM_RATIO);

	createFixture(world, PTM_RATIO);
}
Exemple #3
0
TTFB_Prop::TTFB_Prop(Box2DWorld * _world, std::string _samplerResourceId, Shader * _shader, float _scaleMult) :
	Box2DSprite(_world, TTFB_ResourceManager::scenario->getTextureSampler(_samplerResourceId)->textureSampler)
{
	b2Filter filt;
	filt.categoryBits = Category::PROP;
	filt.maskBits     = 0x000000;
	setShader(_shader);

	scale = B2_SCALE * _scaleMult;
	createFixture(filt);
}
/*creates a new object,at pos, with its config from file*/
LevelObject::LevelObject(b2World* w,Json::Value& json,const b2Vec2& pos,int id)
:world(w),objectId(uniqueId++),spriteId(id){
	b2BodyDef bodyDef;
	bodyDef.type = b2_staticBody;
	bodyDef.position.Set(pos.x,pos.y);
	body = world->CreateBody(&bodyDef);
	body->SetUserData(this);
	Json::Value shapes=json["shapes"];
	Json::ValueIterator shapesIt=shapes.begin();
	for(; shapesIt!=shapes.end(); shapesIt++){
		createFixture(*shapesIt);
	}
}
b2Body* TiledBodyCreator::initCollisionMap(TMXTiledMap* map, b2World* world, std::string groupname)
{
	auto collisionGroup = map->getObjectGroup(groupname);
	cocos2d::ValueVector collisionObjects = collisionGroup->getObjects();

	b2BodyDef bd;
    bd.position.Set(map->getPositionX() / 32, map->getPositionY() / 32);
	auto collisionBody = world->CreateBody(&bd);

	for(cocos2d::Value objectValue : collisionObjects)
	{
		auto fixtureShape = createFixture(objectValue.asValueMap());
		if(fixtureShape != NULL) {
			collisionBody->CreateFixture(&fixtureShape->fixture);
		}
	}
    
    return collisionBody;
}
Exemple #6
0
LD32_Enemy::LD32_Enemy(Box2DWorld * _world) :
	Box2DMeshEntity(_world, nullptr, b2_dynamicBody, false, nullptr, transform),
	NodeChild(nullptr),
	NodeTransformable(new Transform()),
	heDed(false)
{
	b2Filter sf;
	sf.categoryBits = LD32_Game::kENEMY;

	if(std::rand() % 2 == 0){
		mesh = Resource::loadMeshFromObj("../assets/Mushroom.vox");
	}else{
		mesh = Resource::loadMeshFromObj("../assets/ThingGuy.vox");
	}

	world->addToWorld(this);
	b2Fixture * f = createFixture(true);
	f->SetRestitution(1.f);
	f->SetUserData(this);
	f->SetFilterData(sf);
	body->SetUserData(this);
}
Exemple #7
0
LD32_Donut::LD32_Donut(Box2DWorld * _world) :
	Box2DMeshEntity(_world, nullptr, b2_staticBody, false, nullptr, transform),
	NodeChild(nullptr),
	NodeTransformable(new Transform()),
	bot(nullptr),
	rotSpeed(vox::NumberUtils::randomFloat(-0.1f, 0.1f))
{
	b2Filter sf;
	sf.categoryBits = LD32_Game::kBUMPER;

	//if(donutTopMesh == nullptr){
		donutTopMesh = Resource::loadMeshFromObj("../assets/donutTop.vox");
		donutTopMesh->pushMaterial(donutMat);
		donutTopMesh->pushTexture2D(LD32_ResourceManager::donutTop);
	//}if(donutBotMesh == nullptr){
		donutBotMesh = Resource::loadMeshFromObj("../assets/donutBot.vox");
		donutBotMesh->pushMaterial(donutMat);
		donutBotMesh->pushTexture2D(LD32_ResourceManager::donutBot);
	//}

	bot = new MeshEntity(nullptr);
	bot->mesh = donutBotMesh;
	++donutBotMesh->referenceCount;
	addChild(bot);

	mesh = donutTopMesh;
	++donutTopMesh->referenceCount;

	world->addToWorld(this);
	b2Fixture * f = createFixture(true);
	f->SetRestitution(2.5f);
	f->SetUserData(this);
	f->SetFilterData(sf);
	body->SetUserData(this);
	body->SetTransform(body->GetPosition(), vox::NumberUtils::randomFloat(0, 6.28));
}