Esempio n. 1
0
Game::Game()
{
    state = END;
    window.setFramerateLimit( 30 ); //framerate limit of the window
	if( !font.loadFromFile( "data/Fonts/calibri.ttf" ) )
	{
		std::cout << "Nie znaleziono czcionki!!!\n";
		return;
	}
	std::cout << "dziala\n";

	state = MENU;
}
Esempio n. 2
0
void Score::Draw(RenderWindow& window, Time timeSinceLastDrawCall)
{
	window.setFramerateLimit(70);
	window.clear();
	window.draw(ScoreBackground);
	window.draw(CoinsCollectedLabel);
	window.draw(Coins);
	window.draw(Lives);
	window.draw(LivesleftLabel);
	window.draw(ScoreMade);
	window.draw(ScoreMadeLabel);
	window.display();

}
Esempio n. 3
0
Game::Game(void)
{
	ContextSettings settings;
	settings.antialiasingLevel = 8;

	okno.create(VideoMode(1280,720), "Nazwa Gry", Style::Default, settings);

	state = END;
	okno.setFramerateLimit(100);

	if (!font.loadFromFile("data/font.ttf"))
	{
		MessageBox(NULL, "Font not found! Chceck data folder!", "ERROR", NULL);
		return;
	}

	state = MENU;
}
Esempio n. 4
0
int main(int argc,char** argv){
	RenderWindow *window;
	window = new RenderWindow(VideoMode(1366, 768), "srJna", Style::Fullscreen);
	window->setFramerateLimit(60);

	showWelcome(window);
	Game games[5];
	games[0] = Game("Electricity","../schemes/Electricity.gme", window);
	games[1] = Game("ForceAndWork", "../schemes/ForceAndWork.gme", window);
	games[2] = Game("Optics", "../schemes/Optics.gme", window);
	games[3] = Game("Biology", "../schemes/Biology.gme", window);
	games[4] = Game("Maths", "../schemes/Maths.gme", window);

	while (true){
		games[showMenue(window)].start();
	}

	return 0;
}
Esempio n. 5
0
Game::Game(void)
{
    ContextSettings settings;
    settings.antialiasingLevel = 8;

    window.create(VideoMode(1280,720),"Mechanized Techno Explorer",Style::Default,
                  settings);

    state = END;
    window.setFramerateLimit(100);

    if(!font.loadFromFile("data/Mecha.ttf"))
    {
        MessageBox(NULL,"Font not found!","ERROR",NULL);
        return;
    }

    state = MENU;
}
Esempio n. 6
0
	bool init() {
		VideoMode videoMode(width, height);
		window.create(videoMode, "Break Out");
		window.setVerticalSyncEnabled(true);
		window.setFramerateLimit(FRAMES_PER_SECOND);

		 if (!font.loadFromFile("res\\stocky.ttf"))
            return false;  
 
        if (!soundBuffer1.loadFromFile("res\\blip.wav"))
            return false;
         
        if (!soundBuffer2.loadFromFile("res\\blam.wav"))
            return false;
         
        if (!soundBuffer3.loadFromFile("res\\blap.wav"))
            return false;
 
        if (!soundBuffer4.loadFromFile("res\\blop.wav"))
            return false;

		setup();
		return true;
	}
