Пример #1
0
GinsengSandbox::GinsengSandbox(Engine *engine) : engine(engine)
{
    ModulePtr sensorModule(new Module());

    utility::add_class<FootSensor>(*sensorModule,
                                   "FootSensor",
    {  },
    { {fun(&FootSensor::OnGround), "OnGround"} }
                                  );

    engine->chai->add(sensorModule);

    accumulator = 0.f;

    sf::Vector2u wSize = engine->window.getSize();
    gridView.reset(sf::FloatRect(wSize.x / -2.f, wSize.y / -2.f, wSize.x, wSize.y));

    PhysicsWorld physicsWorld(b2Vec2(0.f, -9.81f * 8), 1.f / 60.f, 8, 3);
    physicsWorld.World->SetContactListener(new ContactListener());
    DebugDraw* debugDraw = new DebugDraw(engine->window, 64.f);
    debugDraw->SetFlags(b2Draw::e_shapeBit);
    physicsWorld.World->SetDebugDraw(debugDraw);
    db.makeComponent(db.makeEntity(), physicsWorld);

    loadLevel("data/scripts/level/test.json");

    EntID player = db.makeEntity();
    db.makeComponent(player, DynamicBody(physicsWorld, 4.f, 0.9f, 1.f , 1.8f));
    db.makeComponent(player, FootSensor(player.get<DynamicBody>().data().Body));
    db.makeComponent(player, AIComponent{PlayerAI(player)});
    engine->chai->add(var(player.get<FootSensor>().data()), "foot");
}
Пример #2
0
// Load your images here
void LoadImages ()
{
   myWorld.SetDebugDraw (&draw);
   draw.SetFlags ( DebugDraw::e_shapeBit | DebugDraw::e_aabbBit |
                   DebugDraw::e_jointBit | DebugDraw::e_centerOfMassBit | DebugDraw::e_pairBit);

   glutTimerFunc (1000 / 100.0, Update, 1);
   glutTimerFunc (2000 / 1000, Clear, 1);

}
Пример #3
0
void Game::Setup(void){
	sf::WindowSettings s = this->app->GetSettings();

	s.DepthBits = 24;
	s.StencilBits = 8;
	s.AntialiasingLevel = 4;


    this->app->PreserveOpenGLStates(true);
	this->app->SetFramerateLimit(60);

	glViewport(0,0,800,600);
	glEnable(GL_TEXTURE_RECTANGLE_EXT);
	glDisable( GL_LIGHTING );
	/* glDisable(GL_DITHER); */
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);

	// Setup a perspective projection
	glMatrixMode(GL_PROJECTION);

	glAlphaFunc(GL_GREATER, 0.5);
	glEnable(GL_ALPHA_TEST);

	glOrtho(0, 800, 600, 0, -100, 100);
	// Setup a perspective projection
	glMatrixMode(GL_MODELVIEW);

	// Displacement trick for exact pixelization
	glTranslatef(0.375, 0.375, 0);
	/* glTranslatef(0, 0, -5); */

	// Box2D initialization
	b2Vec2 gravity(0, 9.8f);

	b2World *w = Utils::GetWorld();
	w = new b2World(gravity);
	w->SetContinuousPhysics(true);
	this->world = w;
	Utils::SetWorld(w);

	// Ground definition
	b2BodyDef groundBodyDef;
	groundBodyDef.position.Set(0.0f / RATIO / 2, 0.0f / RATIO / 2);

	b2Body *groundBody = w->CreateBody(&groundBodyDef);

	b2EdgeShape groundEdge;
	b2FixtureDef boxShapeDef;
	boxShapeDef.shape = &groundEdge;
	groundEdge.Set(b2Vec2(0.0f, 600.0f / RATIO), b2Vec2(800.0f / RATIO, 600.0f / RATIO));

	/* b2PolygonShape groundBox; */
	/* groundBox.SetAsBox(800.0f / RATIO / 2, 600.0f / RATIO / 2); */
	/* groundBody->CreateFixture(&groundBox, 1.0f); */
	groundBody->CreateFixture(&boxShapeDef);

	// DebugDraw initialization
	if (DEBUG_DRAW) {
		DebugDraw *debug = new DebugDraw();
		this->world->SetDebugDraw(debug);

		uint32 flags = 0;
		flags += 1	* b2Draw::e_shapeBit;
		flags += 1	* b2Draw::e_jointBit;
		/* flags += 1	* b2Draw::e_aabbBit; */
		flags += 1	* b2Draw::e_pairBit;
		flags += 1	* b2Draw::e_centerOfMassBit;
	
		debug->SetFlags(flags);
	}

}