Example #1
0
int main()
{
	System::Window::Instance()->SetTitle(L"OpenGL Init test");
	System::Mouse::Instance()->LockInWindow(false);
	
	OpenGL::Driver::Instance()->Start();

	System::EventManager::Instance()->SubscribeHandler(System::EVENT_IDLE, System::EventHandler(Idle));
	System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_LBUTTON_DOWN, System::EventHandler(OnMouseLeftButtonDown));	
	System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_LBUTTON_UP, System::EventHandler(OnMouseLeftButtonUp));
	System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_MOVE, System::EventHandler(OnMouseMove));
	System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_WHEEL, System::EventHandler(OnMouseWheelScroll));

	OpenGL::RenderTargetBackBuffer::RenderTargetBackBufferProperties p;		
	rt = OpenGL::Driver::Instance()->CreateRenderTarget(&p);
	rt->SetClearColor(0.6, 0.6, 0.6, 1);

	if (!rt)
	{
		out_error() << "Render target was not created" << std::endl;
		return 0;
	}

	CreateWorld();

	System::Window::Instance()->Loop();
	
	System::MegaDestroyer::Destroy();
	return 0;
}
Example #2
0
TEST(ECS, GettingAllComponents)
{
	// Initialize a world and some components
	ECS::World* world = CreateWorld();
	g_world = world;

	// Create entities with different permutations of components
	ECS::Entity* e12 = world->GetEntityManager()->CreateEntity();
	ECS::Entity* e1 = world->GetEntityManager()->CreateEntity();
	ECS::Entity* e2 = world->GetEntityManager()->CreateEntity();
	
	world->GetEntityManager()->CreateComponent<RootForce::Transform>(e12);
	world->GetEntityManager()->CreateComponent<RootForce::HealthComponent>(e12);
	world->GetEntityManager()->CreateComponent<RootForce::Transform>(e1);
	world->GetEntityManager()->CreateComponent<RootForce::HealthComponent>(e2);

	// Retrieve all components
	auto r12 = world->GetEntityManager()->GetAllComponents(e12);
	auto r1 = world->GetEntityManager()->GetAllComponents(e1);
	auto r2 = world->GetEntityManager()->GetAllComponents(e2);

	// Make sure we get the correct number of components
	ASSERT_EQ(r12.size(), 2);
	ASSERT_EQ(r1.size(), 1);
	ASSERT_EQ(r2.size(), 1);

	// Make sure the components are of the proper type
	ASSERT_EQ(r12[0].first, RootForce::Transform::GetTypeId());
	ASSERT_EQ(r12[1].first, RootForce::HealthComponent::GetTypeId());
	ASSERT_EQ(r1[0].first, RootForce::Transform::GetTypeId());
	ASSERT_EQ(r2[0].first, RootForce::HealthComponent::GetTypeId());
}
Example #3
0
void handle_simple_display(void) {
	Vec3 focus = camera->get_focalvector();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(camera->aperture, camera->screenwidth/(double) camera->screenheight, 0.1, 10000.0);
	glViewport(0, 0, camera->screenwidth, camera->screenheight);

	// Create the model

	gluLookAt(camera->vpos.x, camera->vpos.y, camera->vpos.z, focus.x, focus.y, focus.z,
	camera->vup.x, camera->vup.y, camera->vup.z);
	glShadeModel(GL_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LINE_SMOOTH);
	CreateWorld();

	if (windowdump || movierecord) {
		WindowDump(camera->screenwidth, camera->screenheight);
		windowdump = 0;
	}

	glutSwapBuffers();
}
Example #4
0
TEST(AbilitySpawn, LoadAndAttatch)
{
	ECS::World* world = CreateWorld();
	g_world = world;
	g_networkEntityMap.clear();

	ECS::Entity* testity = world->GetEntityManager()->CreateEntity();
	world->GetGroupManager()->RegisterEntity("AbilitySpawnPoint", testity);
	RootForce::AbilitySpawnSystem* system = new RootForce::AbilitySpawnSystem(world, &g_engineContext, g_engineContext.m_resourceManager->GetWorkingDirectory());
	world->GetSystemManager()->AddSystem<RootForce::AbilitySpawnSystem>(system);
	g_engineContext.m_resourceManager->LoadScript("AbilityBall");
	g_engineContext.m_resourceManager->LoadScript("AbilitySpawnPoint");
	//Test so that loading an ability pack works
	{
		system->LoadAbilities("Fake"); //Load a fake pack, should give a logg message but no crash

		system->LoadAbilities("Standard"); //Load existing pack
	}

	{
		system->AttachComponentToPoints();

		RootForce::AbilitySpawnComponent* component = world->GetEntityManager()->GetComponent<RootForce::AbilitySpawnComponent>(testity);
		EXPECT_NE(component, nullptr); //Make sure that the component was attached correctly by checking so that it is not null
	}

	world->GetEntityManager()->RemoveAllEntitiesAndComponents();
	world->GetTagManager()->UnregisterAll();
	world->GetGroupManager()->UnregisterAll();
	g_engineContext.m_physics->RemoveAll();
	delete world;
}
Example #5
0
gint main(gint argc, gchar* argv[]){
  char* hw = "`r```````````.H.e.l.l.o. .w.o.r.l.di";
  char* fib =  "```s``s``sii`ki\n"
"`k.*``s``s`ks\n"
"``s`k`s`ks``s``s`ks``s`k`s`kr``s`k`sikk\n"
"`k``s`ksk";
  /*
   * http://www.madore.org/~david/programs/unlambda/
   */
  World* world;
  UnlambdaEval* ue;
  GOptionContext *context;
  GError *error = NULL;

  context = g_option_context_new("This line is appeared after Uagese's command line");
  g_option_context_set_summary(context, "This line is appeared before options");
  g_option_context_set_description(context, "This line is appeared after options");
  if(!g_option_context_parse(context, &argc, &argv, &error)){
    g_printerr("option parsing failed: %s\n", error->message);
    return 1;
  }

  world = CreateWorld(MAXOBJECTS);
  setWorld(world);
  ue = NewUnlambdaEval(world);

  printf("%s\n", fib);
  //eval(hw);
  UnlambdaEval_eval(ue, fib);
  DeleteWorld(world);

  return 0;
}
Example #6
0
 void  CScenePhyscs::	CreateShellsSelected()
 {
    if(b_update_level_collision)
    	DestroyObjectSpace();
 	if(!m_object_space)
    	CreateObjectSpace(false);
        
	CreateWorld					();
    CreatePhysicsShellsSelected	();
 }