Esempio n. 7
0
int main(int, char const**){
    // Create the main window
    RenderWindow window(VideoMode(800, 600), "SFML window");
    window.setFramerateLimit(60);

    
    Font font;
    if (!font.loadFromFile("Resources/sansation.ttf")) {
        return EXIT_FAILURE;
    }
    Text text(std::to_string(fps), font, 50);
    text.setColor(Color::White);
    text.setPosition(0,600-text.getGlobalBounds().height*2);
    
    tileTexture.loadFromFile("Resources/mapTileSpritesheet.png");

    guyTexture.loadFromFile("Resources/sprite1.png");
    // guyTexture.loadFromFile("Resources/guy.png");

    wallTexture.loadFromFile("Resources/64x64/b0.png");

    chestTexture.loadFromFile("Resources/chest.png");

    // std::cout << sizeof(tileTexture) << std::endl;

    dirtRect.left = 0;
    dirtRect.top = 0;
    dirtRect.width = 32;
    dirtRect.height = 32;
    
    Sprite dirt(tileTexture, dirtRect);
    
    grassRect.left = 32;
    grassRect.top = 0;
    grassRect.width = 32;
    grassRect.height = 32;
    
    Sprite grass(tileTexture, grassRect);

    wallRect.left = 0;
    wallRect.top = 0;
    wallRect.width = 32;
    wallRect.height = 32;

    Sprite wall(wallTexture,wallRect);

    Sprite closedChest(chestTexture,IntRect(0,0,16,16));
    closedChest.setScale(2,2);
    Sprite openChest(chestTexture,IntRect(17,0,16,16));
    openChest.setScale(2,2);

    // guyRect.left = 0;
    // guyRect.top = 128;
    // guyRect.width = 64; 
    // guyRect.height = 64;

    guyRect.left = 0;
    guyRect.top = 32;
    guyRect.width = 24; 
    guyRect.height = 24;

    Sprite guy(guyTexture, guyRect);
    // guy.setOrigin(guy.getLocalBounds().width/2, guy.getLocalBounds().height/2);
    // guy.setScale(32/24.0,32/24.0);
    guy.setPosition(windowWidth/2,windowHeight/2);

    RectangleShape guyHitBox(Vector2f(guy.getLocalBounds().width, guy.getLocalBounds().height));
    // guyHitBox.setOrigin(guyHitBox.getLocalBounds().width/2, guyHitBox.getLocalBounds().height/2);
    // guyHitBox.setScale(32/24.0,32/24.0);
    guyHitBox.setPosition(guy.getPosition());

    RectangleShape centerScreen(Vector2f(10,10));
    centerScreen.setPosition(windowWidth/2-5,windowHeight/2-5);
    centerScreen.setFillColor(Color(255,0,0));

    // std::cout << sizeof(dirt) << std::endl;
    // std::cout << sizeof(grass) << std::endl;
    
    tiles = new Tile[numTiles];
    for (int i = 0; i < numTiles; i++){
        if(i/columns == 0 || i / columns == rows-1 || i%columns == 0 || i%columns == columns-1){
            tiles[i].setVal(i/columns,i%columns,WALL,false);
        }
        else{
            tiles[i].setVal(i/columns,i%columns,GRASS,true);
        }
    }

    tiles[getTileIndex(5,5)].type = WALL;
    tiles[getTileIndex(5,5)].walkable = false;
    tiles[getTileIndex(6,5)].type = WALL;
    tiles[getTileIndex(6,5)].walkable = false;
    tiles[getTileIndex(7,5)].type = WALL;
    tiles[getTileIndex(7,5)].walkable = false;
    tiles[getTileIndex(8,5)].type = WALL;
    tiles[getTileIndex(8,5)].walkable = false;

    tiles[getTileIndex(5,18)].type = GRASS;
    tiles[getTileIndex(5,18)].walkable = false;
    tiles[getTileIndex(5,18)].chest = true;
    // tiles[getTileIndex(5,18)].chestOpen = true;

    // std::cout << sizeof(tiles[1]) << std::endl;
    
//    tiles[getTileIndex(2, 1)].setColor(Color::White);

    while (window.isOpen()){
        Event event;
        while (window.pollEvent(event)){
            // Close window: exit
            if (event.type == Event::Closed) {
                window.close();
            }
            // Escape pressed: exit
            if (event.type == Event::KeyPressed) {
                if(event.key.code == Keyboard::Escape){
                    window.close();
                }
                if(event.key.code == Keyboard::E){
                    tileAction(guy);
                }
            }
            if (event.type == Event::MouseButtonPressed)
            {
                if (event.mouseButton.button == Mouse::Left)
                {
                    int index = mouseToTile(event.mouseButton.x,event.mouseButton.y);
                    if (index >= 0) {
                        if(tiles[index].chest){
                            tiles[index].toggleState();
                        }
                    }
                }
            }
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
            facing = UP;
            guy.move(0,-movementSpeed);
            guyPos = guy.getPosition();
            FloatRect guyBox = guy.getLocalBounds();
            tempIndex = mouseToTile(guyPos.x+guyBox.width/2,guyPos.y);
            Tile tempTile = tiles[tempIndex];
            int tempRow = tempTile.row;
            int tempCol = tempTile.col;
            for(int i = tempCol-2; i < tempCol+2; i++){
                // tiles[getTileIndex(tempRow,i)].type = DIRT;
                tempTile = tiles[getTileIndex(tempRow,i)];
                if(!tempTile.walkable){
                    int z1 = (tempTile.x +tempTile.width/2) - (guyPos.x + guyBox.width/2);
                    int z2 = (tempTile.y +tempTile.height/2) - (guyPos.y + guyBox.height/2);
                    int z3 = tempTile.width/2 + guyBox.width/2;
                    int z4 = tempTile.height/2 + guyBox.height/2;
                    if(std::abs(z1) < z3 && std::abs(z2) < z4){
                        // printf("top\n");
                        guyPos = Vector2f(guyPos.x, tempTile.y + tempTile.height+spacing);
                        guy.setPosition(guyPos);
                    }
                }
            }
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
            facing = DOWN;
            guy.move(0,movementSpeed);
            guyPos = guy.getPosition();
            FloatRect guyBox = guy.getLocalBounds();
            tempIndex = mouseToTile(guyPos.x+guyBox.width/2,guyPos.y+guyBox.height);
            Tile tempTile = tiles[tempIndex];
            int tempRow = tempTile.row;
            int tempCol = tempTile.col;
            for(int i = tempCol-2; i < tempCol+2; i++){
                // tiles[getTileIndex(tempRow,i)].type = DIRT;
                tempTile = tiles[getTileIndex(tempRow,i)];
                if(!tempTile.walkable){
                    int z1 = (tempTile.x +tempTile.width/2) - (guyPos.x + guyBox.width/2);
                    int z2 = (tempTile.y +tempTile.height/2) - (guyPos.y + guyBox.height/2);
                    int z3 = tempTile.width/2 + guyBox.width/2;
                    int z4 = tempTile.height/2 + guyBox.height/2;
                    if(std::abs(z1) < z3 && std::abs(z2) < z4){
                        // printf("bottom\n");
                        guyPos = Vector2f(guyPos.x, tempTile.y - guyBox.height - spacing);
                        guy.setPosition(guyPos);
                    }
                }
            }
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
            facing = LEFT;
            guy.move(-movementSpeed,0);
            guyPos = guy.getPosition();
            FloatRect guyBox = guy.getLocalBounds();
            tempIndex = mouseToTile(guyPos.x,guyPos.y+guyBox.height/2);
            Tile tempTile = tiles[tempIndex];
            int tempRow = tempTile.row;
            int tempCol = tempTile.col;
            for(int i = tempRow-2; i < tempRow+2; i++){
                tempTile = tiles[getTileIndex(i,tempCol)];
                // tiles[getTileIndex(i,tempCol)].type = DIRT;
                if(!tempTile.walkable){
                    int z1 = (tempTile.x +tempTile.width/2) - (guyPos.x + guyBox.width/2);
                    int z2 = (tempTile.y +tempTile.height/2) - (guyPos.y + guyBox.height/2);
                    int z3 = tempTile.width/2 + guyBox.width/2;
                    int z4 = tempTile.height/2 + guyBox.height/2;
                    if(std::abs(z1) < z3 && std::abs(z2) < z4){
                        // printf("left\n");
                        guyPos = Vector2f(tempTile.x + tempTile.width+spacing,guyPos.y);
                        guy.setPosition(guyPos);
                    }
                }
            }
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
            facing = RIGHT;
            guy.move(movementSpeed,0);
            guyPos = guy.getPosition();
            FloatRect guyBox = guy.getLocalBounds();
            tempIndex = mouseToTile(guyPos.x+guyBox.width,guyPos.y+guyBox.height/2);
            Tile tempTile = tiles[tempIndex];
            int tempRow = tempTile.row;
            int tempCol = tempTile.col;
            for(int i = tempRow-2; i < tempRow+2; i++){
                // tiles[getTileIndex(i,tempCol)].type = DIRT;
                tempTile = tiles[getTileIndex(i,tempCol)];
                if(!tempTile.walkable){
                    int z1 = (tempTile.x +tempTile.width/2) - (guyPos.x + guyBox.width/2);
                    int z2 = (tempTile.y +tempTile.height/2) - (guyPos.y + guyBox.height/2);
                    int z3 = tempTile.width/2 + guyBox.width/2;
                    int z4 = tempTile.height/2 + guyBox.height/2;
                    if(std::abs(z1) < z3 && std::abs(z2) < z4){
                        // printf("right\n");
                        guyPos = Vector2f(tempTile.x - guyBox.width - spacing,guyPos.y);
                        guy.setPosition(guyPos);
                    }
                }
            }
        }

        guyHitBox.setPosition(guy.getPosition());
        
        calculateFPS();
        
        text.setString(std::to_string(fps));
        closedChest.setPosition(-100,-100);
        openChest.setPosition(-100,-100);

        window.clear(Color(0,0,0));

        for (int i = 0; i < numTiles; i++){
            switch (tiles[i].type){
                case DIRT:
                    dirt.setPosition(tiles[i].x,tiles[i].y);
                    window.draw(dirt);
                    break;
                case GRASS:
                    grass.setPosition(tiles[i].x,tiles[i].y);
                    window.draw(grass);
                    break;
                case WALL:
                    wall.setPosition(tiles[i].x,tiles[i].y);
                    window.draw(wall);
                    break;
            }
            if(tiles[i].chest){
                if(tiles[i].chestOpen){
                    openChest.setPosition(tiles[i].x,tiles[i].y);
                    window.draw(openChest);
                }
                else{
                    closedChest.setPosition(tiles[i].x,tiles[i].y);
                    window.draw(closedChest);
                }
            }
        }
        window.draw(guyHitBox);
        window.draw(guy);
        // window.draw(openChest);
        window.draw(text); //FPS 
        // window.draw(centerScreen);
        
//        window.draw(dirt);

        window.display();
    }

    return EXIT_SUCCESS;
}
Esempio n. 8
0
int main()
{
    // Creates the window to show your game
    RenderWindow *window;
    window = new RenderWindow(VideoMode(800, 600),"Ping Pong");
    window->setFramerateLimit (25);

    Sprite *background = new Sprite(); // a pointer for sprite
    Texture bg; // bgtex to store the texture

	if(!bg.loadFromFile("assets/background.png")) // Loads image as texture. Image must at least be 610 x 600
		std::cout<<"\nError loading image";
	else
		background->setTexture (bg);   // you set the texture to the sprite

	// Use setTextureRect() function to set the texture to some of the window
	background->setTextureRect (IntRect (0, 0, 610, 600));

    //Initialize the game objects
    onCreate ();

    // The Game Loop

    while (window->isOpen ())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        Event event;
        while (window->pollEvent (event))
        {
            //Window is closed or 'Esc' key is pressed
            if (event.type == Event::Closed || (event.type == Event::KeyPressed && event.key.code == Keyboard::Escape))
                window->close ();
        }

		//checks User input
        InputHandler (window);

		//update positions,scores etc.
        GameUpdate ();

		//perform AI operations
       	AIOperation ();

        //Clears the window every frame to render updated positions. MUST DO
        window->clear (sf::Color::White);

	    //Draw the background image
		window->draw (*background);

        //Draw everything else here
        Display (window);

		//Check score
		ScoreManager (window);

		if (ResultManager (window) ) onEnd ();

		//Display everything on the Window
        window->display();
    }

	//free memory
	delete background;
	delete window;

    return 0;
}
Esempio n. 9
0
int main(int argc, char* argv[])
{
	setlocale(LC_ALL, "polish");
	string title = "Deltix v.";
	title += VERSION;
	///////////////////
	RenderWindow okno; //OKNO
	try
	{
		okno.create(VideoMode(RESOLUTION_WIDTH, RESOLUTION_HEIGHT, COLOR_DEPTH),
			title,
#if __MODE__ != 0
			Style::Fullscreen
#elif __MODE__ == 0
			Style::Default
#endif
			); //TWORZENIE OKNA
		okno.setFramerateLimit(200); //limit do 200fps
		okno.setMouseCursorVisible(false);
	}
	catch (...)
	{
		string temp = "BŁĄD - " + title;
		MessageBox(NULL, "Nie udało się utworzyć okna!", temp.c_str(), MB_OK | MB_ICONERROR);
		return 1;
	}
	
	/////////////////////
	
	States states = Splash;
	// PĘTLA
	while(okno.isOpen())
	{

		switch (states)
		{
		case Splash:
			
			if (SplashUpdate(&okno) < 0)

				states = Menu;
			break;
		case Menu:
			MenuUpdate(&okno);
			break;
		}


		Event eventMain;
		while (okno.pollEvent(eventMain))
		{
			if (eventMain.type == Event::Closed)
				okno.close(); // zamykanie
			/*if (eventMain.type == Event::KeyReleased && eventMain.key.code == Keyboard::C)
			{
				STARTUPINFO si;
				PROCESS_INFORMATION pi;

				ZeroMemory(&si, sizeof(si));
				si.cb = sizeof(si);
				ZeroMemory(&pi, sizeof(pi));
				CreateProcess(TEXT("C:\\WINDOWS\\System32\\calc.exe"), NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
			}*/ // SYSTEMOWY KALKULATOR pod "C"
			switch (states)
			{
			case Menu:
				MenuEvents(&okno, eventMain); //Eventy Menu
				break;
			}
				
		}//TABELA EVENTÓW
		
		if (states != Splash) drawPointer(&okno);
		okno.display();
	}

#if __DEBUG__ == 1
	system("pause");
#endif
	return 0;
}
Esempio n. 10
0
int main()
{
    //-----------------------------
    RenderWindow window; //creates the main window
    window.create(VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "SFML Works!"); //gives the main window attributes such as width, height, and a name
    //-----------------------------

    //-----------------------------
    window.setFramerateLimit(60);//sets frame rate (makes game speed faster/slower)
    //-----------------------------

    //-----------------------------
    RectangleShape mybox; //A rectangle shape
    mybox.setFillColor(Color::Red); //sets color
    mybox.setSize(Vector2f(20,30)/*an xy coordinate using float*/); //sets size
    mybox.setPosition(0,0); //sets position using the upper left corner of the box by default
    //-----------------------------


    //-----------------------------
    while (window.isOpen()) //the almighty gameloop (Keeps game running until gameover)
    {
        Event event; //creates an event, so we have access to it's many wonderful functions
        while (window.pollEvent(event))// event loop (constantly checks for user inputs and queues the actions)
        {
            switch (event.type)// checks the type of the event...
            {
            case Event::Closed: //closed event, triggered by clicking the X button
                window.close(); //closes the window
                break;

                // key pressed
            case Event::KeyPressed: //KeyPressed event, triggered by pressing any key
                switch (event.key.code) //takes in user inputs and performs actions
                {
                case Keyboard::Escape: //if esc button is pressed...
                    window.close();//close the window
                    break;

                case Keyboard::W://if W is pressed...
                    mybox.move(Vector2f(0,-5));//move the box up
                    break;

                case Keyboard::A://if A is pressed...
                    mybox.move(Vector2f(-5,0));//move the box left
                    break;

                case Keyboard::S://if S is pressed...
                    mybox.move(Vector2f(0,5));//move the box down
                    break;

                case Keyboard::D://if D is pressed...
                    mybox.move(Vector2f(5,0));//move the box right
                    break;

                default:
                    break;
                }//end of switch (event.key.code)
                break;

            default:
                break;
            }//end of switch (event.type)
        }//end of while (window.pollEvent(event))


        //~~~~~~~~~~~~~~~
        process();
        //~~~~~~~~~~~~~~~


        //~~~~~~~~~~~~~~~
        window.clear();//clears the screen
        window.draw(mybox);//draws your box shape on the screen (note: invisible unless displayed)
        //window.display();//displays what ever you drew.
        //~~~~~~~~~~~~~~~

    }//end of while (window.isOpen())

    //-----------------------------

}//end of int main()
Esempio n. 11
0
void	Client::Start()
{
  //Creating Everything

  RenderWindow *window = RenderWindow::getInstance();
  _network = new Network();
  _UDPnetwork = new Network();
  _sound = new Sound();

  //Connecting to server

  _network->init(window->getSettings()->getPort(), ANetwork::TCP_MODE);
  std::cout << "Connecting to : " << window->getSettings()->getIP() << ":" << window->getSettings()->getPort() << std::endl;
  try {
	  _network->connect(window->getSettings()->getIP());
  }
  catch (const std::exception &e)
  {
	  std::cerr << e.what() << std::endl;
  }
  //Sending Handshake

  ANetwork::t_frame sender = CreateRequest::create((unsigned char)C_HANDSHAKE, CRC::calcCRC("Bonjour 1.0"), 0, "Bonjour 1.0");
  _network->write(sender);

  //Creating SF::window

  window->setWindow(sf::VideoMode(1920, 1080, 32), "R-Pint");
  window->setFramerateLimit(60);
  window->clear();

  //Creating Textures for splash screen

  Texture	*splashScreenTexture = new Texture();
  Sprite	*splashScreen = new Sprite();

  splashScreenTexture->loadFromFile("../common/misc/splash_screen.png");
  splashScreen->setTexture(*splashScreenTexture);
  splashScreen->setPosition(0, 0);

  //Display Splash screen and loading Ressources

  window->draw(splashScreen->getSprite());
  window->display();
  window->_ressources = new Ressources();

  window->getPanels().push(static_cast<StartPanel*>(PanelFactory::createPanel(PanelFactory::PanelType::START_PANEL)));
  window->getPanels().top()->setUserInterface();

  //Adding & playing music for Menu

  _sound->registerSound("../common/misc/mouseHover.ogg", "hover");
  _sound->registerSound("../common/misc/accessDenied.ogg", "denied");
  _sound->registerSound("../common/misc/metalDoorOpen.ogg", "door");
  _sound->registerMusic("../common/misc/laserSound.ogg", "riffle");
  _sound->registerSound("../common/misc/rocketSound.ogg", "missile");
  _sound->registerSound("../common/misc/megaLaser1.ogg", "laser");
  _sound->registerMusic("../common/misc/menuMusic1.ogg", "mainMenu");
  _sound->registerSound("../common/misc/explosion1.ogg", "explosion1");
  _sound->registerSound("../common/misc/gameOver.ogg", "endGame");
  _sound->registerMusic("../common/misc/GameMusicIntro.ogg", "gameIntro");
  _sound->registerMusic("../common/misc/GameMusicLoop.ogg", "gameLoop");
  _sound->registerSound("../common/misc/BimBamBoum.ogg", "logoSound");
  _sound->playMusic("mainMenu");

  //Threading the Read

  std::unique_ptr<AThread> t(new Thread(1));
  char str1[] = "";
  (void) str1;
  t->attach(&readdisp, (void *)str1);
  t->run();

  //Main Loop

  while(window->isOpen())
    {
      window->getPanels().top()->update();
      window->getPanels().top()->render();
      window->display();
      sf::Event event;
      while (window->pollEvent(event))
      	{
      	  window->getPanels().top()->getInputManager().methodChecker(event);
      	}
    }

  //Closing Thread and Window

  t->cancel();
  _network->close();
}