예제 #1
0
void menu(RenderWindow &window)
 {
	 Texture menuText1, menuText2, menuText3, menuBackground;
	 menuBackground.loadFromFile("images/menu1.jpg");
	 menuText2.loadFromFile("images/cat.jpg");
	 Sprite menuLoad(menuText2);
	 Sprite menuBg(menuBackground);
	 bool isMenu = 1;
	 int menuNum = 0;
	 menuBg.setPosition(0,0);
	 Music music;
	 music.openFromFile("music/menu.ogg");
	 music.play();

	 Font font;
	 font.loadFromFile("dumb.ttf");
	 Text text("", font, 38); text.setStyle(Text::Bold);
	 Text text2("", font, 38); text2.setStyle(Text::Bold);
	 Text text3("", font, 38); text3.setStyle(Text::Bold);
	 text.setString("New Game");
	 text2.setString("Load");
	 text3.setString("Exit");
	 text.setPosition(485, 410);
	 text2.setPosition(550, 450);
	 text3.setPosition(550,568);


	 while(isMenu)
	 {
		text.setColor(Color(254,150,121));
		text2.setColor(Color(254,150,121));
		text3.setColor(Color(254,150,121));
		menuNum = 0;

		 window.clear(Color(129,181,221));
		 //New Game
		 if(IntRect(500,410,200,60).contains(Mouse::getPosition(window)))
		 {
			 text.setColor(Color(98,198,223));
			 menuNum = 1;
		 }
		 //Load Game
		 if(IntRect(550,488,200,60).contains(Mouse::getPosition(window)))
		 {
			 text2.setColor(Color(98,198,223));
			 menuNum = 2;
		 }
		 //Exit
		 if(IntRect(500,564,200,60).contains(Mouse::getPosition(window)))
		 {
			 text3.setColor(Color(98,198,223));
			 menuNum = 3;
		 }


		if(Mouse::isButtonPressed(Mouse::Left))
		{
			if(menuNum == 1)
			{
				music.stop();
				return;
			}
			if(menuNum == 2)
			{
				window.draw(menuLoad);
				window.display();
				while(!Keyboard::isKeyPressed(Keyboard::Escape))
				{;}
			}
			if(menuNum == 3)
			{
				music.stop();
				window.close();
				isMenu = false;
			}
		}
		 window.draw(menuBg);
		 window.draw(text);
		 window.draw(text2);
		 window.draw(text3);
		 window.display();
	 }
 }
예제 #2
0
 int main()
 {
	 RenderWindow window(VideoMode(1300,702),"Find the fish", Style::Default);
	 window.setPosition(Vector2i(10,10));
	 menu(window);
	 int cntMeow = 0;


	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Player p("cat.png", 55, 25, 200, 120, 45, 445);
	 Clock clock;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	 //Objects
	 Object posters("tayles1.png", 160, 660, 210, 250, 280, 215);
	 Object bed("tayles1.png", 420, 80, 280, 310, 250, 440);
	 Object toys("tayles1.png", 120, 470, 180, 150, 220, 545);
	 Object upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
	 Object cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
	 Object mop("tayles1.png", 515, 785, 165, 241, 587, 385);
	 Object flower("tayles1.png", 780, 65, 170, 330, 147, 285);
	 Object ball("tayles1.png", 905, 615, 40, 55, 357, 190);
	 Object books("tayles1.png", 860, 735, 125, 80, 290, 187);
	  while (window.isOpen())
    {

		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);

        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
			//>>>>>----Meow----<<<<<<
			if (event.type == Event::MouseButtonPressed)
					if (event.key.code == Mouse::Left)
						if (p.sprite.getGlobalBounds().contains(pos.x, pos.y))
						{
							if(cntMeow == 5)
							{
								meow2.play();
								cntMeow = 0;
							}
							meow1.play();
							cntMeow++;
						}
			//------------------------------------------------------------------------------
        }
		p.update(time);

		window.clear();
		window.draw(level);
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		window.draw(toys.sprite);
		window.draw(upShelf.sprite);
		window.draw(cabinet.sprite);
		window.draw(mop.sprite);
		window.draw(flower.sprite);
		window.draw(ball.sprite);
		window.draw(books.sprite);
		window.draw(p.sprite);
		window.display();
    }
 }
