Exemplo n.º 1
0
EnemyType enemy_identifyType(const tmx::MapObject& object)
{
	if (object.GetType() == "mummy")
		return EnemyType::Mummy;
	if (object.GetType() == "witch")
		return EnemyType::Witch;
	return EnemyType::Regurgitator;
}
Exemplo n.º 2
0
	void createEntity(tmx::MapObject mapObject, b2World& box2dWorld, anax::World& anaxWorld) {
		b2Vec2 statingPosition = tmx::SfToBoxVec(mapObject.GetPosition());
		b2Vec2 endPosition = tmx::SfToBoxVec(sf::Vector2f(mapObject.GetPosition().x + mapObject.GetAABB().width, mapObject.GetPosition().y));

		b2Body* firstBodyToJoinWith = createStartingBody(statingPosition, box2dWorld);
		b2Body* prevBody = firstBodyToJoinWith;
		{
			b2PolygonShape shape;
			shape.SetAsBox(0.5f, 0.125f);

			b2FixtureDef fd  = getRopeFixture(shape);

			b2RevoluteJointDef jd;
			jd.collideConnected = false;

			const int32 N = ceilf((mapObject.GetAABB().width / 30) / (1.0f )) + 1;

			for (int32 xVal = 1; xVal < N; ++xVal) {
				b2BodyDef bd;
				bd.type = b2_dynamicBody;
				bd.position.Set(statingPosition.x + xVal , statingPosition.y );
				if (xVal == N - 1) {
					bd.type = b2_staticBody;
					shape.SetAsBox(0.1f, 0.1f);
					fd.density = 1.0f;
					bd.position.Set(endPosition.x, endPosition.y);
				}

				b2Body* body = box2dWorld.CreateBody(&bd);
				body->CreateFixture(&fd);

				auto objectEntity = anaxWorld.createEntity();
				auto& texCoordsComp = objectEntity.addComponent<Texcoords>();
				auto& physComp = objectEntity.addComponent<PhysicsComponent>();
				auto& splitDirectionComp = objectEntity.addComponent<SplitDirectionComponent>();
				auto& breakableJointComp = objectEntity.addComponent<BreakableJointComponent>();
				breakableJointComp.maxWeight = 1 ;


				b2Vec2 anchor( statingPosition.x + xVal  , statingPosition.y );
				jd.Initialize(prevBody, body, anchor);
				box2dWorld.CreateJoint(&jd);

				physComp.physicsBody = body;

				objectEntity.activate();
				prevBody = body;
			}

		}



	}
Exemplo n.º 3
0
void Guard::addPatrolPoints(tmx::MapObject points)
{
    sf::Vector2f origin(points.GetPosition());
    for(sf::Vector2f point: points.PolyPoints())
    {
        sf::Vector2f patrolPoint(origin.x + point.x, origin.y + point.y);
        _patrolPoints.push_back(patrolPoint);
    }
    initialize();
    setPosition(_patrolPoints[0]);

}
Exemplo n.º 4
0
bool entity_intersects(Entity& entity, tmx::MapObject& obj)
{
	sf::FloatRect objRect(createRect(OrthogonalToIsometric(obj.GetPosition()), obj.GetSize()));
	return  (createRect(OrthogonalToIsometric(entity.objectEntity->GetPosition()), entity.objectEntity->GetSize()).intersects(objRect));
}
Exemplo n.º 5
0
bool entity_ojectInView(tmx::MapObject& object, sf::View& view)
{
	return createRect(object.GetPosition(), object.GetSize()).intersects((createRect(view.getCenter() - view.getSize() / 1.5f, view.getSize() * 1.5f)));
}