Beispiel #1
0
GameMap::GameMap(IGame *__game): IMap(__game)
{
    cells=0;
    width=0;
    height=0;
    initBlocks();
    initWater();
}
Beispiel #2
0
void Map::initPhysics ()
{
	b2Vec2 gravity;
	gravity.Set(0.0f, getGravity());
	_world = new b2World(gravity);

	_world->SetDestructionListener(&_destructionListener);

	//_world->SetWarmStarting(false);
	//_world->SetContinuousPhysics(false);
	//_world->SetSubStepping(false);
	_world->SetAutoClearForces(true);
	_world->SetContactListener(this);
	_world->SetContactFilter(this);

	const float zeroX = 0.0f;
	const float zeroY = -0.5f;
	const float width = getMapWidth();
	// added a small offset to allow water diving out of screen
	const float height = getMapHeight() + 1.0f;

	b2BodyDef lineBodyDef;
	lineBodyDef.type = b2_staticBody;
	lineBodyDef.position.Set(0, 0);
	b2Body* boxBody = _world->CreateBody(&lineBodyDef);

	b2EdgeShape edge;
	b2FixtureDef fd;
	fd.friction = 1.0f;
	fd.restitution = 0.2f;
	fd.shape = &edge;

	_borders.resize(BORDER_MAX);
	const bool isSideBorderFail = getSetting(msn::SIDEBORDERFAIL).toBool();
	_borders[BORDER_TOP] = new Border(BorderType::TOP, *this);
	_borders[BORDER_LEFT] = new Border(BorderType::LEFT, *this, isSideBorderFail);
	_borders[BORDER_RIGHT] = new Border(BorderType::RIGHT, *this, isSideBorderFail);
	_borders[BORDER_BOTTOM] = new Border(BorderType::BOTTOM, *this);
	_borders[BORDER_PLAYER_BOTTOM] = new Border(BorderType::PLAYER_BOTTOM, *this);

	edge.Set(b2Vec2(zeroX, zeroY), b2Vec2(width, zeroY));
	b2Fixture *top = boxBody->CreateFixture(&fd);
	top->SetUserData(_borders[BORDER_TOP]);

	edge.Set(b2Vec2(zeroX, zeroY), b2Vec2(zeroX, height));
	b2Fixture *left = boxBody->CreateFixture(&fd);
	left->SetUserData(_borders[BORDER_LEFT]);

	edge.Set(b2Vec2(width, height), b2Vec2(width, zeroY));
	b2Fixture *right = boxBody->CreateFixture(&fd);
	right->SetUserData(_borders[BORDER_RIGHT]);

	edge.Set(b2Vec2(zeroX, height), b2Vec2(width, height));
	b2Fixture *bottom = boxBody->CreateFixture(&fd);
	bottom->SetUserData(_borders[BORDER_BOTTOM]);

	edge.Set(b2Vec2(zeroX, height), b2Vec2(width, getMapHeight()));
	b2Fixture *playerBottom = boxBody->CreateFixture(&fd);
	playerBottom->SetUserData(_borders[BORDER_PLAYER_BOTTOM]);

	initWater();
}
/**
 * Hier findet die komplette Initialisierung des kompletten SPIEeles statt.
 * Inklusive der Datenhaltung und des SPIEelfeldes.
 */
void initGame ()
{   
    initCameraPosition();
    initTerrain();
    initWater();
}