void menu(sf::RenderWindow & window) {
    Music music;//создаем объект музыки
    music.openFromFile("bg_music.wav");//загружаем файл
    music.play();//воспроизводим музыку
    music.setLoop(true);
    char *fname = "high_score.txt";
    FILE * fp;
    fp=fopen(fname,"r");
    Font font;
    int hsT=0;
    int hsS=0;
    int hsC=0;
    fscanf(fp,"%i", &hsT);
    fscanf(fp,"%i", &hsS);
    fscanf(fp,"%i", &hsC);
    font.loadFromFile("game_over.ttf");
	Texture menuBackground;
	menuBackground.loadFromFile("images/background.jpg");
	Text menu1("Start tetris " , font, 20);
	Text menu2("Start snake " , font, 20);
	Text menu3("Start tetroCar " , font, 20);
	Text menu4("High score " , font, 20);
	Text menu5("Music " , font, 20);
	Text menu6("Exit " , font, 20);
	Sprite menuBg(menuBackground);
	bool isMenu = 1;
	int menuNum = 1;
	int stat=1;
	menu1.setPosition(120, 80);
	menu2.setPosition(120, 120);
	menu3.setPosition(120, 160);
	menu4.setPosition(120, 200);
	menu5.setPosition(120, 240);
	menu6.setPosition(120, 280);
	menuBg.setPosition(0, 0);
    menu5.setColor(Color::Magenta);
	while (isMenu)
	{
	    if(menuNum!=1)
		menu1.setColor(Color::Magenta);
		else menu1.setColor(Color::Blue);
		if(menuNum!=2)
		menu2.setColor(Color::Magenta);
		else menu2.setColor(Color::Blue);
		if(menuNum!=3)
		menu3.setColor(Color::Magenta);
		else menu3.setColor(Color::Blue);
		if(menuNum!=4)
		menu4.setColor(Color::Magenta);
		else menu4.setColor(Color::Blue);
		if(menuNum!=6)
		menu6.setColor(Color::Magenta);
		else menu6.setColor(Color::Blue);
		window.clear(Color(129, 181, 221));

		if (IntRect(120, 80, 220, 20).contains(Mouse::getPosition(window))) { menu1.setColor(Color::Blue); menuNum = 1; }
		if (IntRect(120, 120, 220, 20).contains(Mouse::getPosition(window))) { menu2.setColor(Color::Blue); menuNum = 2; }
		if (IntRect(120, 160, 220, 20).contains(Mouse::getPosition(window))) { menu3.setColor(Color::Blue); menuNum = 3; }
        if (IntRect(120, 200, 220, 20).contains(Mouse::getPosition(window))) { menu4.setColor(Color::Blue); menuNum = 4; }
        if (IntRect(120, 240, 220, 20).contains(Mouse::getPosition(window))) {  menuNum = 5; }
        if (IntRect(120, 280, 200, 20).contains(Mouse::getPosition(window))) { menu6.setColor(Color::Blue); menuNum = 6; }
         sf::Event event;
        while (window.pollEvent(event)){
        if (event.type == sf::Event::Closed){
                freopen(fname, "w",fp);
                fprintf(fp,"%i\n", hsT);
                fprintf(fp,"%i\n", hsS);
                fprintf(fp,"%i\n", hsC);
                fclose(fp);
                window.close();
                return;
        }
        if(event.type == sf::Event::KeyPressed&&event.key.code==sf::Keyboard::Up){
                if(menuNum==1)
                menuNum=6;
                else menuNum--;
            }
        if(event.type == sf::Event::KeyPressed&&event.key.code==sf::Keyboard::Down){
                if(menuNum==6)
                menuNum=1;
                else menuNum++;
            }
		if (Mouse::isButtonPressed(Mouse::Left)||(event.type == sf::Event::KeyPressed&&event.key.code==sf::Keyboard::Return))
		{
			if (menuNum == 1) {hsT=GameT(window,hsT);}
			if (menuNum == 2) {hsS=snake(window,hsS);};
			if (menuNum == 3) {hsC=GameTc(window, hsC);}
			if (menuNum == 4) hshow(window, hsT, hsS, hsC);
			if (menuNum == 5) {if(stat==1){
                menu5.setColor(Color::Blue);
                music.pause();
                stat=0;
			}else {
			    menu5.setColor(Color::Magenta);
			    music.play();
			    stat=1;
			}
			}
			if (menuNum == 6)  {
                window.close();
                isMenu = false;
                freopen(fname, "w",fp);
                fprintf(fp,"%i\n", hsT);
                fprintf(fp,"%i\n", hsS);
                fprintf(fp,"%i\n", hsC);
                fclose(fp);
            }
            continue;

		}
		continue;
        }
		window.draw(menuBg);
		window.draw(menu1);
		window.draw(menu2);
		window.draw(menu3);
		window.draw(menu4);
		window.draw(menu5);
		window.draw(menu6);
		window.display();
	}
}
예제 #4
0
void Menu::menu(RenderWindow & app, int width, int height) {
	bool musicIsPlaying = true;
	Music music;
	music.openFromFile("sounds/menuMusic.ogg");
	music.setLoop(true);

	Texture menuTexture1, menuTexture2, menuTexture3, aboutTexture, menuBackground;
	menuTexture1.loadFromFile("images/StartGame.png");
	menuTexture2.loadFromFile("images/LeaderBoard.png");
	menuTexture3.loadFromFile("images/exit.png");
	menuBackground.loadFromFile("images/menu.png");
	Sprite menu1(menuTexture1), menu2(menuTexture2), menu3(menuTexture3), menuBg(menuBackground);
	bool isMenu = 1;
	int menuNum = 0;
	menu1.setPosition(400, 300);
	menu2.setPosition(400, 375);
	menu3.setPosition(400, 450);
	menuBg.setPosition(0, 0);

	while (isMenu)
	{
		if (musicIsPlaying)
		{
			music.play();
			musicIsPlaying = false;
		}

		menu1.setColor(Color::White);
		menu2.setColor(Color::White);
		menu3.setColor(Color::White);
		menuNum = 0;
		app.clear(Color(129, 181, 221));

		if (IntRect(400, 300, 300, 50).contains(Mouse::getPosition(app))) 
		{ 
			menu1.setColor(Color::Blue); 
			menuNum = 1; 
		}
		if (IntRect(400, 375, 300, 50).contains(Mouse::getPosition(app))) 
		{
			menu2.setColor(Color::Blue); 
			menuNum = 2; 
		}
		if (IntRect(400, 450, 300, 50).contains(Mouse::getPosition(app))) 
		{
			menu3.setColor(Color::Blue); 
			menuNum = 3; 
		}

		if (Mouse::isButtonPressed(Mouse::Left))
		{
			if (menuNum == 1)
			{
				music.stop();
				const char * filename = "score.txt";
				isMenu = false;
				Game * game = new Game(width, height);
				int score = game->run(app);
				int prevScore;
				ifstream scoreFile;
				scoreFile.open(filename);
				scoreFile >> prevScore;
				scoreFile.close();
				if (score > prevScore)
				{
					ofstream scoreFile;
					scoreFile.open(filename);
					scoreFile << score;
					scoreFile.close();
				}
				isMenu = true;
			}
			//if (menuNum == 2) { window.draw(about); window.display(); while (!Keyboard::isKeyPressed(Keyboard::Escape)); }
			if (menuNum == 3) 
			{ 
				app.close(); isMenu = false; 
			}
			musicIsPlaying = true;
		}

		app.draw(menuBg);
		app.draw(menu1);
		app.draw(menu2);
		app.draw(menu3);
		printTopScore(app);
		app.display();
	}
예제 #5
0
bool StartGame(RenderWindow & window, Game & game)
{
	Level lvl;
	lvl.LoadFromFile(GetLevelNumb(game));
	Image image;
	Texture texture;
	if (!image.loadFromFile("images/lvl1.png"))
		cout << "Error loading image from file " << endl;
	image.createMaskFromColor(Color(0, 128, 0));
	if (!texture.loadFromImage(image))
		cout << "Error loading texture from image " << endl;

	Sprite heartSprite;
	heartSprite.setTexture(texture);
	heartSprite.setTextureRect(IntRect(395, 151, 54, 46));
	heartSprite.setScale(0.3f, 0.3f);

	Sprite lifeSprite;
	lifeSprite.setTexture(texture);
	lifeSprite.setTextureRect(IntRect(457, 149, 29, 29));
	lifeSprite.setScale(0.8f, 0.8f);

	Font font;
	font.loadFromFile("fonts/pixel.ttf");
	Text text("", font, 25);

	game.graphic.statistic.heart = heartSprite;
	game.graphic.statistic.life = lifeSprite;
	game.graphic.text = text;
	game.isPause = true;
	game.restart = false;

	vector <Enemy*>  enemies;
	std::vector<Object> e = lvl.GetObjects("easyEnemy");
	for (Object i : e)
		enemies.push_back(new Enemy(texture, "easyEnemy", i.rect.left, i.rect.top, 53, 28));

	e = lvl.GetObjects("flyEnemy");
	for (Object i : e)
		enemies.push_back(new Enemy(texture, "flyEnemy", i.rect.left, i.rect.top, 38, 36));
	
	
	if (lvl.IsExist("trap"))
	{
		e = lvl.GetObjects("trap");
		for (Object i : e)
			enemies.push_back(new Enemy(texture, "trap", i.rect.left, i.rect.top, 32, 18));
	}


	vector <Portal*> portals;
	vector <Bullet*> bullets;
	vector <Object> objects = lvl.GetAllObjects();
	Clock clock;

	SoundBuffer shootBuffer;
	shootBuffer.loadFromFile("sound/shoot.wav");
	Sound shoot(shootBuffer);

	SoundBuffer portalBuffer;
	portalBuffer.loadFromFile("sound/portal.wav");
	Sound portal(portalBuffer);

	SoundBuffer teleportBuffer;
	teleportBuffer.loadFromFile("sound/teleport.wav");
	Sound teleport(teleportBuffer);

	SoundBuffer damageBuffer;
	damageBuffer.loadFromFile("sound/damage.wav");
	Sound damage(damageBuffer);

	SoundBuffer deathBuffer;
	deathBuffer.loadFromFile("sound/damage.wav");
	Sound gameOver(deathBuffer);

	Music music;
	music.openFromFile("sound/musicGame.ogg");
	music.play();

	Object playerObject = lvl.GetObject("player");
	Player player(texture, "Player1", playerObject.rect.left, playerObject.rect.top, 32, 32);
	player.health = game.health;
	player.heart = game.hearts;

	while (window.isOpen() && (!game.restart))
	{
		float time = float(clock.getElapsedTime().asMicroseconds());
		clock.restart();
		time = time / 800;
		Event event;
		Vector2i pixelPos = Mouse::getPosition(window);
		Vector2f pos = window.mapPixelToCoords(pixelPos);
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed || (Keyboard::isKeyPressed(Keyboard::Escape) && game.isPause))
			{
				window.close();
				game.restart = false;
			}
			if (event.type == Event::MouseButtonPressed)
			{
				pos.y = float(player.teleportY);
				if ((event.key.code == Mouse::Left) && (player.doesOpenPortal))
				{
					CreatePortal(portals, game, "blue", pos, texture);
					portal.play();
				}
				else if (event.key.code == Mouse::Right && (player.doesOpenPortal))
				{
					CreatePortal(portals, game, "yellow", pos, texture);
					portal.play();
				}
			}
			if (player.isTeleporting)
			{
				TeleportPlayer(player, portals);
				teleport.play();
			}
			if (Keyboard::isKeyPressed(Keyboard::Return))
			{
				game.isPause = false;
			}
			if (Keyboard::isKeyPressed(Keyboard::P))
			{
				game.isPause = true;
			}
			if (Keyboard::isKeyPressed(Keyboard::Tab) && game.isPause) 
			{ 
				game.restart = true; 
			}
		}
		if (player.isExit)
		{
			if (game.isEndLevel)
			{
				game.isPause = true;
			}
			else
			{
				game.level++;
				game.restart = true;
				game.health = player.health;
				game.hearts = player.heart;
			}
		}
		for (auto *e : enemies)
		{
			if ((*e).name == "flyEnemy" && (*e).isShoot)
			{
				CreateBullet(bullets, (*e).GetRect(), player, texture);
				shoot.play();
			}
		}
		EntitiesIntersection(player, enemies, portals, bullets, damage);
		if (player.alive)
		{
			setPlayerCoordinateForView(game.camera, player.GetPos().x, player.GetPos().y);
		}
		if (!game.isPause)
		{
			UpdateEnemies(objects, enemies, time, player);
			UpdatePortals(portals, time);
			UpdateBullets(objects, bullets, time);
			player.Update(objects, time, pos, game.portalH);
		}
		window.setView(game.camera);
		window.clear();
		lvl.Draw(window);
		DrawEnemies(window, enemies);
		DrawPortals(window, portals);
		DrawBullets(window, bullets);
		DrawStatistic(window, &game, player, game.camera);
		window.draw(player.sprite);
		DrawAllMessages(player, game, window);
		music.setLoop(true);
		window.display();
	}
	return game.restart;
}
예제 #6
0
void Game::gra()
{
	srand(time(0));
	
	
	///////////////////////////////
	Texture tekstura_cel;			//wczytanie tekstur i dzwiêków i tekstów
	tekstura_cel.loadFromFile("data/cel.png");
	Texture tekstura_z;
	tekstura_z.loadFromFile("data/zombie_after_attack_rect.png");
	Texture tekstura;
	tekstura.loadFromFile("data/ground.png");
	Texture tekstura_bl;
	tekstura_bl.loadFromFile("data/blood.png");
	Texture tekstura_zombie_bl;
	tekstura_zombie_bl.loadFromFile("data/zombie_after_attack_rect.png");
	Texture tekstura_zombie_aa;
	tekstura_zombie_aa.loadFromFile("data/zombie_after_attack_rect.png");
	Texture tekstura_zombie_full;
	tekstura_zombie_full.loadFromFile("data/zombie_after_attack_rect.png");
	Texture tekstura_gun;
	tekstura_gun.loadFromFile("data/gun.png");
	Texture tekstura_bullet;
	Texture tekstura_floor;
	tekstura_floor.loadFromFile("data/floor.png");
	Texture tekstura_ak_47;
	tekstura_ak_47.loadFromFile("data/ak_47.png");
	tekstura_bullet.loadFromFile("data/bullet.png");
	Texture tekstura_corps;
	tekstura_corps.loadFromFile("data/corps.png");
	Texture tekstura_ammo;
	tekstura_ammo.loadFromFile("data/ammo_pickup.png");
	Texture tekstura_hp;
	tekstura_hp.loadFromFile("data/hp_pickup.png");
	Texture tekstura_wall;
	tekstura_wall.loadFromFile("data/wall.jpg");
	tekstura_wall.setRepeated(true);
	SoundBuffer buffer, buffer_z;
	buffer_z.loadFromFile("data/hit.wav");
	buffer.loadFromFile("data/shot.wav");
	Sound sound, sound_hit;
	sound.setBuffer(buffer);
	sound_hit.setBuffer(buffer_z);
	SoundBuffer zombie_bite;
	zombie_bite.loadFromFile("data/zombie_bite.wav");
	Sound sound_bite;
	sound_bite.setBuffer(zombie_bite);
	SoundBuffer reload_wav, ammo_out;
	reload_wav.loadFromFile("data/long_reload.wav");
	ammo_out.loadFromFile("data/out_of_ammo.wav");
	SoundBuffer health_wav, ammo_wav;
	health_wav.loadFromFile("data/health.wav");
	ammo_wav.loadFromFile("data/ammo.wav");
	Sound health_collect, ammo_collect;
	health_collect.setBuffer(health_wav);
	ammo_collect.setBuffer(ammo_wav);
	SoundBuffer ak_shot;
	ak_shot.loadFromFile("data/AK_47_shot.wav");
	Sound ak;
	ak.setBuffer(ak_shot);
	Sound sound_reload, sound_ammo_out;
	sound_reload.setBuffer(reload_wav);
	sound_ammo_out.setBuffer(ammo_out);
	Music muzyka;
	muzyka.openFromFile("data/COD4_theme.wav");
	muzyka.setLoop(true);
	muzyka.play();
	
	Font font;
	font.loadFromFile("data/font_UI.ttf");
	Text hp;
	hp.setFont(font);
	hp.setCharacterSize(25);
	hp.setColor(Color(138, 7, 7));
	Text round;
	round.setCharacterSize(25);
	round.setFont(font);
	round.setColor(Color(138, 7, 7));
	Text gun_name;
	gun_name.setCharacterSize(25);
	gun_name.setFont(font);
	gun_name.setColor(Color(138, 7, 7));
	Text bullets_Left;
	bullets_Left.setFont(font);
	bullets_Left.setCharacterSize(25);
	bullets_Left.setColor(Color(138, 7, 7));
	Text licznik_zombie;
	licznik_zombie.setFont(font);
	licznik_zombie.setCharacterSize(25);
	licznik_zombie.setColor(Color(138, 7, 7));
	////////////////////////////////
	
	Sprite celownik;
	celownik.setScale(0.045, 0.045);
	celownik.setTexture(tekstura_cel);
	celownik.setOrigin(celownik.getLocalBounds().width/2.0f, celownik.getLocalBounds().height/ 2.0f);

	RectangleShape sprint_ui;
	sprint_ui.setSize(Vector2f(15 * 5, 15));
	sprint_ui.setFillColor(Color(138, 7, 7));


	/////////////////////////// tablice obiektów
	vector<Blood> tab_bl;
	vector < Bullet > tab; //tablica przechowuj¹ca pociski
	vector <Zombie> tab_z; //zombie
	deque <Vector2f> tab_p;//pozycje gracza z ostatnich 100 klatek
	vector <Corps> tab_corps;
	vector <Ammo_Pickup> tab_am;
	vector <Hp_Pickup> tab_hp;
	

	Sprite map(tekstura);
	tekstura.setRepeated(true);
	map.setTextureRect(IntRect(0, 0, 10000, 10000));
	map.setOrigin(5000,5000);
	map.setPosition(0, 0);
	
	Sprite floor;
	floor.setPosition(-500, -480);
	floor.setTexture(tekstura_floor);
	tekstura_floor.setRepeated(true);
	floor.setTextureRect(IntRect(0, 0, 1000, 980));
	
	vector<RectangleShape> tab_wall;
	for (int i = 0; i < 12; i++)
	{
		RectangleShape wall;
		wall.setFillColor(Color(7, 138, 7, 100));
		
		
		if (i == 0)
		{
			wall.setPosition(-1000, -1000);
			//wall.setFillColor(Color::White);
		}
		else if (i == 1) {
			wall.setPosition(-1000, 1000);
			//wall.setFillColor(Color::Red);
		}
		else if (i == 2) {
			wall.setPosition(-1100, -1000);
			//wall.setFillColor(Color::Cyan);
		}
		else if (i == 3) {
			//wall.setOrigin(100, 0);
			wall.setPosition(1000, -1000);
			//wall.setFillColor(Color::Blue);
		}
		if (i == 0 || i == 1)wall.setSize(Vector2f(2000, 100));
		else if (i == 2 || i == 3)wall.setSize(Vector2f(100, 2100));
		if (i == 4)
		{
			wall.setPosition(-500,-500);

		}
		else if (i == 5)
		{
			wall.setPosition(-520,500);

		}
		else if (i == 6)
		{
			wall.setPosition(-520, -500);

		}
		else if (i == 7)
		{
			wall.setPosition(500, -500);

		}
		if (i == 4 || i == 5)wall.setSize(Vector2f(1020, 20));
		else if (i == 6 || i == 7)wall.setSize(Vector2f(20, 1020));
		
		if (i == 8)
		{
			wall.setPosition(-100, -489);
			wall.setFillColor(Color(138, 7, 7, 150));
		}
		else if (i == 9)
		{
			wall.setPosition(-100, 510);
			wall.setFillColor(Color(138, 7, 7, 150));
		}
		else if (i == 10)
		{
			wall.setPosition(-509, -100);
			wall.setFillColor(Color(138, 7, 7, 150));
		}
		else if (i == 11)
		{
			wall.setPosition(510, -100);
			wall.setFillColor(Color(138, 7, 7,150));
		}
		if (i == 8 || i == 9)wall.setSize(Vector2f(100, 6));
		else if (i == 10 || i == 11)wall.setSize(Vector2f(6, 100));
		if (i == 8 || i == 9 || i == 10 || i == 11)wall.setOrigin(wall.getLocalBounds().width / 2.0f, wall.getLocalBounds().height / 2.0f);

		tab_wall.push_back(wall);

	}
	
	
	Player gracz;
	gracz.body.setPosition(0,0);


	int runda = 1;

	float vx = 0, vy = 0; //prêdkoœæ gracza
	float angle;
	float sprint = 1;

	Clock zombie_player_collisionTimer;
	Clock reload_time;
	Clock zombie_generator_timer;
	Clock zegar;
	Time czas;
	Event event;
	float x, y; //x,y myszy
	okno.setMouseCursorVisible(false);
	int max_zombie_per_round;
	int generated_zombie=0;
	bool generate = true;
	bool menu = false;
	bool canReload = false;
	bool canShoot = true;
	bool Rpressed = false;
	bool isSprint = false;
	bool canSprint = true;
	int zombies_killed_in_round = 0;
	zombie_generator_timer.restart();

	Gun *wsk_gun;
	

	Gun pistol("colt .45", 80.0f,16.0f,2000.0f,2.0f,tekstura_bullet, tekstura_gun,Vector2f(2,2), Vector2f (1,1),gracz.body.getPosition(),0.1);
	Gun ak_47("ak 47", 120.0f, 30.0f, 2800.0f, 2.0f, tekstura_bullet, tekstura_ak_47, Vector2f(2, 2), Vector2f(1, 1), gracz.body.getPosition(),0.08f);
	//view.zoom(1.0f/1.2f);
	//view.zoom(1.0f / 1.2f);
	wsk_gun = &pistol;
	while (!menu)
	{
		//cout << tab_z.size() << " | "<< wsk_gun->bullets_fired.size() <<endl;
		
		gracz.canMoveDown = true;
		gracz.canMoveUP= true;
		gracz.canMoveRight = true;
		gracz.canMoveLeft = true;
		max_zombie_per_round = runda * 4 * 7 ;
		
		if (generated_zombie >= max_zombie_per_round)
		{
			generate = false;
			
		}
		if (!generate&&tab_z.empty())
		{
			zombies_killed_in_round = 0;
			generated_zombie = 0;
			generate = true;
			runda++;

		}
			if (generate && (zombie_generator_timer.getElapsedTime().asSeconds() >= 1.0f)) {
				zombie_generator_timer.restart();
					
						
						if (tab_z.size() <=20)
						{
							generated_zombie += 4;
						zombie_generator(tab_z, Vector2f((tab_wall[0].getPosition().x + rand() % ((int)tab_wall[0].getGlobalBounds().width + 1)), (tab_wall[0].getPosition().y + tab_wall[0].getGlobalBounds().height)), tekstura_z, runda, tab_wall[8].getPosition());
						zombie_generator(tab_z, Vector2f((tab_wall[1].getPosition().x + rand() % ((int)tab_wall[1].getGlobalBounds().width + 1)), (tab_wall[1].getPosition().y + tab_wall[1].getGlobalBounds().height)), tekstura_z, runda, tab_wall[9].getPosition());
						zombie_generator(tab_z, Vector2f((tab_wall[2].getPosition().x + tab_wall[2].getGlobalBounds().width), (tab_wall[2].getPosition().y + rand() % ((int)tab_wall[2].getGlobalBounds().height + 1))), tekstura_z, runda, tab_wall[10].getPosition());
						zombie_generator(tab_z, Vector2f((tab_wall[3].getPosition().x + tab_wall[3].getGlobalBounds().width), (tab_wall[3].getPosition().y + rand() % ((int)tab_wall[3].getGlobalBounds().height + 1))), tekstura_z, runda, tab_wall[11].getPosition());
						
						/*zombie_generator(tab_z, Vector2f((tab_wall[0].getPosition().x + rand() % ((int)tab_wall[0].getGlobalBounds().width + 1)), (tab_wall[0].getPosition().y + tab_wall[0].getGlobalBounds().height)), tekstura_z, runda, Vector2f(0,0));
						zombie_generator(tab_z, Vector2f((tab_wall[1].getPosition().x + rand() % ((int)tab_wall[1].getGlobalBounds().width + 1)), (tab_wall[1].getPosition().y + tab_wall[1].getGlobalBounds().height)), tekstura_z, runda, Vector2f(0,0));
						zombie_generator(tab_z, Vector2f((tab_wall[2].getPosition().x + tab_wall[2].getGlobalBounds().width), (tab_wall[2].getPosition().y + rand() % ((int)tab_wall[2].getGlobalBounds().height + 1))), tekstura_z, runda, Vector2f(0,0));
						zombie_generator(tab_z, Vector2f((tab_wall[3].getPosition().x + tab_wall[3].getGlobalBounds().width), (tab_wall[3].getPosition().y + rand() % ((int)tab_wall[3].getGlobalBounds().height + 1))), tekstura_z, runda, Vector2f(0,0));
*/
						}
						/*else
						{
							generated_zombie += 4;
							zombie_generator(tab_z, Vector2f((tab_wall[4].getPosition().x + rand() % ((int)tab_wall[4].getGlobalBounds().width + 1)), (tab_wall[4].getPosition().y + tab_wall[4].getGlobalBounds().height)), tekstura_z, runda);
							zombie_generator(tab_z, Vector2f((tab_wall[5].getPosition().x + rand() % ((int)tab_wall[5].getGlobalBounds().width + 1)), (tab_wall[5].getPosition().y + tab_wall[5].getGlobalBounds().height)), tekstura_z, runda);
							zombie_generator(tab_z, Vector2f((tab_wall[6].getPosition().x + tab_wall[6].getGlobalBounds().width), (tab_wall[6].getPosition().y + rand() % ((int)tab_wall[6].getGlobalBounds().height + 1))), tekstura_z, runda);
							zombie_generator(tab_z, Vector2f((tab_wall[7].getPosition().x + tab_wall[7].getGlobalBounds().width), (tab_wall[7].getPosition().y + rand() % ((int)tab_wall[7].getGlobalBounds().height + 1))), tekstura_z, runda);
						}*/
					
					
			}
		
			
			
		
		

		view.setCenter(gracz.body.getPosition()); //gracz ca³y czas w centrum widoku
		

		x = (float)Mouse::getPosition(okno).x+view.getCenter().x-1280/2, y = (float)Mouse::getPosition(okno).y+view.getCenter().y-720/2; //zapisanie pozycji myszy wzglêdem lewgo górnego rogu widoku
		
		celownik.setPosition(x, y); //przypisanie pozycji celownika 

		angle = (float)atan2((float)(y - gracz.body.getPosition().y), (float)(x - gracz.body.getPosition().x)) * 180.0f / (float)M_PI - 90.0f; //zapisanie k¹t miêdzy œrodkiem ekranu a pozycj¹ myszy
		gracz.body.setRotation(angle);		//obrócenie gracza w kierunku myszy
		
		cout <<x << " | "<< y << endl;
		
		/////////////////////////////
		if (tab_p.size() != 30)				//wype³nienie tablicy pozycjami gracza z ostatnich stu klatek (czyli 1 sekundy)
		tab_p.push_back(gracz.body.getPosition());

		if (tab_p.size() == 30)
		{	
			tab_p.pop_front();
			tab_p.push_back(gracz.body.getPosition());
		}
		///////////////////////////////
		
		while (okno.pollEvent(event))
		{

			if (event.type == Event::Closed || event.type == Event::KeyPressed &&
				event.key.code == Keyboard::Escape)
				menu = true;
			
			//if (event.type == Event::MouseButtonPressed && Mouse::isButtonPressed(Mouse::Right))//stworzenie zombie i dodanie go do tablicy
			//{

			//	Zombie zombie(x, y, tekstura_z,rand()%51+50, 1+runda);
			//	tab_z.push_back(zombie);

			//}
			if (wsk_gun==&pistol) {
				if (event.type == Event::MouseButtonPressed && Mouse::isButtonPressed(Mouse::Left))//stworzenie pocisku i dodanie go do tablicy
				{
					if (wsk_gun->magazynek == 0)
					{
						sound_ammo_out.play();
						if (wsk_gun->bulletsLeft != 0 && !wsk_gun->reload_demand&& !wsk_gun->reloading)
						{
							sound_reload.play();
							wsk_gun->reload_demand = true;
						}
					}
					else if (!wsk_gun->reloading)
					{
						sound.play();
						wsk_gun->shoot(gracz.body.getPosition());


						wsk_gun->magazynek--;

					}
					else {
						sound_ammo_out.play();
					}
				}
			}
			
		
				if (event.type == Event::MouseButtonPressed && Mouse::isButtonPressed(Mouse::Left) && (wsk_gun->magazynek == 0 || wsk_gun->reloading || wsk_gun->reload_demand))
					sound_ammo_out.play();
			

			
				if (event.type == Event::KeyPressed && event.key.code == Keyboard::R && wsk_gun->bulletsLeft != 0 && wsk_gun->magazynek != wsk_gun->magazynekSize &&!wsk_gun->reloading&& !wsk_gun->reload_demand)
				{
					wsk_gun->reload_demand = true;
					sound_reload.play();
				}

				if (event.type == Event::KeyPressed && event.key.code == Keyboard::Num1)
				{ 
					wsk_gun = &pistol;
					//buffer = wsk_gun->shot;
				}
				if (event.type == Event::KeyPressed && event.key.code == Keyboard::Num2) 
				{
					wsk_gun = &ak_47;
					//buffer = wsk_gun->shot;
				}
			if (event.type == Event::KeyPressed && event.key.code == Keyboard::Up)view.zoom(1.2f);
			if (event.type == Event::KeyPressed && event.key.code == Keyboard::Down)view.zoom(1.0f/1.2f);
			
		}
		/////// strza³ pistoletem
		

		if (wsk_gun != &pistol) {
			if (wsk_gun->fire_timer.getElapsedTime().asSeconds() >= wsk_gun->fireRate) {
				if (Mouse::isButtonPressed(Mouse::Left))//stworzenie pocisku i dodanie go do tablicy
				{
					if (wsk_gun->magazynek == 0)
					{

						if (wsk_gun->bulletsLeft != 0 && !wsk_gun->reload_demand&& !wsk_gun->reloading)
						{
							sound_reload.play();
							wsk_gun->reload_demand = true;
						}
					}
					else if (!wsk_gun->reloading)
					{
					sound.play();
						wsk_gun->shoot(gracz.body.getPosition());


						wsk_gun->magazynek--;


					}
					/*else {
						sound_ammo_out.play();
					}*/
				}
				wsk_gun->fire_timer.restart();
			}
			
		}
		wsk_gun->update(angle, czas, gracz.body.getPosition());

		if(!tab_z.empty())//zombie update
		{
			for (int i = 0; i < tab_z.size(); i++)
				tab_z[i].update(gracz.body.getPosition(), czas,tab_p[0]);
		}
		//if (!tab.empty())//obrócenie zombie w kierunku pozycji gracz z przed sekundy
		//{
		//	for (int i = 0; i < tab.size(); i++)
		//		tab[i].rotate();
		//}
	
		
		
		//////////////////////////////////////kolizja
		
		// kolizja zombie-gracz	
			for (int i = 0; i < tab_z.size(); i++)
			{
				//if(gracz.body.getGlobalBounds().intersects(tab_z[i].body.getGlobalBounds()))
				if (Collision::PixelPerfectTest(gracz.body, tab_z[i].body))
				{
					tab_z[i].collidesWithPlayer = true;
					if ((tab_z[i].body.getPosition().y > gracz.body.getPosition().y >0) || (gracz.body.getPosition().y <tab_z[i].body.getPosition().y <0))
					{
						gracz.canMoveDown = false;
						//gracz.body.move(0, -1);
					}

					if ((gracz.body.getPosition().y >tab_z[i].body.getPosition().y >0) || (tab_z[i].body.getPosition().y < gracz.body.getPosition().y <0))
					{
					
						gracz.canMoveUP = false;
						//gracz.body.move(0, 1);
					}
					
					 if ((tab_z[i].body.getPosition().x > gracz.body.getPosition().x >0)||(gracz.body.getPosition().x <tab_z[i].body.getPosition().x <0))
					{
						gracz.canMoveRight = false;
						//gracz.body.move(-1, 0);
						
					}
					
					 if ((gracz.body.getPosition().x >tab_z[i].body.getPosition().x >0)||(tab_z[i].body.getPosition().x < gracz.body.getPosition().x <0))
					{
						gracz.canMoveLeft = false;
						//gracz.body.move(1, 0);
					}
					
					
					if (zombie_player_collisionTimer.getElapsedTime().asSeconds() >= 0.5) {
						zombie_player_collisionTimer.restart();
					
						sound_bite.play();
						//cout << gracz.healthPoints << endl;
						if (tab_z[i].healthPoints < 3)tab_z[i].body.setTexture(tekstura_zombie_full);
						else tab_z[i].body.setTexture(tekstura_zombie_aa);
						tab_z[i].haveAttacked = true;
						gracz.healthPoints--;
						if (gracz.healthPoints == 0)
						{
							menu = true;
						}
						break;
					}
				}
				else tab_z[i].collidesWithPlayer = false;
			}
		
			// kolizja zombie-zombie
		if (!tab_z.empty())
		{
			for (int i = 0; i < tab_z.size(); i++)
			{
				for (int j = 0; j < tab_z.size(); j++)
				{
					if (i != j)
					{	
						//if (tab_z[j].body.getGlobalBounds().intersects( tab_z[i].body.getGlobalBounds()))
						if (Collision::PixelPerfectTest(tab_z[j].body, tab_z[i].body))
						{
							if (fabs(tab_z[i].body.getPosition().x - gracz.body.getPosition().x) + fabs(tab_z[i].body.getPosition().y - gracz.body.getPosition().y)
				>fabs(tab_z[j].body.getPosition().x - gracz.body.getPosition().x) + fabs(tab_z[j].body.getPosition().y - gracz.body.getPosition().y))
							{
								tab_z[i].collide_parameter = 0;
								tab_z[j].collide_parameter = 1.2;

							}
							else
							{
								tab_z[j].collide_parameter = 0;
								tab_z[i].collide_parameter = 1.2;
							}
							tab_z[i].col_in = true;
							tab_z[j].col_in = true;
							break;
						}


					}

				}
			}


		}
		// kolizja gracz-œciana
		if (tab_wall[4].getGlobalBounds().intersects(gracz.body.getGlobalBounds()))
		{
			gracz.canMoveUP = false;

			sprint = 1;
			//vx = 0;
			//gracz.body.move(0, 1);
			//gracz.canMoveUP = true;
		}
	
		if (tab_wall[5].getGlobalBounds().intersects(gracz.body.getGlobalBounds()))
		{
			sprint = 1;
			gracz.canMoveDown = false;
			//vx = 0;
			//gracz.body.move(0, -1); 
			//gracz.canMoveDown = true;
		}
	 
		if (tab_wall[6].getGlobalBounds().intersects(gracz.body.getGlobalBounds()))
		{
			sprint = 1;
			gracz.canMoveLeft = false;
			//vy = 0;
			//gracz.body.move(1, 0);
			//gracz.canMoveRight = true;
		}
		  
		if (tab_wall[7].getGlobalBounds().intersects(gracz.body.getGlobalBounds()))
		{
			sprint = 1;
			gracz.canMoveRight= false;
			//vy = 0;
			//gracz.body.move(-1, 0);
			//gracz.canMoveLeft = true;
		}
		 

		
		///////////kolizja zombie pocisk
		
			if (!tab_z.empty() && !wsk_gun->bullets_fired.empty())				//zniszczenie pocisku i zombie w przypadku kolizji
			{
				for (int i = 0; i < wsk_gun->bullets_fired.size(); i++)
				{
					for (int j = 0; j < tab_z.size(); j++)
					{
						if (wsk_gun->bullets_fired[i].body.getGlobalBounds().intersects(tab_z[j].body.getGlobalBounds()))
						{
							sound_hit.play();

							bullet_destroy(wsk_gun->bullets_fired, i);

							Blood krew(tekstura_bl, tab_z[j].body.getPosition());
							krew.body.setRotation((rand() % 360) + 1);
							tab_bl.push_back(krew);

							tab_z[j].healthPoints--;
							if (tab_z[j].healthPoints == 1)
							{
								tab_z[j].setSpeed(80.0f);
								if (tab_z[j].haveAttacked == true)tab_z[j].body.setTexture(tekstura_zombie_full);
								else tab_z[j].body.setTexture(tekstura_zombie_bl);
							}
							if (tab_z[j].healthPoints == 0)
							{	//œmieræ zombie
								Corps corpses(tekstura_corps, tab_z[j].body.getPosition(), tab_z[j].rotate_angle);
								tab_corps.push_back(corpses);
								if (tab_z[j].isInside)
								{
									Ammo_Pickup am(tekstura_ammo, tab_z[j].body.getPosition());
									Hp_Pickup hp(tekstura_hp, tab_z[j].body.getPosition());
									switch (rand() % 10)
									{
									case 0:
										tab_am.push_back(am);
										break;
									case 1:
										tab_am.push_back(am);
										break;
							


									case 5:
										if (gracz.healthPoints < 5)tab_hp.push_back(hp);
										break;

									}
								}
								tab_z[j] = tab_z[tab_z.size() - 1];
								tab_z.pop_back();
								zombies_killed_in_round++;

							}

							break;
						}


					}
				}
			}
		
		//kolizja gracz-ammo_pickup
		for (int i = 0; i < tab_am.size(); i++)
		{
			if (gracz.body.getGlobalBounds().intersects(tab_am[i].body.getGlobalBounds()))
			{	
				ammo_collect.play();
				
					wsk_gun->bulletsLeft += tab_am[i].add_ammo;
				
				ammo_destroy(tab_am, i);
			}
		}

		//kolizja gracz-hp_pickup
		for (int i = 0; i < tab_hp.size(); i++)
		{
			if (gracz.body.getGlobalBounds().intersects(tab_hp[i].body.getGlobalBounds()))
			{
				
				if (gracz.healthPoints + tab_hp[i].add_hp <= 5)
				{
					health_collect.play();
					gracz.healthPoints += tab_hp[i].add_hp;
					hp_destroy(tab_hp, i);
				}
			}
		}
		////////////////////////////////////////
		for (int j = 4; j < tab_wall.size()-4;j++)
		for (int i = 0; i < wsk_gun->bullets_fired.size(); i++)
		{

			if (wsk_gun->bullets_fired[i].body.getGlobalBounds().intersects(tab_wall[j].getGlobalBounds()))
				bullet_destroy(wsk_gun->bullets_fired, i);
		}
		for (int j = 8; j < tab_wall.size(); j++)
			for (int i = 0; i < tab_z.size(); i++)
				if (tab_z[i].body.getGlobalBounds().intersects(tab_wall[j].getGlobalBounds()))tab_z[i].isInside = true;

			for (int i = 0; i < wsk_gun->bullets_fired.size(); i++)
			{
				if (wsk_gun->bullets_fired[i].onCreate_clock.getElapsedTime().asSeconds() >= wsk_gun->bullets_fired[i].lifeTime)
				{
					bullet_destroy(wsk_gun->bullets_fired, i);
				}
			}
		
		for (int i = 0; i < tab_bl.size(); i++)
		{
			if (tab_bl[i].onCreate_clock.getElapsedTime().asSeconds() >= tab_bl[i].lifeTime)
			{
				blood_destroy(tab_bl, i);
			}
		}
		for (int i = 0; i < tab_corps.size(); i++)
		{
			if (tab_corps[i].onCreate_clock.getElapsedTime().asSeconds() >= tab_corps[i].lifeTime)
			{
				corps_destroy(tab_corps, i);
			}
		}
		
		for(int i = 0; i < tab_am.size(); i++)
		{
			if (tab_am[i].onCreate_clock.getElapsedTime().asSeconds() >= tab_am[i].lifeTime)
			{
				ammo_destroy(tab_am, i);
			}
		}
		
		for (int i = 0; i < tab_hp.size(); i++)
		{
			if (tab_hp[i].onCreate_clock.getElapsedTime().asSeconds() >= tab_hp[i].lifeTime)
			{
				hp_destroy(tab_hp, i);
			}
		}
		
		///////////////////////////////////////////
		 
			interfejs(gracz.healthPoints, wsk_gun->bulletsLeft, hp, bullets_Left, view.getCenter(), wsk_gun->magazynek, runda, round, max_zombie_per_round - zombies_killed_in_round, licznik_zombie, 
				gun_name, wsk_gun->name, sprint_ui, isSprint&&(tab_p[0]!=gracz.body.getPosition()), czas);
		
		okno.setView(view);
		okno.clear();
		//cout << "Up: " << gracz.canMoveUP << " | Down: " << gracz.canMoveDown << " | Left: " << gracz.canMoveLeft << " | Right: " << gracz.canMoveRight << endl;
		/////////////////////////////////////////////////////
		gracz.input(vx, vy);
		if (Keyboard::isKeyPressed(Keyboard::LShift) && canSprint)
		{
			if (sprint_ui.getSize().x < 1) {
				canSprint = false;
			}
			sprint = 1.5;
			isSprint = true;
		}
		else
		{
			if (sprint_ui.getSize().x >15) {
				canSprint = true;
			}
			sprint = 1;
			isSprint = false;
		}
		//////////////////////////////////////
		//	ruch //

		
		gracz.ruch(czas, vx, vy, sprint);
	

		/*if (!tab_z.empty())
		{

			for (int i = 0; i < tab_z.size(); i++)
			{

				tab_z[i].ruch(tab_p[0], czas);
			}
		}*/

		
		////////////////////////////////
		okno.draw(map);		
		//rysowanie
	
		okno.draw(floor);
			if (!wsk_gun->bullets_fired.empty())
			{
				for (int i = 0; i <wsk_gun->bullets_fired.size(); i++)
					if (!gracz.body.getGlobalBounds().intersects(wsk_gun->bullets_fired[i].body.getGlobalBounds()))
					okno.draw(wsk_gun->bullets_fired[i].body);
			}
		
		if (!tab_bl.empty())
		{
			for (int i = 0; i < tab_bl.size(); i++)
			{
				
				okno.draw(tab_bl[i].body);
				//okno.draw(tab_bl[i].rect);
			}
		}
		if (!tab_corps.empty())
		{
			for (int i = 0; i < tab_corps.size(); i++)
				okno.draw(tab_corps[i].body);
		}
		if (!tab_am.empty())
		{

			for (int i = 0; i < tab_am.size(); i++)
			{
				if(tab_am[i].onCreate_clock.getElapsedTime().asSeconds() < tab_am[i].lifeTime-8.0f)
				okno.draw(tab_am[i].body);
				if (tab_am[i].onCreate_clock.getElapsedTime().asSeconds() >= tab_am[i].lifeTime - 8.0f)
				{
					if (tab_am[i].onCreate_clock.getElapsedTime().asMilliseconds() % 500 >= 0 && tab_am[i].onCreate_clock.getElapsedTime().asMilliseconds() % 500 <= 125) {
						//nie rysij
					}
					else okno.draw(tab_am[i].body);

				}
			}
		}
		if (!tab_hp.empty())
		{

			for (int i = 0; i < tab_hp.size(); i++)
			{
				if (tab_hp[i].onCreate_clock.getElapsedTime().asSeconds() < tab_hp[i].lifeTime - 8.0f)
					okno.draw(tab_hp[i].body);
				if (tab_hp[i].onCreate_clock.getElapsedTime().asSeconds() >= tab_hp[i].lifeTime - 8.0f)
				{
					if (tab_hp[i].onCreate_clock.getElapsedTime().asMilliseconds() % 500 >= 0 && tab_hp[i].onCreate_clock.getElapsedTime().asMilliseconds() % 500 <= 125) {
						//nie rysij
					}
					else okno.draw(tab_hp[i].body);

				}
			}
		}
		if (!tab_z.empty())
		{
			for (int i = 0; i < tab_z.size(); i++)
				okno.draw(tab_z[i].body);
		}
		for (int i = 4; i < tab_wall.size(); i++)
		{
			okno.draw(tab_wall[i]);
		}
		okno.draw(celownik);
		okno.draw(gracz.body);
		//okno.draw(gracz.point);
		okno.draw(wsk_gun->body);

		okno.draw(hp);
		okno.draw(bullets_Left);
		okno.draw(round);
		okno.draw(licznik_zombie);
		okno.draw(gun_name);
		okno.draw(sprint_ui);
		//////////////////////////////////

		View view = okno.getDefaultView();
		okno.display();
		
		czas = zegar.getElapsedTime();
		zegar.restart();

	}
	


}
예제 #7
0
int main()
{
	//Crear una ventana
	Vector2f windowMedidas;
	windowMedidas.x = 640; windowMedidas.y = 360;
	RenderWindow window(VideoMode(windowMedidas.x, windowMedidas.y), "Urban Mind (Demo)");
	window.setFramerateLimit(60);
	//Crear la V-Cam
	Vector2f CamaraPosicion, CamaraMedidas;
	CamaraPosicion.x = 0; CamaraPosicion.y = 0;
	CamaraMedidas.x = 640; CamaraMedidas.y = 360;
	View Camara(FloatRect(CamaraPosicion.x, CamaraPosicion.y, CamaraMedidas.x, CamaraMedidas.y));
	Camara.setCenter(CamaraMedidas.x / 2, CamaraMedidas.y / 2);

	int Screen = 1, nivel = 1, nivelMaximoAlcanzado = nivel; // Screen 1 = Menu, 2 = Niveles, 3 Otros...

	//Menu
	Texture BackgroundIMG;
	BackgroundIMG.loadFromFile("Dibujos/MainBackground.jpg");
	Sprite BGIMG;
	BGIMG.setTexture(BackgroundIMG);
	BGIMG.setOrigin(BackgroundIMG.getSize().x / 2, BackgroundIMG.getSize().y / 2);
	BGIMG.scale(0.48, 0.48);
	BGIMG.setPosition(320, 180);
	//Musica del menu
	sf::Music BgMainMusic;
	BgMainMusic.openFromFile("Musica/MainTheme.ogg");
	BgMainMusic.setVolume(50);
	BgMainMusic.setLoop(true);
	//Musica del juego
	Music LevelMusic;
	LevelMusic.openFromFile("Musica/LevelMusic.ogg");
	LevelMusic.setVolume(80);
	LevelMusic.setLoop(true);
	//Efecto de sonide empujar caja
	SoundBuffer DragFX;
	DragFX.loadFromFile("Musica/PullBox.ogg");
	Sound BoxFx(DragFX);
	//Botones
	int Selected = 0;
	bool KeyPressed = false;
	Boton Jugar = Boton(Vector2f(320, 180), "Dibujos/1Off.png", "Dibujos/1ON.png", 0.5), Salir = Boton(Vector2f(320, 230), "Dibujos/2Off.png", "Dibujos/2ON.png", 0.5);
	//Cosas inGame
	jugador yo = jugador(0,0);
	bloque box = bloque(1);
	bloque Tile1 = bloque(0);
	Texture TexturaMeta;
	TexturaMeta.loadFromFile("Dibujos/TSprite.jpg");
	Sprite Meta;
	Meta.setTexture(TexturaMeta);
	Meta.setOrigin(TexturaMeta.getSize().x / 2, TexturaMeta.getSize().y/2);
	Meta.scale(0.1,0.1);
	Vector2f coordenadasParaGanar;
	//Letras
	Font sansation;
	sansation.loadFromFile("Retro_Computer.ttf");
	Text scoreLabel("", sansation, 12);
	scoreLabel.setPosition(34, 15 * 34);
	scoreLabel.setColor(Color::White);

	//Contenedor de posiciones (Cajas), Contenedor de posiciones (Suelo)
	vector <Vector2f> contenedorDeCajas, contenedorDeSuelo;

	//Gameloop
	while (window.isOpen())
	{
		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == Event::Closed)
				window.close();
		};
		
		if (window.hasFocus()) //Si la aplicacion esta seleccionada
		{
			window.clear();

			switch (Screen)
			{
				case 1: //Menu principal

					//Si la musica no se esta reproduciendo...
					if (BgMainMusic.getStatus() != 2) 
						BgMainMusic.play();

					window.draw(BGIMG); //Dibujar fondo
					window.draw(Jugar.getSprite()); //Dibujar boton de jugar
					window.draw(Salir.getSprite()); //Dibujar boton de salir

					//Cambiar seleccion de boton
					if (!(Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) && (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) && Selected > 0 && !KeyPressed)
					{
						Selected--;
						KeyPressed = true;
					}
					else if ((Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) && !(Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) && Selected < 1 && !KeyPressed)
					{
						Selected++;
						KeyPressed = true;
					}
					else
					{
						KeyPressed = false;
					};

					if (Selected == 0)
					{
						Jugar.SetON();
						Salir.SetOFF();
					}
					else if (Selected == 1)
					{
						Jugar.SetOFF();
						Salir.SetON();
					};

					if (Keyboard::isKeyPressed(Keyboard::Return) || Keyboard::isKeyPressed(Keyboard::Space))
					{
						if (Selected == 0)
						{
							Screen = 2;
							BgMainMusic.stop();
						}
						else if (Selected == 1)
						{
							window.close();
						};
					};
					break;

				case 2: //Niveles

					//Ajustar camara al jugador
					CamaraPosicion.x = yo.getPosition().x - CamaraMedidas.x / 2;
					CamaraPosicion.y = yo.getPosition().y - CamaraMedidas.y / 2;
					Camara.reset(FloatRect(CamaraPosicion.x, CamaraPosicion.y, CamaraMedidas.x, CamaraMedidas.y));
					//Si la musica no se esta reproduciendo...
					if (LevelMusic.getStatus() != 2)
						LevelMusic.play();

					switch (nivel)
					{
						case 0: //Nivel jugable
							window.setView(Camara);

							for (int i = 0; i < contenedorDeSuelo.size(); i++) //Dibujar escenario
							{
								Tile1.positionOnMap(&contenedorDeSuelo[i]);
								window.draw(Tile1.getSprite());
							};

							//Dibujar la meta
							Meta.setPosition(coordenadasParaGanar.x * 34, coordenadasParaGanar.y * 34);
							window.draw(Meta);

							for (int i = 0; i < contenedorDeCajas.size(); i++) //Dibujar cajas
							{
								box.positionOnMap(&contenedorDeCajas[i]);
								window.draw(box.getSprite());
							};

							if (!yo.getMovingState()) //Si no te estas moviendo...
							{
								yo.checkMove(); //Revisar que accion quieres hacer

								for (int i = 0; i < contenedorDeSuelo.size(); i++) //Comprobar si hay suelo a 1 de ti
								{
									if (yo.IsPossible(&contenedorDeSuelo[i], 1)) //Hay un suelo a 1 de ti
									{
										yo.changeFloorTest(true);
										break;
									}
									else
										yo.changeFloorTest(false);
								};

								for (int i = 0; i < contenedorDeSuelo.size(); i++) //Comprobar si hay suelo a 2 de ti
								{
									if (yo.IsPossible(&contenedorDeSuelo[i], 2)) //Hay un suelo a 2 de ti
									{
										yo.changeSecondFloorTest(true);
										break;
									}
									else
										yo.changeSecondFloorTest(false);
								};

								for (int i = 0; i < contenedorDeCajas.size(); i++) //Comprobar si hay caja a 1 de ti
								{
									if (yo.IsPossible(&contenedorDeCajas[i], 1)) //Hay una caja a 1 de ti
									{
										yo.changeBlockTest(true);
										break;
									}
									else
										yo.changeBlockTest(false);
								};

								for (int i = 0; i < contenedorDeCajas.size(); i++) //Comprobar si hay una caja a 2 de ti
								{
									if (yo.IsPossible(&contenedorDeCajas[i], 2)) //Hay caja a 2 de ti
									{
										yo.changeSecondBlockTest(true);
										break;
									}
									else
										yo.changeSecondBlockTest(false);
								};

								if (yo.getIfHoldingBox()) //Seleccionar caja
								{
									for (int i = 0; i < contenedorDeCajas.size(); i++)
									{
										if (yo.getWatchingTo() == 'W' && yo.getPosition().x == contenedorDeCajas[i].x * 34 && yo.getPosition().y - 34 == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
										else if (yo.getWatchingTo() == 'S' && yo.getPosition().x == contenedorDeCajas[i].x * 34 && yo.getPosition().y + 34 == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
										else if (yo.getWatchingTo() == 'A' && yo.getPosition().x - 34 == contenedorDeCajas[i].x * 34 && yo.getPosition().y == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
										else if (yo.getWatchingTo() == 'D' && yo.getPosition().x + 34 == contenedorDeCajas[i].x * 34 && yo.getPosition().y == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
									};
								};

								//Comprobar si te puedes mover o no
								if (yo.getFloorTest() && !yo.getBlockTest() || yo.getFloorTest() && yo.getSecondFloorTest() && yo.getBlockTest() && !yo.getSecondBlockTest() && yo.getIfHoldingBox())
									//Si hay suelo y no hay caja, o si hay suelo a 1 y 2 de ti y hay caja a l de ti y la empujas y no hay caja a 2 de ti
									yo.setGoalByKey();

								//Si la caja esta cerca
								if (yo.getPosition().x - 34 <= contenedorDeCajas[yo.getBoxID()].x * 34 && yo.getPosition().x + 34 >= contenedorDeCajas[yo.getBoxID()].x * 34 && yo.getPosition().y - 34 <= contenedorDeCajas[yo.getBoxID()].y * 34 && yo.getPosition().y + 34 >= contenedorDeCajas[yo.getBoxID()].y * 34)
									yo.setIfBoxNear(true); //Puedes empujarla/jalarla
								else
									yo.setIfBoxNear(false); //No puedes empujarla/jalarla
							};

							//Si tienes el movimiento activado, moverte
							if (yo.getMovingState())
							{
								yo.movimiento(yo.getNextMove());

								if (yo.getIfHoldingBox() && yo.getIfBoxNear()) //Si estas jalando caja y esta cerca
								{
									if (yo.getNextMove() == 'W' && contenedorDeCajas[yo.getBoxID()].x == yo.getPosition().x / 34)
									{
										if (yo.getPosition().y / 34 > contenedorDeCajas[yo.getBoxID()].y) //Si la caja esta arriba de ti
										{
											yo.Animar('W', true, 0);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('S', true, 180);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else if (yo.getNextMove() == 'S' && contenedorDeCajas[yo.getBoxID()].x == yo.getPosition().x / 34)
									{
										if (yo.getPosition().y / 34 > contenedorDeCajas[yo.getBoxID()].y)
										{
											yo.Animar('W', true, 0);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('S', true, 180);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else if (yo.getNextMove() == 'A' && contenedorDeCajas[yo.getBoxID()].y == yo.getPosition().y / 34)
									{
										if (yo.getPosition().x / 34 > contenedorDeCajas[yo.getBoxID()].x)
										{
											yo.Animar('A', true, 270);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('D', true, 90);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else if (yo.getNextMove() == 'D' && contenedorDeCajas[yo.getBoxID()].y == yo.getPosition().y / 34)
									{
										if (yo.getPosition().x / 34 < contenedorDeCajas[yo.getBoxID()].x)
										{
											yo.Animar('D', true, 90);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('A', true, 270);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else
										yo.Animar(yo.getNextMove(), false, 0);
								}
								else
									yo.Animar(yo.getNextMove(), false, 0);
							};

							window.draw(yo.getCharSprite()); //Dibujar personaje

							//Texto
							window.draw(scoreLabel);
							scoreLabel.setPosition(yo.getPosition().x - CamaraMedidas.x / 2, yo.getPosition().y + CamaraMedidas.y / 2 - scoreLabel.getCharacterSize());
							scoreLabel.setString("Level: " + to_string(nivelMaximoAlcanzado));

							if(yo.getPosition().x == coordenadasParaGanar.x*34 && yo.getPosition().y == coordenadasParaGanar.y*34)
							{
								nivelMaximoAlcanzado++;
								nivel = nivelMaximoAlcanzado;
								//Vaciar los vectores
								contenedorDeCajas.clear();
								contenedorDeSuelo.clear();
								//Cambiar la caja seleccionada
								yo.setBoxID(0);
							}

							break;

						case 1: //Cargar nivel 1
							//Posicion del jugador
							yo.setPosition(5, 1);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(0, 1));
							contenedorDeSuelo.push_back(Vector2f(0, 1));
							contenedorDeSuelo.push_back(Vector2f(1, 1));
							contenedorDeSuelo.push_back(Vector2f(2, 1));
							contenedorDeSuelo.push_back(Vector2f(3, 1));
							contenedorDeSuelo.push_back(Vector2f(4, 1));
							contenedorDeSuelo.push_back(Vector2f(5, 1));
							//Meta
							coordenadasParaGanar.x = 1;
							coordenadasParaGanar.y = 1;
							//ir al jugable
							nivel = 0;
							break;
						case 2: //Cargar nivel 2
							//Posicion del jugador
							yo.setPosition(4, 2);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(2, 2));
							contenedorDeSuelo.push_back(Vector2f(2, 1));
							contenedorDeSuelo.push_back(Vector2f(3, 1));
							contenedorDeSuelo.push_back(Vector2f(1, 2));
							contenedorDeSuelo.push_back(Vector2f(2, 2));
							contenedorDeSuelo.push_back(Vector2f(3, 2));
							contenedorDeSuelo.push_back(Vector2f(4, 2));
							contenedorDeSuelo.push_back(Vector2f(2, 3));
							//Meta
							coordenadasParaGanar.x = 1;
							coordenadasParaGanar.y = 2;
							//ir al jugable
							nivel = 0;
							break;
						case 3: //Cargar nivel 3
							//Posicion del jugador
							yo.setPosition(3, 3);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(1, 3));
							contenedorDeSuelo.push_back(Vector2f(1, 1));
							contenedorDeSuelo.push_back(Vector2f(2, 1));
							contenedorDeSuelo.push_back(Vector2f(3, 1));
							contenedorDeSuelo.push_back(Vector2f(1, 2));
							contenedorDeSuelo.push_back(Vector2f(3, 2));
							contenedorDeSuelo.push_back(Vector2f(1, 3));
							contenedorDeSuelo.push_back(Vector2f(2, 3));
							contenedorDeSuelo.push_back(Vector2f(3, 3));
							contenedorDeSuelo.push_back(Vector2f(1, 4));
							//Meta
							coordenadasParaGanar.x = 1;
							coordenadasParaGanar.y = 4;
							//ir al jugable
							nivel = 0;
							break;
						case 4: //Cargar nivel 4
							//Posicion del jugador
							yo.setPosition(10, 13);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(8, 13));
							contenedorDeCajas.push_back(Vector2f(10, 9));
							contenedorDeCajas.push_back(Vector2f(8, 7));
							contenedorDeCajas.push_back(Vector2f(8, 4));
							contenedorDeCajas.push_back(Vector2f(11, 2));
							contenedorDeCajas.push_back(Vector2f(2, 7));
							contenedorDeCajas.push_back(Vector2f(4, 2));
							//fila 1
							contenedorDeSuelo.push_back(Vector2f(4, 1));
							contenedorDeSuelo.push_back(Vector2f(7, 1));
							contenedorDeSuelo.push_back(Vector2f(8, 1));
							contenedorDeSuelo.push_back(Vector2f(9, 1));
							contenedorDeSuelo.push_back(Vector2f(11, 1));
							//fila 2
							contenedorDeSuelo.push_back(Vector2f(4, 2));
							contenedorDeSuelo.push_back(Vector2f(6, 2));
							contenedorDeSuelo.push_back(Vector2f(7, 2));
							contenedorDeSuelo.push_back(Vector2f(9, 2));
							contenedorDeSuelo.push_back(Vector2f(10, 2));
							contenedorDeSuelo.push_back(Vector2f(11, 2));
							//fila 3
							contenedorDeSuelo.push_back(Vector2f(1, 3));
							contenedorDeSuelo.push_back(Vector2f(2, 3));
							contenedorDeSuelo.push_back(Vector2f(3, 3));
							contenedorDeSuelo.push_back(Vector2f(4, 3));
							contenedorDeSuelo.push_back(Vector2f(6, 3));
							contenedorDeSuelo.push_back(Vector2f(8, 3));
							contenedorDeSuelo.push_back(Vector2f(11, 3));
							//fila 4
							contenedorDeSuelo.push_back(Vector2f(1, 4));
							contenedorDeSuelo.push_back(Vector2f(4, 4));
							contenedorDeSuelo.push_back(Vector2f(5, 4));
							contenedorDeSuelo.push_back(Vector2f(6, 4));
//							contenedorDeSuelo.push_back(Vector2f(7, 4));
							contenedorDeSuelo.push_back(Vector2f(8, 4));
							contenedorDeSuelo.push_back(Vector2f(9, 4));
							contenedorDeSuelo.push_back(Vector2f(10, 4));
							contenedorDeSuelo.push_back(Vector2f(11, 4));
							//fila 5
							contenedorDeSuelo.push_back(Vector2f(1, 5));
							contenedorDeSuelo.push_back(Vector2f(4, 5));
							contenedorDeSuelo.push_back(Vector2f(8, 5));
							//fila 6
							contenedorDeSuelo.push_back(Vector2f(1, 6));
							contenedorDeSuelo.push_back(Vector2f(3, 6));
							contenedorDeSuelo.push_back(Vector2f(4, 6));
							contenedorDeSuelo.push_back(Vector2f(8, 6));
							//fila 7
							contenedorDeSuelo.push_back(Vector2f(1, 7));
							contenedorDeSuelo.push_back(Vector2f(2, 7));
							contenedorDeSuelo.push_back(Vector2f(3, 7));
							contenedorDeSuelo.push_back(Vector2f(4, 7));
							contenedorDeSuelo.push_back(Vector2f(8, 7));
							contenedorDeSuelo.push_back(Vector2f(9, 7));
							contenedorDeSuelo.push_back(Vector2f(10, 7));
							//fila 8
							contenedorDeSuelo.push_back(Vector2f(3, 8));
							contenedorDeSuelo.push_back(Vector2f(8, 8));
							contenedorDeSuelo.push_back(Vector2f(10, 8));
							//fila 9
							contenedorDeSuelo.push_back(Vector2f(8, 9));
							contenedorDeSuelo.push_back(Vector2f(9, 9));
							contenedorDeSuelo.push_back(Vector2f(10, 9));
							contenedorDeSuelo.push_back(Vector2f(11, 9));
							//fila 10
							contenedorDeSuelo.push_back(Vector2f(9, 10));
							//fila 11
							contenedorDeSuelo.push_back(Vector2f(8, 11));
							contenedorDeSuelo.push_back(Vector2f(9, 11));
							contenedorDeSuelo.push_back(Vector2f(10, 11));
							//fila 12
							contenedorDeSuelo.push_back(Vector2f(8, 12));
							//fila 13
							contenedorDeSuelo.push_back(Vector2f(7, 13));
							contenedorDeSuelo.push_back(Vector2f(8, 13));
							contenedorDeSuelo.push_back(Vector2f(9, 13));
							contenedorDeSuelo.push_back(Vector2f(10, 13));
							//Meta
							coordenadasParaGanar.x = 4;
							coordenadasParaGanar.y = 1;
							//ir al jugable
							nivel = 0;
							break;

						default:
							LevelMusic.stop();
							nivel = 1;
							nivelMaximoAlcanzado = 1;
							window.setView(window.getDefaultView());
							Screen = 1;
							break;
					};
					break;
				default:
					Screen = 1;
					break;
			};

			window.display();
		};
	};
};
예제 #8
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 Music skyrim, muse, bathMus;
	 bathMus.openFromFile("music/bath.ogg");
	 Object mus = lvl.GetObject("muse");
	 muse.openFromFile("music/synd.ogg"); muse.setVolume(100);
	 skyrim.openFromFile("music/skyrim.ogg"); skyrim.setVolume(100);
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Object fish = lvl.GetObject("fish");
	 Object mo = lvl.GetObject("mouse");
	 Object ob = lvl.GetObject("catPlace");


	 Player cat("cat.png", lvl, 68, 429, 60, 120, player.rect.left,  player.rect.top, ELSE);
	 
	 Clock clock;
	 Clock gameTimeClock;
	 int sinkCnt = 0;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf, buf3;
	buf.loadFromFile("music/steklo.ogg");
	buf3.loadFromFile("music/mouse.ogg");
	Sound glass; Sound mouseS;
	glass.setBuffer(buf); glass.setVolume(100);
	mouseS.setBuffer(buf3);
	
	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215, POSTERS);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440, ELSE); 
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545, TOYS);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83, SHELF);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305, CABINET); 
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385, MOP); 
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285, ELSE);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190, BALL); 
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187, BOOKS); 
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430, ELSE); 
	 Furniture key("tayles1.png", 1, 1, 25, 25, 430, 425, KEY);
	 Furniture cabinetEnd("cabinet.png", 20, 50, 270, 350, 590, 290, ELSE); 
	 Furniture girl("girlHair.png", 1,1, 96, 45, 1075, 350, ELSE);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350, ELSE);
	 Furniture puddle("tayles1.png",789, 1000, 204, 75, 1057, 559, ELSE);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430, ELSE);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565, ELSE);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330, BATH);
	 Furniture openBath("bathr.png", 264, 79, 339, 369, 1015, 315, ELSE);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530, ELSE);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300, ELSE);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450, SINK);
	 Furniture sinkWater("bathr.png", 22, 180, 197, 427, 1200, 540, ELSE);
	 Furniture mou("mouse.png",  2, 21, 32, 25, mo.rect.left, mo.rect.top, ELSE);
	 
	 
	 std::list<Furniture> fList;
	 std::list<Furniture>::iterator it;
	 fList.push_back(posters);
	 fList.push_back(toys);
	 fList.push_back(upShelf);
	 fList.push_back(cabinet);
	 fList.push_back(mop);
	 fList.push_back(ball);
	 fList.push_back(books);
	 fList.push_back(key);
	 fList.push_back(puddle);
	 fList.push_back(brokenLight);
	 fList.push_back(bath);
	 fList.push_back(sink);
	 for(it = fList.begin(); it != fList.end(); it++){
		 it->setSub((void *)&it, writeMess);
	 }

	 int cntMeow = 1, cntGame = 0, click = 0, clickBath = 1, clickSink = 1;
	 bath.isPlayed = true;
	 sink.isPlayed = true;


	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		float sinkTime = gameTimeClock.getElapsedTime().asSeconds();
		if(clickSink < 2)
			gameTimeClock.restart();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);
		
		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();

			if (event.type == Event::MouseButtonPressed)
				if (event.key.code == Mouse::Left){

					if (fish.rect.contains(pos.x, pos.y) && key.isPlayed == true){
						mainSong.stop();
						finish();
						window.close();
					}
					if (cat.sprite.getGlobalBounds().contains(pos.x, pos.y))
					{
						cntMeow++;
						if(cntMeow == 5)
						{
							meow2.play();
							cntMeow = 0;
						}
						else
							meow1.play();
					}
					 
					toys.trueMove(pos);
					if(light.isPlayed == false) light.trueMove(pos);
					if(ball.isPlayed == true && books.isPlayed == true) key.trueMove(pos);
					if(puddle.isPlayed == true) mop.trueMove(pos);
					click = light.clickedThings(pos);
					clickBath = bath.clickedThings(pos);
					clickSink = sink.clickedThings(pos);


					if (upShelf.sprite.getGlobalBounds().contains(pos.x, pos.y)){
						skyrim.play();
					}
					if (mus.rect.contains(pos.x, pos.y)){
						muse.play();
					}
					if (girl.sprite.getGlobalBounds().contains(pos.x, pos.y) && cat.room == 2){
						mainSong.pause();
						gameOver();
						mainSong.play();
					}
					if(mou.isPlayed == false)
						{
							if (mou.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								mouseS.play();
								//gameRunning();
								mou.isPlayed = true;
								mainSong.play();
							}
						}

						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}
				}
					
			if (event.type == Event::MouseButtonReleased)
				if (event.key.code == Mouse::Left){
					toys.isMove = false;
					key.isMove = false;
					if(light.isPlayed == false) light.isMove = false;
					 mop.isMove = false;
				}
		}
		if(sinkTime > 5 && clickSink == 2) puddle.isPlayed = true;

		if(clickBath == 2 && cat.room == 2)
			bathMus.play();

		if(click == -1){}
		else if(click == 1 || click == 2)
			cat.room = click;
		toys.intersect("toys",lvl); toys.move(pos); 
		if(mop.isPlayed == false)
		{
			mop.intersect("mop", lvl);
			mop.move(pos);
		}
		if(light.isPlayed == false) 
		{
			light.intersect("light", lvl);
			light.move(pos);
		}
		if(ball.isPlayed == true && books.isPlayed == true){
			if(mop.isPlayed == true)
				key.intersect("key", lvl);
			if(key.isPlayed == false)
				key.move(pos);
		}
		if(ball.isPlayed == false && books.isPlayed == true){
			if(cat.sprite.getGlobalBounds().intersects(ob.rect))
			{
				if(cntMeow == 0)
				{
					ball.falling(event, window, pos, lvl, time);
					glass.play();
					ball.isPlayed = true;
					ball.intersect("ball", lvl);
				}
			}
		}
        
      
		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		if(key.isPlayed == true)
			window.draw(cabinetEnd.sprite);
		else
			window.draw(cabinet.sprite);
		window.draw(upShelf.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
		{
			window.draw(brokenBall.sprite);
			window.draw(key.sprite);
		}
		window.draw(books.sprite);

		
		if(mou.isPlayed == false){
			window.draw(mou.sprite);
		}
		else
			window.draw(light.sprite);
		window.draw(toys.sprite);


		if(cat.room == 2){
				
			 if(clickBath == 2){
				window.draw(girl.sprite);
				window.draw(openBath.sprite);
			 }
			 else
				 window.draw(bath.sprite);
			window.draw(mirror.sprite);

			 if(clickSink == 2)
				window.draw(sinkWater.sprite);
			 else
				 window.draw(sink.sprite);

			 if(puddle.isPlayed == true && mop.isPlayed == false)
				window.draw(puddle.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		if(mop.isPlayed == false)
			window.draw(mop.sprite);
		window.draw(cat.sprite);

		for(it = fList.begin(); it != fList.end(); it++)
			{
				if(it->sprite.getGlobalBounds().contains(pos.x, pos.y))
				{
					if(it->f.cb_fn != NULL)
					{
						cb_fn fn;
						fn = (cb_fn)it->f.cb_fn;
						fn(&window, it->type, &pos);
					}
				}
			}
		
		window.display();
    }

}
예제 #9
0
int main()
{  
    RenderWindow window(VideoMode(800, 250), "Mario v0.1 Alpha");
	Texture tileSet;
	tileSet.loadFromFile("Mario_Tileset.png");

	//===========================
	PLAYER Mario(tileSet);
	//==========[Bot]============
	ENEMY  enemy[3];
	enemy[0].set(tileSet,48*16,13*16);//1lvl
	enemy[1].set(tileSet,110*16,13*16);
	enemy[2].set(tileSet,48*16,30*16);//2lvl
	/*enemy[3].set(tileSet,110*16,13*16);
	enemy[4].set(tileSet,48*16,13*16);//3lvl
	enemy[5].set(tileSet,110*16,13*16);*/
	//===========================
	Sprite tile(tileSet);
	SoundBuffer buffer;
	//==========[«вук]============
	buffer.loadFromFile("Jump.ogg");
	Sound sound(buffer);
	//==========[Ўрифты]==========
	sf::Font font;
	font.loadFromFile("arial.ttf");
	//==========[ћеню]============
	Texture menu_texture1,menu_texture2,menu_texture3,about_texture;
	menu_texture1.loadFromFile("111.png");
	menu_texture2.loadFromFile("222.png");
    menu_texture3.loadFromFile("333.png");
	about_texture.loadFromFile("about.png");
	Sprite menu1(menu_texture1),menu2(menu_texture2),menu3(menu_texture3),about(about_texture);
	if(NewGm==true) {
		NewGame:
		GameOver=false;
		Mario.rect.left=100; Mario.rect.top=180;
		Mario.sprite.setPosition(100, 180);  
		offsetX = Mario.rect.left-100; 
		enemy[0].life=true; enemy[1].life=true;
		offsetY = Mario.rect.top-180; 
		std::cout<<Mario.rect.left<<"   "<< Mario.rect.top<<std::endl;
		NewGm=false;
	}

	bool Menu=1;
	int MenuNum=0;
	menu1.setPosition(100,30);
	menu2.setPosition(100,90);
    menu3.setPosition(100,150);

	while(Menu)
	{	   
	   menu1.setColor(Color::White);
	   menu2.setColor(Color::White);
	   menu3.setColor(Color::White);
	   MenuNum=0;
	   window.clear(Color(0,0,0));

	   if (IntRect(100,30,300,50).contains(Mouse::getPosition(window))) {menu1.setColor(Color::Yellow); MenuNum=1;}
       if (IntRect(100,90,300,50).contains(Mouse::getPosition(window))) {menu2.setColor(Color::Yellow); MenuNum=2;}
       if (IntRect(100,150,300,50).contains(Mouse::getPosition(window))) {menu3.setColor(Color::Yellow); MenuNum=3;}

	   if (Mouse::isButtonPressed(Mouse::Left))
	     {
			 if (MenuNum==1) Menu=false;
			 if (MenuNum==2) {window.draw(about); window.display(); while(!Keyboard::isKeyPressed(Keyboard::Escape)) ;}
			 if (MenuNum==3)  {window.close();Menu=false;}

	     }
		window.draw(menu1);
        window.draw(menu2);
		window.draw(menu3);
		window.display();
	}
	//==========[¬рубаем музыку в игру]============
	Music music;
    music.openFromFile("Mario_Theme.ogg");
    music.play();
	//==================[»гра]=====================
	Clock clock;

    while (GameOver==false)
    { 
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		if (time > 20) time = 20; 

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)      
                window.close();
		}
		if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.dx=-0.1; 
	    if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.dx=0.1;
	    if (Keyboard::isKeyPressed(Keyboard::Up)) if (Mario.onGround) { Mario.dy=-0.27; Mario.onGround=false;  sound.play(); }
	 
		 Mario.update(time);
		 enemy[0].update(time);
		 enemy[1].update(time);
		 enemy[2].update(time);

		 if  (Mario.rect.intersects(enemy[0].rect))
		 {
			 if (enemy[0].life) {
				 if (Mario.dy>0) { enemy[0].dx=0; Mario.dy=-0.2; enemy[0].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if  (Mario.rect.intersects(enemy[1].rect))
		 {
			 if (enemy[1].life) {
				 if (Mario.dy>0) { enemy[1].dx=0; Mario.dy=-0.2; enemy[1].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if  (Mario.rect.intersects(enemy[2].rect))
		 {
			 if (enemy[2].life) {
				 if (Mario.dy>0) { enemy[2].dx=0; Mario.dy=-0.2; enemy[2].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if (Mario.rect.left>200) offsetX = Mario.rect.left-200;
		 window.clear(Color(107,140,255));
		 for (int i=0; i<H; i++)
			 for (int j=0; j<W; j++)
			 { 
				switch(TileMap[i][j]) {
					case 'P':  tile.setTextureRect( IntRect(143-16*3,112,16,16)); break; 
					case 'k': tile.setTextureRect( IntRect(143,112,16,16)); break; 
					case 'c': tile.setTextureRect( IntRect(143-16,112,16,16)); break; 
					case 't': tile.setTextureRect( IntRect(0,47,32,95-47)); break; 
					case 'm': tile.setTextureRect( IntRect(96,6,202-47,111)); break; 
					case 'g': tile.setTextureRect( IntRect(0,16*9-5,3*16,16*2+5)); break; 
					case 'G': tile.setTextureRect( IntRect(145,222,222-145,255-222)); break; 
					case 'd': tile.setTextureRect( IntRect(0,106,74,127-106)); break; 
					case 'w': tile.setTextureRect( IntRect(99,224,140-99,255-224)); break; 
					case 'r': tile.setTextureRect( IntRect(143-32,112,16,16)); break; 
					default: continue;
				}

  			    tile.setPosition(j*16-offsetX,i*16 - offsetY) ; 
		        window.draw(tile);
			}
		window.draw(Mario.sprite);
	    window.draw(enemy[0].sprite);
		window.draw(enemy[1].sprite);
		window.draw(enemy[2].sprite);
		window.display();
    }
	while(Win)
	{	
		GameOver=false;
		window.clear(Color(0,0,0));
		sf::Text text("You Win! :3", font); 
		text.setPosition(100,30);
		text.setCharacterSize(30);
		text.setStyle(sf::Text::Bold);
		text.setColor(sf::Color::Yellow);
		window.draw(text);	
		sf::Text text1("Press ESC", font); 
		text1.setPosition(100,60);
		text1.setCharacterSize(30);
		text1.setStyle(sf::Text::Bold);
		text1.setColor(sf::Color::Red);
		window.draw(text1);	
		window.display();
		if (Keyboard::isKeyPressed(Keyboard::Escape)) { goto NewGame; NewGm=true; }
	}
	while(GameOver)
	{	   
		window.clear(Color(0,0,0));
		sf::Text text("Game Over :c", font); 
		text.setPosition(100,30);
		text.setCharacterSize(30);
		text.setStyle(sf::Text::Bold);
		text.setColor(sf::Color::Red);
		window.draw(text);	
		sf::Text text1("Press ESC", font); 
		text1.setPosition(100,60);
		text1.setCharacterSize(30);
		text1.setStyle(sf::Text::Bold);
		text1.setColor(sf::Color::Red);
		window.draw(text1);	
		window.display();
		if (Keyboard::isKeyPressed(Keyboard::Escape)) { goto NewGame; NewGm=true; }
	}
    return 0;
}
예제 #10
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Player cat("cat.png", lvl, player.rect.left, player.rect.top, 60, 120, 55, 25);
	 Clock clock;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf;
	buf.loadFromFile("music/steklo.ogg");
	Sound glass;
	glass.setBuffer(buf); glass.setVolume(100);

	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440);
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385);
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190);
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187);
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450);
	 int cntMeow = 0;
	 Object ob = lvl.GetObject("catPlace");
	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

			if (event.type == Event::MouseButtonPressed){
					if (event.key.code == Mouse::Left)
					{
						int cntMeow = meow(meow1, meow2, cat, pos);
						//>>>>>>BALL<<<<<<<<<<<<<<
						if(cat.sprite.getGlobalBounds().intersects(ob.rect))
						{
							if(cntMeow == -1)
							{
								ball.falling(event, window, pos, lvl, time);
								glass.play();
								ball.moving(event, window, pos, "ball", lvl);
							}
						}
						cat.clickedThings(window, light);
						//BOOKS>>>>----<<<<<<
						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}

					}
			}		
					
					toys.moving(event, window, pos, "toys", lvl);
					if(light.isPlayed == false)
						light.moving(event, window, pos, "light", lvl);
					

	
        }
		
		

		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		window.draw(light.sprite);
		window.draw(toys.sprite);
		window.draw(upShelf.sprite);
		window.draw(cabinet.sprite);
		window.draw(mop.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
			window.draw(brokenBall.sprite);
		window.draw(books.sprite);



		if(cat.room == 2){
			window.draw(bath.sprite);
			window.draw(mirror.sprite);
			window.draw(sink.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		

		window.draw(cat.sprite);
		
		window.display();
    }

}
예제 #11
0
void SoundHandler::initializeSounds()
{
	criticalTimer = new Clock();
	messageTimer = new Clock();
	soundTimer = new Clock();
	spellTimer = new Clock();
	urgentTimer = new Clock();
	
	criticalSound = new Sound();
	genericSound = new Sound();
	message = new Sound();
	spellSound = new Sound();
	urgentSound = new Sound();


	SoundBuffer* buffer;
	Music* music;
	string name;

	sounds.push_back("gold_drop_1");
	sounds.push_back("gold_drop_2");
	sounds.push_back("gold_drop_3");
	sounds.push_back("imp_mine_1");
	sounds.push_back("imp_mine_2");
	sounds.push_back("imp_mine_3");
	sounds.push_back("imp_mine_4");
	sounds.push_back("imp_mine_5");
	sounds.push_back("imp_mine_6");
	sounds.push_back("imp_spawn");
	sounds.push_back("imp_step_1");
	sounds.push_back("imp_step_2");
	sounds.push_back("imp_step_3");
	sounds.push_back("imp_step_4");
	sounds.push_back("option_failure");
	sounds.push_back("option_select_1");
	sounds.push_back("option_select_2");
	sounds.push_back("tile_build");
	sounds.push_back("tile_cave-in_1");
	sounds.push_back("tile_cave-in_2");
	sounds.push_back("tile_cave-in_3");
	sounds.push_back("tile_select");
	sounds.push_back("tile_sell");
	sounds.push_back("voice_bigger_treasury");
	sounds.push_back("voice_game_saved");
	sounds.push_back("voice_game_loaded");
	sounds.push_back("voice_need_treasury");
	sounds.push_back("voice_tunneled_new_area");

	int length = sounds.size();

	for (int i = 0; i < length; i++)
	{
		buffer = new SoundBuffer();
		name = sounds[i];
		buffer->loadFromFile("Resources/" + name + ".ogg");
		soundMap[name] = buffer;
	}

	songs.push_back("game_music");
	songs.push_back("menu_music");
	length = songs.size();

	for (int i = 0; i < length; i++)
	{
		music = new Music();
		name = songs[i];
		music->openFromFile("Resources/" + name + ".ogg");
		musicMap[name] = music;
	}
}