Example #1
0
/// This function handles any Events/Inputs thrown to the game
/// Do any input code here
/// Arguments are window => Window to register inputs from
/// THANKS TO JA_COP FOR HELPING ME OUT WITH THIS :)
void getEvents(sf::RenderWindow& window)
{
  sf::Event event;
  while(window.GetEvent(event))
  {
    switch(event.Type)
    {
      case sf::Event::Closed:
        window.Close();
      break;

      case sf::Event::KeyPressed:
        switch(event.Key.Code)
        {
          case sf::Key::Escape:
            window.Close();
          break;			

          default:
            // TODO: A call to some global key handler here? ;esa			
          break;
        }
     break;

     default:
       // I don't know what to do here but ja_cop says this:
       // Pass to input module or GUI module (placeholder)
       // so do that i guess
       // TODO: ADD MORE INPUTS
     break;
     }
  }
}
Example #2
0
//function
bool AccessOptions::exitGame(sf::RenderWindow &Menu, sf::RenderWindow &App)
{
    Menu.Close();
 //how do you delete the Game...just close window??
    App.Close();
    return true;
}
Example #3
0
void showCredits(sf::RenderWindow& app)
{
  Credits credit(app);

  //Credits loop
  while (app.IsOpened()) {

    //Process events
    sf::Event Event;

    //Window closed
    while (app.GetEvent(Event)) 
    {
      if(Event.Type == sf::Event::Closed)
        app.Close();

      //Escape key pressed
      if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))	
        app.Close();
    }

    if (credit.showCredits())
    {
      app.Clear();
      credit.update();
      app.Display();
      continue;
    }
    else
    {
      break;
    }
  }
}
Example #4
0
//function
bool AccessOptions::startNewGame(sf::RenderWindow &Menu, sf::RenderWindow &App)
{
    //needs world making to be made into a
    //function instead of something just found in the main.
     Menu.Close();

    App.Create(sf::VideoMode(800, 600, 32), "SectorTD");
    GameHandler::PlayGame(App);
    return true;

}
Example #5
0
bool quitApp(sf::RenderWindow &App,t_sharedData &sharedData, const CEGUI::EventArgs &e)
{
   App.Close();

   t_message message;

   message.id = QUIT_MESSAGE;

   {
      boost::unique_lock<boost::mutex> lock(sharedData.gameMutex);

      sharedData.gameBuffer.push_back(message);
   }

   sharedData.gameCondition.notify_one();

   return true;
}
int Splash::Run(sf::RenderWindow &win, sf::VideoMode &vMode)
{
	Event events;
	while(win.IsOpened())
	{
		while(win.GetEvent(events))
		{
			if(events.Type == Event::Closed)
				win.Close();
			if(win.GetInput().IsKeyDown(Key::Space)) return 2;
		}
		if(m_scripter.RunScript(&m_splashBgImg, &m_splashBgSp) == 2) return 2;
		win.Clear();
		win.Draw(m_splashBgSp);
		win.Display();
	}
	return -1;
}
Example #7
0
void MainMenuHandler::run(sf::RenderWindow& window) {
	ImageCache mainMenuImages;
	const sf::Image& logoImage = mainMenuImages.get(Path::findDataPath("graphics/logo.png"));

	// Entering main menu, no game should be running.
	GameHandler::instance.reset();

	// Make view that is as close to 640x480 as possible and centered.
	view = window.GetDefaultView();
	view.Zoom(std::min(view.GetRect().GetWidth() / 640, view.GetRect().GetHeight() / 480));
	view.SetCenter(view.GetHalfSize());
	window.SetView(view);

	window.SetFramerateLimit(30);

	// Position at the top of the window.
	sf::Sprite logoSprite(logoImage);
	logoSprite.SetCenter(logoImage.GetWidth() / 2, 0);
	logoSprite.SetPosition(window.GetView().GetRect().GetWidth() / 2, 1);

	// Build the main menu GUI.
	GUI::Container gui;
	gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("New game", 200, 100, 240, 50, boost::bind(&MainMenuHandler::startGame, this))));
	gui.insert(boost::shared_ptr<GUI::Object>(new GUI::Button("Exit", 250, 170, 140, 50, boost::bind(&sf::RenderWindow::Close, boost::ref(window)))));

	menuClosed = false;
	while (window.IsOpened() && !menuClosed) {
		sf::Event e;
		if (window.GetEvent(e)) {
			if (gui.handleEvent(e, window)) {
				continue;
			}
			if (e.Type == sf::Event::Closed || (e.Type == sf::Event::KeyPressed && e.Key.Code == sf::Key::Escape)) {
				window.Close();
				continue;
			}
		} else {
			window.Clear(sf::Color(0xcc, 0x66, 0x33));
			window.Draw(logoSprite);
			gui.draw(window);
			window.Display();
		}
	}
}
Example #8
0
vector<Start_Items*> Start_Items::SetHair(sf::RenderWindow& App, sf::Sprite* menu)
{
	vector<Start_Items*> parts;
	int ids=0;
	if (initalizeItems(ids,parts,menu) == 1) NULL;
	else EXIT_FAILURE;
	
	//cout << parts[0]->name << endl;
	
	sf::Image img_spr;
	img_spr.LoadFromFile("sprites/fig2t.png");
	sf::Sprite spr(img_spr);
	spr.SetPosition(200,210);
	spr.Scale(1.5,1.5);
	
	sf::Image i;
	i.LoadFromFile("items/hair/next_button.jpg");
	sf::Sprite next(i);
	next.SetPosition(691,491);
	
	vector<Start_Items*> eq2;
	vector<Start_Items*> all;
	sf::String hair_str;
	
	hair_str.SetPosition(100,500);
	
	while (App.IsOpened())
	{
		App.Clear();
		sf::Event Event;
		while (App.GetEvent(Event))
		{
			if (Event.Type == sf::Event::Closed)
				App.Close();
			if (Event.Type == sf::Event::MouseButtonPressed)
			{
				if (eq2.size() >=1 && !((Event.MouseButton.X >= 691 && Event.MouseButton.X <= 755) && 
				(Event.MouseButton.Y >= 491 && Event.MouseButton.Y <=555))) eq2.clear();
				for (int x=0; x<parts.size(); x++)
				{
					if ((Event.MouseButton.X >= parts[x]->hair.GetPosition().x && Event.MouseButton.X <= parts[x]->hair.GetPosition().x+26*(parts[x]->hair.GetScale().x)) && 
					(Event.MouseButton.Y >= parts[x]->hair.GetPosition().y  && Event.MouseButton.Y <= parts[x]->hair.GetPosition().y+40*(parts[x]->hair.GetScale().y)))
					eq2.push_back(parts[x]);
				}
				if ((Event.MouseButton.X >= 691 && Event.MouseButton.X <= 755) && (Event.MouseButton.Y >= 491 && Event.MouseButton.Y <=555)) 
				{
					ids+=1;
					all.push_back(eq2[0]);
					if (initalizeItems(ids,parts,menu) == 2) return all;
				}
				
				
			}
		}
		//cout << ids << endl;
		App.Draw(*(menu));
		
		spr.SetSubRect(sf::IntRect(0,0,32,48));
		App.Draw(spr);
		if (ids>0)
		{
			for (int x=0; x<all.size(); x++)
			{
				all[x]->hair.Scale(1,1);
				all[x]->hair.SetSubRect(sf::IntRect(0,0,32,48));
				all[x]->hair.SetPosition(spr.GetPosition().x, spr.GetPosition().y);
				App.Draw(all[x]->hair);
			}
		}
		for (int x=0; x<eq2.size(); x++) 
		{
			eq2[x]->hair.Scale(1,1);
			eq2[x]->hair.SetSubRect(sf::IntRect(0,0,32,48));
			eq2[x]->hair.SetPosition(spr.GetPosition().x, spr.GetPosition().y);
			hair_str.SetText("You have selected: "+eq2[x]->name);
			App.Draw(eq2[x]->hair);
			App.Draw(hair_str);
		}
		for (int x=0; x<parts.size(); x++)
		{
			int wid=400+(50*(x+1));
			int hei=200;
			if (wid>=601) 
			{
				hei=280;
				wid=400+(50*(x-3));
			}
			parts[x]->hair.SetSubRect(sf::IntRect(0,0,32,47));
			if (parts[x]->hair.GetScale().x != 1.5) parts[x]->hair.Scale(1.5,1.5);
			parts[x]->hair.SetPosition(wid,hei);
			App.Draw(parts[x]->hair);
		}
		App.Draw(next);
		App.Display();
	}
}
Example #9
0
//function
bool AccessOptions::runAccess(sf::RenderWindow &Menu, World& myWorld, Player& myPlayer)
{
    //extern World myWorld;
    //creating an image and using events
    sf::Event Event;

    sf::Image image;
    if(!image.LoadFromFile("images/accessMenu2.png"))
    return false;

    //create a sprite
    sf::Sprite sprite;
    sprite.SetImage(image);

    int xoffset = 50;
    int yoffset = 25;

    sprite.SetPosition(xoffset,yoffset);

    //list of Buttons on screen
    Button newGame = Button(305,73,Position(100+xoffset,42+yoffset));
    Button saveGame = Button(193,72,Position(165+xoffset,150+yoffset));
    Button resumeGame = Button(233,74,Position(144+xoffset,269+yoffset));
    Button exitGame = Button(139,87,Position(195+xoffset,380+yoffset));

    while(Menu.IsOpened())
    {
        //loop for event handling
        if(Menu.GetEvent(Event))
        {
            if(Event.Type==sf::Event::Closed)
            Menu.Close();

            Position click = Position(Event.MouseButton.X, Event.MouseButton.Y);
            //determining what button is pressed & task to follow
            if(Event.Type==sf::Event::MouseButtonPressed && newGame.clickedOn(click))
                {
                    sf::RenderWindow App;
                    startNewGame(Menu, App);
                }
            if(Event.Type==sf::Event::MouseButtonPressed && saveGame.clickedOn(click))
                {
                    saveSector(myWorld,myPlayer);
                }
            if(Event.Type==sf::Event::MouseButtonPressed && resumeGame.clickedOn(click))
                {
                    return true;
                }
            if(Event.Type==sf::Event::MouseButtonPressed &&exitGame.clickedOn(click))
                {
                    //also closes all other windows and system
                    return false;
                }
            }
        //clear window
        //Menu.Clear();

        //draw sprite
        Menu.Draw(sprite);
        //display
        Menu.Display();
    }
    return true;
}
Example #10
0
//function
bool AccessOptions::resumeGame(sf::RenderWindow &Menu)
{
    Menu.Close();
    return true;
}
void ProcessAppEvents(sf::RenderWindow &App, sf::View &v, GroupManager &gm)
{
    sf::Event Event;
    while (App.GetEvent(Event))
    {
        switch (Event.Type)
        {
            case sf::Event::Closed: App.Close(); break;
            case sf::Event::KeyPressed:
            {
                switch (Event.Key.Code)
                {
                    case sf::Key::Escape: App.Close(); break;
                    case sf::Key::Right:
                    case sf::Key::Left:
                    case sf::Key::Up:
                    case sf::Key::Down:
                    {
                        const int step = 5;
                        v = App.GetView();
                        int hor = 0, ver = 0;
                        if (Event.Key.Code == sf::Key::Left)
                            hor+=step;
                        if (Event.Key.Code == sf::Key::Right)
                            hor-=step;
                        if (Event.Key.Code == sf::Key::Up)
                            ver+=step;
                        if (Event.Key.Code == sf::Key::Down)
                            ver-=step;
                        v.Move(hor, ver);
                        App.SetView(v);
                        break;
                    }
                    case sf::Key::S:
                    case sf::Key::D:
                    {
                        //if (Event.Key.Code == sf::Key::S)
                        //    wanna_step_per_second-= wanna_step_per_second/10 - 1;
                        //if (Event.Key.Code == sf::Key::D)
                        //    wanna_step_per_second+= wanna_step_per_second/10 + 1;
                        //if (wanna_step_per_second <= 0)
                        //    step_per_second = 1;
                        //if (wanna_step_per_second >= 250)
                        //    step_per_second = 250;
                        //step_time = 1.0/wanna_step_per_second;
                        break;
                    }
                    case sf::Key::W:
                    case sf::Key::E:
                    {
                        if (Event.Key.Code == sf::Key::E)
                            gm.SetStepSize(gm.GetStepSize() + 0.005);
                        if (Event.Key.Code == sf::Key::W)
                            gm.SetStepSize(gm.GetStepSize() - 0.005);
                        break;
                    }
                    case sf::Key::Z:
                    case sf::Key::X:
                    {
                        if (Event.Key.Code == sf::Key::Z)
                            v.Zoom(1.01);
                        if (Event.Key.Code == sf::Key::X)
                            v.Zoom(1.0/1.01);
                        break;
                    }
                    case sf::Key::A:
                    {
                        step_mode = (STEP_MODE) ((int)SM_HARD_STEPS_CNT + (int)SM_FREE_STEPS_CNT - step_mode);
                        break;
                    }
                    default: break;
                }
                break;
            }
            case sf::Event::Resized:
            {
                int h = Event.Size.Height;
                int w = Event.Size.Width;
                v.SetHalfSize(w/2, h/2);
                break;
            }
            default: break;
        }
    }
}
Example #12
0
int main()
{
    // Create the main rendering window
    App.Create(sf::VideoMode(640,480,32), "SFML Graphics");
	UIState uistate;
	uistate.renderer = &App;

	InitEntities();
	PhysicsSub physSub(&App, &entitysystem); 
	RenderingSystem renderSys(&App, &entitysystem);
	ControllerSystem controller(&App, &entitysystem);
	ProjectileSystem projSys(&App, &entitysystem);

	bool inventory = false;
	int invX; 
	int invY;

	std::vector<Entity*> players; 
	entitysystem.getEntities<CompPlayer>(players);
	Entity* player = players[0];

    // Start game loop
	while (App.IsOpen())
    {
        // Process events
        sf::Event Event;
		while (App.PollEvent(Event))
        {
			uistate.uiEvents(Event);
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
			if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Right)
			{
				inventory = !inventory;
				if(inventory)
					invX = sf::Mouse::GetPosition(App).x;
					invY = sf::Mouse::GetPosition(App).y; 
			}
			if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left)
				makeProjectile();
		}

		controller.Tick(Clock.GetElapsedTime().AsSeconds());
		physSub.Tick(Clock.GetElapsedTime().AsSeconds());
		projSys.Tick(Clock.GetElapsedTime().AsSeconds());

        // Clear the screen with red color
		App.Clear(sf::Color::Black);

		uistate.imgui_prepare();
		if(widget::button(uistate, GEN_ID, sf::Vector2f(100, 30), sf::Vector2f(520, 10), "button", 24))
			entitysystem.deleteEntity(player);
		if(inventory)
			if(widget::button(uistate, GEN_ID, sf::Vector2f(100, 30), sf::Vector2f(invX, invY), "inventory", 20))
				player = makePlayer();

		uistate.imgui_finish();

		renderSys.Tick(Clock.GetElapsedTime().AsSeconds());

        // Display window contents on screen
        App.Display();

		Clock.Restart();
    }

    return EXIT_SUCCESS;
}