Example #7
0
NewWorldDialog::NewWorldDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NewWorldDialog)
{
    ui->setupUi(this);
    selected_object = NULL;

    for (int i = 0; i < Class::nmetaclasses; i++)
    {
        Class* c = Class::metaclasses[i];
        if (c->abstract) continue;
        for (Class* p = c; p; p = Class::Lookup(p->pname))
        {
            if (strcmp(p->name, "Block") == 0)
            {
                ui->prototypeList->addItem(c->name);
                break;
            }
            if (strcmp(p->name, "Shape") == 0)
            {
                ui->prototypeList->addItem(c->name);
                break;
            }
        }
    }
    ui->prototypeList->setCurrentRow(0);

    ui->objectTable->setDragDropMode(QAbstractItemView::InternalMove);

    ui->splitter->setStretchFactor(0,3);
    ui->splitter->setStretchFactor(1,2);
    ui->objectTable->setFocus();

    ui->containerObject->setLayout(new QGridLayout);

    ui->commentBox->setVisible(false);

    DeselectObject();

    is_start = true;

    connect(ui->objectTable, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), ui->prototypeList, SLOT(clearSelection()));
    connect(ui->prototypeList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(DeselectObject()));
    connect(ui->saveTemplate, SIGNAL(released()), this, SLOT(SaveTemplate()));
    connect(ui->loadTemplate, SIGNAL(released()), this, SLOT(LoadTemplate()));
    connect(ui->copyObject, SIGNAL(released()), this, SLOT(CopyObject()));
    connect(ui->addObject, SIGNAL(released()), this, SLOT(AddObject()));
    connect(ui->removeObject, SIGNAL(released()), this, SLOT(RemoveObject()));
    connect(ui->objectTable, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(SelectObject(QListWidgetItem*,QListWidgetItem*)));
    connect(ui->numberBox, SIGNAL(valueChanged(int)), this, SLOT(SetObjectNumber(int)));
    connect(ui->commentVisibleBox, SIGNAL(toggled(bool)), ui->commentBox, SLOT(setVisible(bool)));
    connect(this, SIGNAL(accepted()), SLOT(CreateWorld()));


}
Example #8
0
bool GameWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
	CreateWorld();
	CreateGame();
    return true;
}
Example #9
0
void LevelLoad(int levelNum) {
  switch (levelNum)
  {
    case 1:
      CreateWorld();
      break;

    case 2:
       l1.CreateLevel();
      break;
 
  }
}
Example #10
0
void CreateWorldDialog::OKBtnClicked()
{
	if(ui->worldNameLineEdit->text() == "")
	{
		QMessageBox::warning(this, tr("Warning"),
			tr("The world name can't be empty!"),
			QMessageBox::Ok);
	}
	else
	{
		emit CreateWorld(ui->worldNameLineEdit->text().trimmed());
	}
}
Example #11
0
TEST(ECS, NullComponent)
{
	// Initialize a world and some components
	ECS::World* world = CreateWorld();

	// Create an entity
	ECS::Entity* e = world->GetEntityManager()->CreateEntity();
	
	// Assert that trying to get a component returns null
	ASSERT_EQ(world->GetEntityManager()->GetComponent<RootForce::Transform>(e), nullptr);

	// Add component and test again
	world->GetEntityManager()->CreateComponent<RootForce::Transform>(e);

	ASSERT_NE(world->GetEntityManager()->GetComponent<RootForce::Transform>(e), nullptr);
}
Example #12
0
TEST(AbilitySpawn, ProcessEmptyEntity)
{
	ECS::World* world = CreateWorld();
	g_world = world;
	g_networkEntityMap.clear();

	ECS::Entity* testity = world->GetEntityManager()->CreateEntity();
	RootForce::AbilitySpawnSystem* system = new RootForce::AbilitySpawnSystem(world, &g_engineContext, g_engineContext.m_resourceManager->GetWorkingDirectory());
	world->GetSystemManager()->AddSystem<RootForce::AbilitySpawnSystem>(system);
	// Will test that an empty entity (an entity missing the necessary components does not crash the system
	system->Process();
	world->GetEntityManager()->RemoveAllEntitiesAndComponents();
	world->GetTagManager()->UnregisterAll();
	world->GetGroupManager()->UnregisterAll();
	g_engineContext.m_physics->RemoveAll();
	delete world;
}
Example #13
0
CWorldEditor::CWorldEditor(bool isEmbedding)
: m_elapsed(0)
, m_mousePosition(0, 0)
{
	CGlobalResources::GetInstance().Initialize();

	CreateWorld();

	Palleon::CGraphicDevice::GetInstance().AddViewport(m_mainViewport.get());
	Palleon::CGraphicDevice::GetInstance().AddViewport(m_overlayViewport.get());

	if(!isEmbedding)
	{
		m_debugOverlay = std::make_shared<CDebugOverlay>();
		//CFileManager::SetGamePath("F:\\FFXIV_10_Copy");
		CreateMap(0xA09B0002);
	}
}
Example #14
0
TEST(AbilitySpawn, ProcessEntity)
{
	ECS::World* world = CreateWorld();
	g_world = world;
	g_networkEntityMap.clear();

	ECS::Entity* testity = world->GetEntityManager()->CreateEntity();
	world->GetGroupManager()->RegisterEntity("AbilitySpawnPoint", testity);
	RootForce::AbilitySpawnSystem* system = new RootForce::AbilitySpawnSystem(world, &g_engineContext, g_engineContext.m_resourceManager->GetWorkingDirectory());
	world->GetSystemManager()->AddSystem<RootForce::AbilitySpawnSystem>(system);

	g_engineContext.m_resourceManager->LoadScript("AbilityBall");
	g_engineContext.m_resourceManager->LoadScript("AbilitySpawnPoint");

	system->LoadAbilities("Standard"); //Load existing pack
	system->AttachComponentToPoints();

	RootForce::Renderable* rendcomp;
	RootForce::AbilitySpawnComponent* spawncomp;

	{
		system->Process();
		rendcomp = world->GetEntityManager()->GetComponent<RootForce::Renderable>(testity);
		spawncomp = world->GetEntityManager()->GetComponent<RootForce::AbilitySpawnComponent>(testity);
		EXPECT_NE(rendcomp, nullptr); //Make sure that a new render component was created in the process since the point had no active ability

		EXPECT_NE(spawncomp->CurrentAbility.Name, ""); //Check that we got an ability to spawn, if the name is empty there is no ability
	}

	{
		spawncomp->Claimed = true;
		system->Process();
		rendcomp = world->GetEntityManager()->GetComponent<RootForce::Renderable>(testity);
		EXPECT_EQ(spawncomp->Timer, 30.0f); //Check that the timer has been set after the ability was claimed
		EXPECT_EQ(spawncomp->CurrentAbility.Name, ""); //Check that there is no ability present at the point
		EXPECT_EQ(rendcomp, nullptr); //Check that the render component has been removed correctly
	}

	world->GetEntityManager()->RemoveAllEntitiesAndComponents();
	world->GetTagManager()->UnregisterAll();
	world->GetGroupManager()->UnregisterAll();
	g_engineContext.m_physics->RemoveAll();
	delete world;
}
Example #15
0
void PtLink::CreateWorld()
{
	float topLeftCornerArry[2];
	float bottomRightCornerArry[2];
	float tileDimensionsArry[2];
	
	topLeftCornerArry[0] = 1.0f;
	topLeftCornerArry[1] = 1.0f;
	
	bottomRightCornerArry[0] = 640.0f;
	bottomRightCornerArry[1] = 640.0f;
	
	tileDimensionsArry[0] = 32.0f;
	tileDimensionsArry[1] = 32.0f;
	
	_state = stateCreateWorlding;
	
	CreateWorld(topLeftCornerArry,bottomRightCornerArry,tileDimensionsArry);
}
Example #16
0
void SpaceSim::Initialize()
{
	done= false;
	FPS=0;
	total_frames=0;
	previous_tick_timestamp =0;
	elapsed_time=0;
	old_time=0;

	dt = .05;
	doubledt = dt*5;
	accumulator = 0.0;

	LoadContent();

	CreateWorld();

	Update();
};
Example #17
0
TEST(ECS, GetAllEntities)
{
	// Initialize a world and some entities
	ECS::World* world = CreateWorld();

	// Create a few entities
	const int NUM_ENTITIES = 5;
	ECS::Entity* e[NUM_ENTITIES];
	for (int i = 0; i < NUM_ENTITIES; ++i)
	{
		e[i] = world->GetEntityManager()->CreateEntity();
	}

	// Assert that we get the right entities
	std::vector<ECS::Entity*> entities = world->GetEntityManager()->GetAllEntities();

	ASSERT_EQ(entities.size(), NUM_ENTITIES);
	for (int i = 0; i < NUM_ENTITIES; ++i)
	{
		ASSERT_EQ(entities[i], e[i]);
	}
}
Example #18
0
int main(int argc,char** argv)
{
	glutInit(&argc,argv);

	init();
    glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);
	glutKeyboardUpFunc(KeyUp);
	glutSpecialFunc(SpecialFunction);
	glutIgnoreKeyRepeat(true);

	Timer->start();
	last_time=Timer->time();
	walkTimer = Timer->time();

    LoadImages(); 
    CreateObjects();
	CreateWorld();

	glutMainLoop();
	return 0;
}
Example #19
0
void
StarServer::SetGameMode(int m)
{
    if (game_mode == m)
    return;

    if (m == LOAD_MODE) {
        Print("  game_mode = LOAD_MODE\n");
        paused = true;
    }

    else if (m == PLAY_MODE) {
        Print("  game_mode = PLAY_MODE\n");

        if (!world) {
            CreateWorld();
            InstantiateMission();
        }

        // stand alone server should wait for players to connect
        // before unpausing the simulation...
        SetTimeCompression(1);
        Pause(true);
    }

    else if (m == MENU_MODE) {
        Print("  game_mode = MENU_MODE\n");
        paused = true;

        Sim* sim = (Sim*) world;

        if (sim)
        sim->UnloadMission();
    }

    game_mode = m;
}
Example #20
0
void
StarServer::GameState()
{
    if (lobby_server) {
        lobby_server->ExecFrame();

        if (lobby_server->GetStatus() == NetServerInfo::PERSISTENT)
        paused = NetGame::NumPlayers() < 1;
    }

    if (game_mode == MENU_MODE) {
        Sleep(30);
    }

    else if (game_mode == LOAD_MODE) {
        CreateWorld();
        InstantiateMission();

        SetGameMode(PLAY_MODE);
    }

    else if (game_mode == PLAY_MODE) {
        if (Game::GameTime() - time_mark > 60000) {
            time_mark = Game::GameTime();
            minutes++;
            if (minutes > 60)
            Print("  TIME %2d:%02d:00\n", minutes/60, minutes%60);
            else
            Print("  TIME    %2d:00\n", minutes);
        }

        Sleep(10);
    }

    Memory::Check();
}
Example #21
0
int main(int argc, char** argv)
{
	sf::RenderWindow window(sf::VideoMode(1000, 1000), "Physics Game!");

  delete world;
  CreateWorld();

  int currentLevel = 1;

  #pragma region Background Graphics
  // Load the background images, create a sprite and assign the image.
  // Sky
  sf::Texture backgroundTexture;
  backgroundTexture.loadFromFile("assets/Sky.png");
  backgroundTexture.setSmooth(true);
  backgroundTexture.setRepeated(true);
  sf::Sprite background;
  background.setPosition(0,0);
  background.setScale((float)window.getSize().x,1.0f);
  background.setTexture(backgroundTexture);

  // Sun
  sf::Texture sunTexture;
  sunTexture.loadFromFile("assets/Sun.png");
  sunTexture.setSmooth(true);
  sunTexture.setRepeated(true);
  sf::Sprite sun;
  sun.setPosition((window.getSize().x - (250*0.6f)) - window.getSize().x * 0.1f , 100);
  sun.setScale(0.6f,0.6f);
  sun.setTexture(sunTexture);

  // Cloud
  sf::Texture cloud1Texture;
  cloud1Texture.loadFromFile("assets/Cloud1.png");
  cloud1Texture.setSmooth(true);
  cloud1Texture.setRepeated(false);
  sf::Sprite cloud1;
  cloud1.setPosition(window.getSize().x*0.15f,80);
  cloud1.setScale(1.0f,1.0f);
  cloud1.setTexture(cloud1Texture);

  // Hills
  sf::Texture hillsTexture;
  hillsTexture.loadFromFile("assets/Hills.png");
  hillsTexture.setSmooth(false);
  hillsTexture.setRepeated(true);
  sf::Sprite hills1;
  hills1.setPosition(0,(float)window.getSize().y - 184);
  hills1.setScale(1.0f ,1.0f);
  hills1.setTexture(hillsTexture);
  sf::Sprite hills2;
  hills2.setPosition(766,(float)window.getSize().y - 184);
  hills2.setScale(1.0f,1.0f);
  hills2.setTexture(hillsTexture);
  sf::Sprite hills3;
  hills3.setPosition(766*2,(float)window.getSize().y - 184);
  hills3.setScale(1.0f,1.0f);
  hills3.setTexture(hillsTexture);
  #pragma endregion

	// Prepare for simulation. Typically we use a time step of 1/60 of a
	// second (60Hz) and 10 iterations. This provides a high quality simulation
	// in most game scenarios.
	float32 timeStep = 1.0f / 30.0f;
	int32 velocityIterations = 8;
	int32 positionIterations = 3;

  std::vector<shape> lines;

  sf::Texture wheel;
  wheel.loadFromFile("assets/Wheel.png");
  wheel.setSmooth(true);

  sf::Texture bikeWheel;
  bikeWheel.loadFromFile("assets/BikeWheel.png");
  bikeWheel.setSmooth(true);

  sf::Texture bikeFrame_t;
  bikeFrame_t.loadFromFile("assets/BikeFrame.png");
  bikeFrame_t.setSmooth(true);

  #pragma region events
  while (window.isOpen()) {

    static sf::Clock deltaClock;
    sf::Time deltaTime = deltaClock.restart();

    static float time;
    time += deltaTime.asSeconds() * 5;

    sf::Event event;
    while (window.pollEvent(event))
    {
      // If the window is closed, close the SFML window
      switch (event.type) {

      case sf::Event::Closed:
          window.close();
          break;

      // Resize window : set new size
      case sf::Event::Resized:
          window.setView(sf::View(sf::FloatRect(0.0f, 0.0f, (float)event.size.width, (float)event.size.height)));

          // Rescale and Reposition the background elements
          background.setScale((float)window.getSize().x,1.0f);
          sun.setPosition((window.getSize().x - (250*0.6f)) - window.getSize().x * 0.1f , 100);
          hills1.setPosition(0,(float)window.getSize().y - 184);
          hills2.setPosition(766,(float)window.getSize().y - 184);
          hills3.setPosition(766*2,(float)window.getSize().y - 184);
          break;

      case sf::Event::MouseButtonPressed:
          static bool pressed = false;
          static vector2 start,end;

          // When we click save the positions to a Vector2
          if(event.mouseButton.button == sf::Mouse::Left) {

          //printf("%f  -  %f\n", (float)event.mouseButton.x, (float)event.mouseButton.y);

            // If we are drawing lines constantly, dont perform click drawing
            if(!pressed) {
              start.x = (float)event.mouseButton.x;
              start.y = (float)event.mouseButton.y;
              pressed = true;
            } else {
              end.x = (float)event.mouseButton.x;
              end.y = (float)event.mouseButton.y;

              if(start == end) {
                pressed = false;
                break;
              }

              // Create the SFML visual box based on click locations
              shape sf_shape = shape(start,end, 2);
              lines.push_back(sf_shape);
        
              vector2 center = center.GetCenter(start, end);

              // Create the Box2D physics box.
              static b2FixtureDef myFixture;
              static b2BodyDef myBody;
              myBody.type = b2_staticBody;
              myBody.position.Set(center.x, center.y);
              b2Body* body = world->CreateBody(&myBody);
              b2Vec2 vertices[4];

              // Caluclate the positions of the Box2D Verts
              sf_shape.Box2DVertPos();
              vertices[0].Set(sf_shape.a.x * SCALE -start.x*0.5f, sf_shape.a.y * SCALE -start.y*0.5f);
              vertices[3].Set(sf_shape.b.x * SCALE -start.x*0.5f, sf_shape.b.y * SCALE -start.y*0.5f);
              vertices[2].Set(sf_shape.c.x * SCALE -start.x*0.5f, sf_shape.c.y * SCALE -start.y*0.5f);
              vertices[1].Set(sf_shape.d.x * SCALE -start.x*0.5f, sf_shape.d.y * SCALE -start.y*0.5f);

              b2PolygonShape polyShape;
              polyShape.Set(vertices, 4);
                 
              myFixture.shape = &polyShape;
              myFixture.density = 1;
              myFixture.friction = 1;
              body->CreateFixture(&myFixture);

              pressed = false;
            }
          }
        }
    }
    #pragma endregion

    if(currentLevel == 2) l1.Update();

    #pragma region Keyboard_Input__Reset
    // RESET ALL
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
      // Clear all SFML Lines
      lines.clear();
      // Pause the game
      paused = true;
      // Reset the World
      delete world;
      LevelLoad(currentLevel);
    }
    else if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) {
      // Reset the Level
      delete world;
      LevelLoad(currentLevel);

      // Recreate the physics on all the lines
      RecreateLines(lines);
      int x = 9;
      // Pause the game
      paused = true;
    }
    else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num1)) {
      // Clear all SFML Lines
      lines.clear();
      // Pause the game
      paused = true;
      // Reset the World
      delete world;
      LevelLoad(1);
      currentLevel = 1;
    } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num2)) {
      // Clear all SFML Lines
      lines.clear();
      // Pause the game
      paused = true;
      // Reset the World
      delete world;
      LevelLoad(2);
      currentLevel = 2;
    }
    #pragma endregion 

    #pragma region Pause
    static bool toggle = false;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
      if(!toggle) {
        paused = !paused;
        toggle = true;
      }
    } else {
      toggle = false;
    }
    #pragma endregion

    if(time > 0.016f) {
      if(!paused) world->Step(time, velocityIterations, positionIterations);
      time = 0;
    }

    window.clear();

    #pragma region BackgroundArt
    window.draw(background);
    window.draw(sun);
    window.draw(cloud1);
    window.draw(hills1);
    window.draw(hills2);
    window.draw(hills3);
    #pragma endregion

    #pragma region DrawSFML
    size_t size = 0;
    sf::ConvexShape cShape;
    cShape.setFillColor(sf::Color::Red);
    //This loops through every single body in the game world
    for(b2Body* b = world->GetBodyList(); b; b = b->GetNext()) {
      //This loops through every fixture in the current body
      for(b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {
        //This checks to see if the type of the fixture is a polygon, if it is then draw the polygon
        if(f->GetType() == b2Shape::e_polygon && currentLevel != 2) {
          // Create the convex shape
          static sf::ConvexShape cShape;
          cShape.setFillColor(sf::Color::Red);
          //Stores a pointer to the shape stored in the fixture
          b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
          //Get the amount of vertices stored in the shape
          size = s->GetVertexCount();
          //Set the size of the object in SFML so it knows how many vertices the shape should have
          cShape.setPointCount(size);
          //Loop through the vertices and send them from Box2D to the SFML shape
          for(int i = 0; i < size; i++) {
            //Stores the current vertex in v
            b2Vec2 v = s->GetVertex(i);
            //Converts the vertex from its local space to where it is in the world
            cShape.setPoint(i, sf::Vector2f((b->GetWorldVector(v).x + b->GetPosition().x), (b->GetWorldVector(v).y + b->GetPosition().y)));
          }
          //Draws the shape onto the window
          window.draw(cShape);
        }
        else if ((f->GetType() == b2Shape::e_polygon && b->GetType() == b2_dynamicBody)) {
          static sf::Sprite bikeFrame;
          bikeFrame.setTexture(bikeFrame_t);
          bikeFrame.setPosition(f->GetBody()->GetPosition().x, f->GetBody()->GetPosition().y);
          bikeFrame.setScale(0.5f,0.5f);
          bikeFrame.setRotation(b->GetAngle() * 57.2957795f);
          bikeFrame.setOrigin(0,0);
          window.draw(bikeFrame);
        }
        else if (f->GetType() == b2CircleShape::e_circle) {
          //  // Create A cricle to be drawn
          //  static sf::CircleShape circle;
          //  circle.setFillColor(sf::Color::Green);
          //  //Stores a pointer to the shape stored in the fixture
          //  b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
          //  // Calculate the radius for the SFML circle
          //  circle.setRadius(s->m_radius);
          //  circle.setPosition(f->GetBody()->GetPosition().x - circle.getRadius(), f->GetBody()->GetPosition().y - circle.getRadius());
          //  window.draw(circle);

          b2PolygonShape* s = (b2PolygonShape*)f->GetShape();
          static sf::Sprite sWheel;
          sWheel.setScale((s->m_radius*0.01)*2,(s->m_radius*0.01)*2);
          sWheel.setPosition (f->GetBody()->GetPosition().x, f->GetBody()->GetPosition().y);
          
          if(currentLevel == 1) sWheel.setTexture(wheel);
          if(currentLevel == 2) sWheel.setTexture(bikeWheel);
          sWheel.setOrigin(50,50);
          sWheel.setRotation(b->GetAngle() * 57.2957795f);
          window.draw(sWheel);

        }
      }
    }
    #pragma endregion

    #pragma region DrawClickedLines
    // draw all elements in line vector
    for(int i = 0; i != lines.size(); ++i) {
      static sf::VertexArray quad(sf::Quads, 4);
      quad[0].position = sf::Vector2f(lines[i].a.x, lines[i].a.y);
      quad[1].position = sf::Vector2f(lines[i].b.x, lines[i].b.y);
      quad[2].position = sf::Vector2f(lines[i].c.x, lines[i].c.y);
      quad[3].position = sf::Vector2f(lines[i].d.x, lines[i].d.y);
      for(int j = 0; j != quad.getVertexCount(); ++j)
        quad[j].color = sf::Color::Green;
      window.draw(quad);

      // Create shadows under all the lines
      static sf::VertexArray shadow(sf::Quads, 4);
      shadow[0].position = sf::Vector2f(lines[i].a.x, lines[i].a.y);
      shadow[1].position = sf::Vector2f(lines[i].b.x, lines[i].b.y);
      shadow[2].position = sf::Vector2f(lines[i].c.x, lines[i].c.y+80);
      shadow[3].position = sf::Vector2f(lines[i].d.x, lines[i].d.y+80);
      shadow[0].color = sf::Color::Color(0,0,0,80);
      shadow[1].color = sf::Color::Color(0,0,0,80);
      shadow[2].color = sf::Color::Color(0,0,0,0);
      shadow[3].color = sf::Color::Color(0,0,0,0);
      window.draw(shadow);
    }
    #pragma endregion

    #pragma region Play/Pause
    // Change the play and pause Icon on screen based on state
    if(!paused) {
      static sf::VertexArray play(sf::Triangles, 3);
      vector2 location(10,10);
      play[0].position = sf::Vector2f(0  +location.x,  0 +location.y);
      play[1].position = sf::Vector2f(20 +location.x, 15 +location.y);
      play[2].position = sf::Vector2f(0  +location.x, 30 +location.y);
      
      play[0].color = sf::Color::Green;
      play[1].color = sf::Color::Green;
      play[2].color = sf::Color::Green;
      window.draw(play);
    } else {
      static sf::VertexArray pause1(sf::Quads, 4);
      static sf::VertexArray pause2(sf::Quads, 4);
      vector2 location(10,10);
      pause1[0].position = sf::Vector2f(0 +location.x, 0 +location.y);
      pause1[1].position = sf::Vector2f(5 +location.x, 0 +location.y);
      pause1[2].position = sf::Vector2f(5 +location.x, 30 +location.y);
      pause1[3].position = sf::Vector2f(0 +location.x, 30 +location.y);
      pause1[0].color = sf::Color::Blue;
      pause1[1].color = sf::Color::Blue;
      pause1[2].color = sf::Color::Blue;
      pause1[3].color = sf::Color::Blue;
      pause2[0].position = sf::Vector2f(10 +location.x, 0 +location.y);
      pause2[1].position = sf::Vector2f(15 +location.x, 0 +location.y);
      pause2[2].position = sf::Vector2f(15 +location.x, 30 +location.y);
      pause2[3].position = sf::Vector2f(10 +location.x, 30 +location.y);
      pause2[0].color = sf::Color::Blue;
      pause2[1].color = sf::Color::Blue;
      pause2[2].color = sf::Color::Blue;
      pause2[3].color = sf::Color::Blue;
      window.draw(pause1);
      window.draw(pause2);
    }
    #pragma endregion

  window.display();
  }

  
	return 0;
}
Example #22
0
TEST(PlayerControlSystem, Process)
{
	ECS::World* world = CreateWorld();
	world->SetDelta(1.0f);
	g_world = world;
	g_networkEntityMap.clear();

	// Initialize the keybindings we need for the test(not the complete list that is normally used)
	std::vector<RootForce::Keybinding> keybindings(6);
	keybindings[0].Bindings.push_back(SDL_SCANCODE_UP);
	keybindings[0].Bindings.push_back(SDL_SCANCODE_W);
	keybindings[0].Action = RootForce::PlayerAction::MOVE_FORWARDS;
	keybindings[0].Edge = true;

	keybindings[1].Bindings.push_back(SDL_SCANCODE_DOWN);
	keybindings[1].Bindings.push_back(SDL_SCANCODE_S);
	keybindings[1].Action = RootForce::PlayerAction::MOVE_BACKWARDS;
	keybindings[1].Edge = true;

	keybindings[4].Bindings.push_back(SDL_SCANCODE_SPACE);
	keybindings[4].Action = RootForce::PlayerAction::JUMP_PRESSED;
	keybindings[4].ActionUp = RootForce::PlayerAction::JUMP_RELEASED;
	keybindings[4].Edge = true;

	keybindings[5].Bindings.push_back((SDL_Scancode)RootEngine::InputManager::MouseButton::LEFT);
	keybindings[5].Action = RootForce::PlayerAction::ACTIVATE_ABILITY_PRESSED;
	keybindings[5].ActionUp = RootForce::PlayerAction::ACTIVATE_ABILITY_RELEASED;
	keybindings[5].Edge = true;

	keybindings.push_back(RootForce::Keybinding());
	keybindings[keybindings.size()-1].Bindings.push_back(SDL_SCANCODE_1);
	keybindings[keybindings.size()-1].Action = RootForce::PlayerAction::SELECT_ABILITY1;
	keybindings[keybindings.size()-1].Edge = true;

	keybindings.push_back(RootForce::Keybinding());
	keybindings[keybindings.size()-1].Bindings.push_back(SDL_SCANCODE_2);
	keybindings[keybindings.size()-1].Action = RootForce::PlayerAction::SELECT_ABILITY2;
	keybindings[keybindings.size()-1].Edge = true;

	keybindings.push_back(RootForce::Keybinding());
	keybindings[keybindings.size()-1].Bindings.push_back(SDL_SCANCODE_3);
	keybindings[keybindings.size()-1].Action = RootForce::PlayerAction::SELECT_ABILITY3;
	keybindings[keybindings.size()-1].Edge = true;


	RootForce::PlayerControlSystem* system = new RootForce::PlayerControlSystem(world);
	system->SetInputInterface(g_engineContext.m_inputSys);
	system->SetLoggingInterface(g_engineContext.m_logger);
	system->SetPhysicsInterface(g_engineContext.m_physics);
	system->SetKeybindings(keybindings);

	// Call the OnCreate script
	g_engineContext.m_script->SetGlobalNumber("UserID", 0);
	g_engineContext.m_script->SetGlobalNumber("IsClient", true);
	g_engineContext.m_script->SetFunction(g_engineContext.m_resourceManager->LoadScript("Player"), "OnCreate");
	//g_engineContext.m_script->AddParameterUserData(testity, sizeof(ECS::Entity*), "Entity");
	g_engineContext.m_script->AddParameterNumber(0);
	g_engineContext.m_script->AddParameterNumber(RootForce::Network::ReservedActionID::CONNECT);
	g_engineContext.m_script->ExecuteScript();

	ECS::Entity* testity = world->GetTagManager()->GetEntityByTag("Player");

	RootEngine::InputManager::InputInterface* ii = g_engineContext.m_inputSys;

	RootForce::PlayerActionComponent* action = world->GetEntityManager()->GetComponent<RootForce::PlayerActionComponent>(testity);

	//Fake event to test different keys
	SDL_Event falseevent;
	falseevent.type = SDL_KEYDOWN;
	falseevent.key.repeat = false;

	//Movement test
	{
		
		falseevent.key.keysym.scancode = SDL_SCANCODE_UP;
		ii->HandleInput(falseevent);

		system->Process();

		//Pushing just forward should set movepower to 1
		EXPECT_EQ(action->MovePower, 1);

		falseevent.key.keysym.scancode = SDL_SCANCODE_DOWN;
		ii->HandleInput(falseevent);
		falseevent.key.keysym.scancode = SDL_SCANCODE_UP;
		ii->HandleInput(falseevent);

		system->Process();

		//Pushing back and forth at the same time should cancel each other out
		EXPECT_EQ(action->MovePower, 0);

		
		falseevent.key.keysym.scancode = SDL_SCANCODE_DOWN;
		ii->HandleInput(falseevent);

		system->Process();

		//We have now released the up key and should be moving backwards
		EXPECT_EQ(action->MovePower, -1);
	}


	//Jump test
	{
		falseevent.key.keysym.scancode = SDL_SCANCODE_SPACE;
		falseevent.type = SDL_KEYDOWN;
		ii->HandleInput(falseevent);

		system->Process();

		EXPECT_GT(action->JumpTime, 0);
	}

	//Orientation test
	{
		SDL_Event falseMouseEvent;
		falseMouseEvent.type = SDL_MOUSEMOTION;
		falseMouseEvent.motion.x = 5;
		falseMouseEvent.motion.y = 140;
		falseMouseEvent.motion.xrel = 5;
		falseMouseEvent.motion.yrel = 140;
		ii->HandleInput(falseMouseEvent);

		system->Process();

		EXPECT_LT(action->Angle.y, 0);
		EXPECT_GT(action->Angle.x, 0);
	}

	world->GetEntityManager()->RemoveAllEntitiesAndComponents();
	world->GetTagManager()->UnregisterAll();
	world->GetGroupManager()->UnregisterAll();
	g_engineContext.m_physics->RemoveAll();
	delete world;
}
Example #23
0
//
// Init GL
//
int InitGL(GLvoid)					// All Setup For OpenGL Goes Here
{
    // seed rand generator
    srand((unsigned int)time(NULL));

    // Load the key codes --
    LoadKeyCodes();

    // enable all the goodies
    Super_LoadGlobals();

    Load_ConfigFile();
    Super_FireAnts();

    Create_Col_List();
    Create_Wall_List();


    //
    // loading sound library
    printf("Loading sound library, make sure 'music apps' are closed\n");
    Load_Audio();


    glShadeModel(GL_SMOOTH);					// Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);				// Black Background
    glClearDepth(1.0f);						// Depth Buffer Setup


    glEnable(GL_NORMALIZE);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glShadeModel(GL_SMOOTH);


    glEnable(GL_DEPTH_TEST);				// Enables Depth Testing
    glDepthFunc(GL_LEQUAL);					// The Type Of Depth Testing To Do
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations


    // have to load the quadrice to be used
    quadric=gluNewQuadric();			// Create A Pointer To The Quadric Object (NEW)
    gluQuadricNormals(quadric, GLU_SMOOTH);		// Create Smooth Normals (NEW)
    gluQuadricTexture(quadric, GL_TRUE);		// Create Texture Coords (NEW)


    GenerateFireAnts();

    CreateWorld();

    LoadCameras();

    // Load the objects
    InitObjects();
    GenerateLights();

    InitGlobals();

    Build_ParticleSet();
    Reset_FontID();

    // Load the title screen text
    Load_Titles();

    // load the text library
    Super_MainText();

    CreateWalls();

    //
    // Load the collsion test for the walll
    //

    // front wall
    InsertColSegment(world_ptr->x_min, world_ptr->y_max,
                     world_ptr->x_max, world_ptr->y_max);

    // right wall
    InsertColSegment(world_ptr->x_max, world_ptr->y_min,
                     world_ptr->x_max, world_ptr->y_max);

    // back wall
    InsertColSegment(world_ptr->x_min, world_ptr->y_min,
                     world_ptr->x_max, world_ptr->y_min);

    // left wall
    InsertColSegment(world_ptr->x_min, world_ptr->y_min,
                     world_ptr->x_min, world_ptr->y_max);

    //
    // for the network save
    // the number of bots incase it is changed
    MAX_SAVED_BOTS = MAX_FIRE_ANTS;


    // end of insertion

    Super_InitNetwork();

    //
    // begin in paused mode
    //
    Super_BeginPaused();

    mSuper_Loaded = LOADED_TRUE;


    return true;			// Initialization Went OK

} // end of the function
Example #24
0
void handle_display(void) {
	Vec3 focus = camera->get_focalvector();
	Vec3 right = camera->get_sidevector();

	glDrawBuffer(GL_BACK);
	glReadBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(camera->aperture, camera->screenwidth/(double) camera->screenheight, 0.1, 10000.0);
	glViewport(0, 0, camera->screenwidth, camera->screenheight);

	// Left eye filter
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	switch (glassestype) {
	case REDBLUE:
	case REDGREEN:
	case REDCYAN:
		glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
		break;
	case BLUERED:
		glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE);
		break;
	case GREENRED:
		glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE);
		break;
	case CYANRED:
		glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
		break;
	}

	// Create the model
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(camera->vpos.x - right.x, camera->vpos.y - right.y,
			camera->vpos.z - right.z, focus.x, focus.y, focus.z, camera->vup.x,
			camera->vup.y, camera->vup.z);
	CreateWorld();
	//glFlush();
	//glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

	glDrawBuffer(GL_BACK);
	glClear(GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(camera->aperture, camera->screenwidth/(double) camera->screenheight, 0.1, 10000.0);
	glViewport(0, 0, camera->screenwidth, camera->screenheight);

	// Right eye filter
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	switch (glassestype) {
	case REDBLUE:
		glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE);
		break;
	case REDGREEN:
		glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE);
		break;
	case REDCYAN:
		glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
		break;
	case BLUERED:
	case GREENRED:
	case CYANRED:
		glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
		break;
	}

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(camera->vpos.x + right.x, camera->vpos.y + right.y,
			camera->vpos.z + right.z, focus.x, focus.y, focus.z, camera->vup.x,
			camera->vup.y, camera->vup.z);
	CreateWorld();
	glFlush();
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

	if (windowdump || movierecord) {
		WindowDump(camera->screenwidth, camera->screenheight);
		windowdump = 0;
	}

	glutSwapBuffers();
}
//
// Init GL
//
int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
{
	// seed rand generator
	srand(getclock());

#if 0
	QueryPerformanceFrequency(&timerFrequency);
	QueryPerformanceCounter(&lastTime);
#endif

	// use the mouse only
	// for camera movement
	// disable the cursor 
	ShowCursor(FALSE);

	Super_LoadGlobals();

	Load_ConfigFile();

	// Now load main variables
	Super_LoadBots();	
	Super_FireAnts();
	
	Create_Col_List();

	Create_Wall_List();

	// enable all the goodies
	//glEnable(GL_TEXTURE_2D);		   // enable texture mapping
	
	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
	glClearDepth(1.0f);									// Depth Buffer Setup


	glEnable(GL_NORMALIZE);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	glShadeModel(GL_SMOOTH);


	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations


	// have to load the quadrice to be used
	quadric=gluNewQuadric();							// Create A Pointer To The Quadric Object (Return 0 If No Memory) (NEW)
	gluQuadricNormals(quadric, GLU_SMOOTH);			// Create Smooth Normals (NEW)
	gluQuadricTexture(quadric, GL_TRUE);				// Create Texture Coords (NEW)


#if ENABLE_LIGHTS
//	InitMaterial();
#endif


	GenerateBots();

	GenerateFireAnts();			// a new breed of warrior

	CreateWorld();

	LoadCameras();

	BuildFont();										// Build The Font

	// Load the objects
	InitObjects();

	GenerateLights();

	InitGlobals();		// for printing data, etc

	// generate the nest objects
	nest.generate();
	garden.generate();

	trail_set.generate();

	// give the ant food
	InitFood();

	Build_ParticleSet();

	Reset_FontID();


	// load the title screen text
	Load_Titles();

	// the text library
	Super_MainText();

	CreateWalls();

	//
	// Load the collision test for the wall
	// very easy test
	// 4 different walls
	//

	// front wall
	InsertColSegment(world_ptr->x_min, world_ptr->y_max, 
		world_ptr->x_max, world_ptr->y_max);

	// right wall
	InsertColSegment(world_ptr->x_max, world_ptr->y_min, 
		world_ptr->x_max, world_ptr->y_max);

	// back wall (top)
	InsertColSegment(world_ptr->x_min, world_ptr->y_min, 
		world_ptr->x_max, world_ptr->y_min);

	// left wall 
	InsertColSegment(world_ptr->x_min, world_ptr->y_min, 
		world_ptr->x_min, world_ptr->y_max);

	// end insertion --


	//
	// The first thing to do is begin in paused mode
	//
	Super_BeginPaused();



	mSuper_Loaded  = LOADED_TRUE;

	return TRUE;			// Initialization Went OK

} // end of the function