void init(){
  _backgroundImage.LoadFromFile("assets/wood-puzzle-floor.png");
  _backgroundSprite.SetImage(_backgroundImage);
  
  _robotImage.LoadFromFile("assets/roomba.png");
  _robotSprite.SetImage(_robotImage);
  _robotSprite.SetCenter(_robotSprite.GetSize().x/2, _robotSprite.GetSize().y/2);
  _fakeRobotSprite.SetImage(_robotImage);
  _fakeRobotSprite.SetCenter(_fakeRobotSprite.GetSize().x/2, _fakeRobotSprite.GetSize().y/2);
  _fakeRobotSprite.SetColor(sf::Color(100,100,255));

  _landmarkImage.LoadFromFile("assets/landmark.png");
  _landmarkSprite.SetImage(_landmarkImage);
  _landmarkSprite.SetCenter(_landmarkSprite.GetSize().x/2, _landmarkSprite.GetSize().y/2);

  _rangeImage.LoadFromFile("assets/range.png");
  _rangeSprite.SetImage(_rangeImage);
  original_range_sprite_size_x = _rangeSprite.GetSize().x;
  original_range_sprite_size_y = _rangeSprite.GetSize().y;
  updateRangeSpriteScale();
  _rangeSprite.SetCenter((original_range_sprite_size_x/2), (original_range_sprite_size_y/2));

  _window.Create(sf::VideoMode(window_width,window_height,32), "Bearing simulator");

  move_amount = 0;
  rotation_amount = 0;
  time_to_capture = false;
  
  walk = 0;
  rotation = 0;
}
示例#2
0
文件: main.cpp 项目: dexter1986/unli
int main()
{
	img_r.LoadFromFile("..\\Imagenes\\rcircle.png");
	img_b.LoadFromFile("..\\Imagenes\\bcircle.png");
	
	sprite_b.SetImage(img_b);
	sprite_r.SetImage(img_r);

	sf::RenderWindow App(sf::VideoMode(800,600,32),"ventana");
	
	const sf::Input& in = App.GetInput();

	sprite_b.Scale(sprite_r.GetSize().x/sprite_b.GetSize().x,sprite_r.GetSize().y/sprite_b.GetSize().y);

	while(App.IsOpened())
	{

		while(App.GetEvent(Event))
		{
			if(Event.Type == sf::Event::Closed)
				App.Close();

			if(Event.Type == sf::Event::MouseMoved){
			//	cursor.SetPosition(Event.MouseMove.X,Event.MouseMove.Y);
			}

		}

		if(in.IsKeyDown(sf::Key::Escape))
			App.Close();

		//cursor.SetPosition(in.GetMouseX(),in.GetMouseY());

		App.Clear();
		sprite_r.SetPosition(0,0);
		App.Draw(sprite_r);

		sprite_r.SetPosition(App.GetWidth()-img_r.GetWidth(),0);
		App.Draw(sprite_r);

		sprite_r.SetPosition(0,App.GetHeight()-img_r.GetHeight());
		App.Draw(sprite_r);

		sprite_r.SetPosition(App.GetWidth()-img_r.GetWidth(),App.GetHeight()-img_r.GetHeight());
		App.Draw(sprite_r);
		
		sprite_b.SetPosition((App.GetWidth()-sprite_b.GetSize().x)/2,(App.GetHeight()-sprite_b.GetSize().y)/2);
		App.Draw(sprite_b);
		App.Display();
	}

	return 0;
}
示例#3
0
void Player::drawAtributes(sf::RenderWindow& rw) const
{
	static bool firstRun = true;
	static sf::Image tlo;
	static sf::Font font;
	if(firstRun)
	{
		tlo.LoadFromFile("Images/tlo.png");
		firstRun = false;
		font.LoadFromFile("silesiana.otf", 50,  L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��XxVvQq0123456789~!@#$%^&*()_-[]\\;',./{}:\"<>?=-+ ");
	}
	sf::Sprite tloH(tlo);
	rw.Draw(tloH);
	
	std::wstringstream ss;
	if(selectedAttribute == 0)
	{
		ss << L"Exp: " << xp << L"\n";
		ss << L"> Poziom obrony: " << defLevel << L"\n";
		ss << L"Poziom ataku: " << attLevel << L"\n";
	}
	else
	{
		ss << L"Exp: " << xp << L"\n";
		ss << L"Poziom obrony: " << defLevel << L"\n";
		ss << L"> Poziom ataku: " << attLevel << L"\n";
	}
	sf::String t(ss.str(), font, 30.f);
	t.SetColor(sf::Color(20, 18, 160));
	t.SetPosition(20.f, 20.0);
	rw.Draw(t);
}
示例#4
0
void ImageManager::AbstractLoadFromFile(sf::Image &image, std::string name, bool transparency, sf::Color color)
{
    if (!image.LoadFromFile(name))
        std::cerr << "Impossible d'ouvrir le fichier " << name << " !" << std::endl;

    if(transparency)
    {
        image.SetSmooth(false);
        image.CreateMaskFromColor(color);
    }
}
示例#5
0
void Player::drawInventory(sf::RenderWindow& rw) const
{
	static bool firstRun = true;
	static sf::Image tlo;
	static sf::Font font;
	if(firstRun) 
	{
		tlo.LoadFromFile("Images/inv.png");
		firstRun = false;
		font.LoadFromFile("silesiana.otf", 50,  L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��XxVvQq0123456789~!@#$%^&*()_-[]\\;',./{}:\"<>?=-+ ");
	}

	sf::Sprite tloH(tlo);
	rw.Draw(tloH);
	
	std::stringstream ss;
	ss<<"Masz " << coins << " $";
	sf::String t(ss.str(), font, 30.f);
	t.SetColor(sf::Color(20, 18, 160));
	t.SetPosition(600.f, 30.f);
	rw.Draw(t);

	float posy = 30.0;
	int i = 0;
	for(std::vector<Item>::const_iterator it = inventory.begin(); it != inventory.end(); it++)
	{
		std::wstring name = it->getName();
		if(i == weapon)
		{
			name += L" (uzbrojny - bro�)";
		}
		if(i == armor)
		{
			name += L" (uzbrojny - zbroja)";
		}
		sf::String t(name, font, 30.f);
		t.SetColor(sf::Color(20, 18, 160));
		if(selectedItem == i)
			t.SetColor(sf::Color(200, 18, 160));
		t.SetPosition(20.f, posy);
		rw.Draw(t);
		posy += 30.0;
		i++;
	}
	if(0 <= selectedItem && selectedItem < inventory.size())
	{
		TextArea desc(inventory[selectedItem].getDesc(), 400, font);
		desc.SetPosition(300, 50);
		rw.Draw(desc);
		Item::Type type = inventory[selectedItem].getProperty();
		if(type == 0)
		{
			TextArea desc1(L"Bron - Atak + " +inventory[selectedItem].getBoost(), 400,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}
		else if(type == 1)
		{
			TextArea desc1(L"Zbroja - Obrona + " +inventory[selectedItem].getBoost(), 400,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}
		else if(type == 2)
		{
			TextArea desc1(L"Helm - Obrona + " +inventory[selectedItem].getBoost(), 400,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}
		else if(type == 3)
		{
			TextArea desc1(L"Mikstura", 460,font);
			desc1.SetPosition(350,250);
			rw.Draw(desc1);
		}

		
	}
}
示例#6
0
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    srand((unsigned)time(0));
    bool spaceIsPressed = false;
    bool finishedEnteringName = false;
    bool savedToFile = false;

    sf::Clock clock;
    float currentTime, deathTime = 0.0f;

    sf::String whatever;
    whatever.SetPosition(300, 300);
    sf::String youMadeIt("You made it to the high score list! Enter your name:");
    youMadeIt.SetPosition(300, 275);
    std::string inputString;
    initHighScores(highScoreList);
    sf::String highScoreString(convertScoresToString(highScoreList));

    bool gameOver = false;

    sf::Music backgroundMusic;
    if ( !backgroundMusic.OpenFromFile("Music/02 - Salt In The Wounds.ogg"))
        return -9;
    backgroundMusic.Play();


    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Space Invaders!");
    App.UseVerticalSync(true);

    // Load the sprite image from a file
    sf::Image PlayerImage;
    if (!PlayerImage.LoadFromFile("Images/player.psd"))
        return EXIT_FAILURE;

    sf::Sprite Player(PlayerImage);
    Player.SetPosition(200.f, 100.f);
    Player.SetCenter(32.f, 32.f);

    sf::Image BackgroundImage;
    if ( !BackgroundImage.LoadFromFile("Images/space.psd"))
        return -1;
    sf::Sprite Background(BackgroundImage);

    std::vector<sf::Sprite> missiles;
    sf::Image MissileImage;
    if ( !MissileImage.LoadFromFile("Images/Missle.psd"))
        return -1;

    std::vector<Enemy> enemies;
    if ( !EnemyImage.LoadFromFile("Images/Bad Guy!.psd"))
        return -2;
    createWave(enemies);

    std::vector<sf::Sprite> enemyMissiles;
    if ( !EnemyMissileSprite.LoadFromFile("Images/BadGuyMissile.psd") )
        return -3;

    sf::String help("Use WASD to move and change your direction.\nUse the arrow keys to move without changing your direction.\nPress space to fire.");
    help.SetSize(16.0f);
    help.SetColor(sf::Color::Red);
    help.SetPosition(848, 0);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            if (Event.Key.Code == sf::Key::F1)
            {
                sf::Image Screen = App.Capture();
                Screen.SaveToFile("screenshot.png");
            }

            if ( gameOver && score > getLastScore(highScoreList))
            {

                if (Event.Type == sf::Event::TextEntered)
                {
                    char c = Event.Text.Unicode;

                    if (c == 8)//8 is backspace
                    {
                        if (inputString.size() > 0)//check that there is something to delete
                        {
                            inputString.erase(inputString.end() - 1);//delete the last character
                        }
                    }
                    else if (c < 128 && c > 31)//pretty much anything you want should be between 31 and 128
                    {
                        inputString.push_back(c);
                    }
                }


                whatever.SetText(inputString);
            }

        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();
        currentTime = clock.GetElapsedTime();

        if ( !gameOver )
        {
            // Move the sprite
            if ((App.GetInput().IsKeyDown(sf::Key::A) || App.GetInput().IsKeyDown(sf::Key::Left)) && Player.GetPosition().x > 32)
            {
                Player.Move(-250 * ElapsedTime, 0);
            }
            if ((App.GetInput().IsKeyDown(sf::Key::D) || App.GetInput().IsKeyDown(sf::Key::Right)) && Player.GetPosition().x < 300)
            {
                Player.Move( 250 * ElapsedTime, 0);
            }
            if ((App.GetInput().IsKeyDown(sf::Key::W) || App.GetInput().IsKeyDown(sf::Key::Up)) && Player.GetPosition().y > 32)
            {
                Player.Move(0, -250 * ElapsedTime);
            }
            if ((App.GetInput().IsKeyDown(sf::Key::S) || App.GetInput().IsKeyDown(sf::Key::Down)) && Player.GetPosition().y < 688)
            {
                Player.Move(0,  250 * ElapsedTime);
            }

            //rotate the sprite
            if (App.GetInput().IsKeyDown(sf::Key::A))
            {
                Player.SetRotation(180);
            }
            if (App.GetInput().IsKeyDown(sf::Key::D) )
            {
                Player.SetRotation(0);
            }
            if (App.GetInput().IsKeyDown(sf::Key::W) )
            {
                Player.SetRotation(90);
            }
            if (App.GetInput().IsKeyDown(sf::Key::S) )
            {
                Player.SetRotation(270);
            }


            if ( !App.GetInput().IsKeyDown(sf::Key::Space) )
            {
                spaceIsPressed = false;
            }

            if ( App.GetInput().IsKeyDown(sf::Key::Space) && !spaceIsPressed)
            {
                sf::Sprite Missile(MissileImage);
                Missile.SetPosition(Player.GetPosition());
                Missile.SetRotation(Player.GetRotation());
                missiles.push_back(Missile);
                spaceIsPressed = true;
            }

            makeEnemiesShoot(enemies, enemyMissiles);

            moveMissiles(missiles, ElapsedTime);
            moveEnemyMissiles(enemyMissiles, ElapsedTime);

            checkMissiles(missiles);
            checkMissiles(enemyMissiles);

            if ( !enemiesInPlace )
                moveEnemiesIn(enemies, ElapsedTime);

            testCollisions(enemies, missiles);
            if ( checkCollisions(Player, enemyMissiles) )
            {
                // Player has been hit! Clear the screen of missiles, reset his position, and decrease the lives
                lives--;
                enemyMissiles.clear();
                Player.SetPosition(200.0f, 32.0f);
                deathTime = clock.GetElapsedTime();

                if ( lives < 0 )
                    gameOver = true;
            }

            if ( getAliveEnemies(enemies) == 0 )
                createWave(enemies);
        }
        else
        {
            if ( App.GetInput().IsKeyDown(sf::Key::Escape) )
                App.Close();
            if ( App.GetInput().IsKeyDown(sf::Key::Return))
                finishedEnteringName = true;
        }
        std::string sStats;
        std::stringstream out;


        out<< "Lives: ";
        if ( lives < 0)
            out<< "Dead";
        else
            out<< lives;

        out << "  Score: " << score;
        sStats = out.str();


        sf::String StringStats(sStats);
        StringStats.SetPosition(10,680);
        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(Background);
        for ( unsigned int i = 0; i < missiles.size(); i++ )
            App.Draw(missiles.at(i));
        if ( !gameOver )
            App.Draw(Player);

        for ( unsigned int i = 0; i < enemies.size(); i++)
            if ( enemies.at(i).isAlive() )
                App.Draw(enemies.at(i).getSprite());
        for ( unsigned int i = 0; i < enemyMissiles.size(); i++ )
            App.Draw(enemyMissiles.at(i));

        App.Draw(StringStats);
        App.Draw(help);

        if ( currentTime - deathTime < 1.0f && clock.GetElapsedTime() > 1.0f)
        {
            sf::String deathInfo("You've been killed!");
            deathInfo.SetPosition(360, 0);
            App.Draw(deathInfo);
        }

        if ( gameOver )
        {
            sf::String gameOverString("Game Over! You lose! Press Esc to quit.");
            std::string scoreMsg;
            if ( score == 0 )
                scoreMsg = "Wow you suck";
            else if ( score < 750 )
            {
                scoreMsg = "You're getting there! Better luck next time.";
            }
            else
            {
                scoreMsg = "You died, but you died after killing a lot of people. Good job!";
            }

            sf::String ScoreMsg(scoreMsg);

            gameOverString.SetPosition(350, 600);
            ScoreMsg.SetPosition(350, 625);
            App.Draw(gameOverString);
            App.Draw(ScoreMsg);
            App.Draw(highScoreString);
            if ( score > getLastScore(highScoreList) && !finishedEnteringName )
            {
                App.Draw(youMadeIt);
                App.Draw(whatever);
            }

            if ( finishedEnteringName && !savedToFile)
            {
                if ( score > getLastScore(highScoreList))
                {
                    for ( unsigned int i = 0; i < highScoreList.size(); i++ )
                    {
                        Score temp = highScoreList.at(i);
                        if ( score >  temp.Getscore())
                        {
                            //add the new score before this one
                            Score newScore(inputString, score);
                            highScoreList.insert(highScoreList.begin()+i, newScore);
                            highScoreList.erase(highScoreList.end()-1);
                            break;
                        }
                    }

                    saveScoresToFile(highScoreList);
                    highScoreString.SetText(convertScoresToString(highScoreList));
                    savedToFile = true;
                }
            }
        }

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

    return EXIT_SUCCESS;
}
示例#7
0
文件: main.cpp 项目: dexter1986/unli
int main()
{
	img_r.LoadFromFile("..\\Imagenes\\rcircle.png");
	img_b.LoadFromFile("..\\Imagenes\\bcircle.png");
	
	sprite_b.SetImage(img_b);
	sprite_r[0].SetImage(img_r);
	sprite_r[1].SetImage(img_r);
	sprite_r[2].SetImage(img_r);
	sprite_r[3].SetImage(img_r);

	sf::RenderWindow App(sf::VideoMode(800,600,32),"ventana");

	const sf::Input& in = App.GetInput();
	
	sprite_b.Scale(sprite_r[0].GetSize().x/sprite_b.GetSize().x,sprite_r[0].GetSize().y/sprite_b.GetSize().y);
	sprite_r[0].SetPosition(0,0);
	sprite_r[1].SetPosition(App.GetWidth()-img_r.GetWidth(),0);
	sprite_r[2].SetPosition(0,App.GetHeight()-img_r.GetHeight());
	sprite_r[3].SetPosition(App.GetWidth()-img_r.GetWidth(),App.GetHeight()-img_r.GetHeight());
	sprite_b.SetPosition((App.GetWidth()-sprite_b.GetSize().x)/2,(App.GetHeight()-sprite_b.GetSize().y)/2);

	int index = -1;
	int pos_x,pos_y;

	while(App.IsOpened())
	{
		while(App.GetEvent(Event))
		{
			if(Event.Type == sf::Event::Closed)
				App.Close();
			
			if(index == -1 && Event.Type == sf::Event::MouseButtonPressed)
			{
				int x = Event.MouseButton.X;
				int y = Event.MouseButton.Y;
				int sx,sy;
				int w,h;
				for(int i=0;i<4;i++)
				{
					sx = sprite_r[i].GetPosition().x;
					sy = sprite_r[i].GetPosition().y;
					h = sprite_r[i].GetSize().y;
					w = sprite_r[i].GetSize().x;
					if(sx < x && sx + w > x && sy < y && sy + h > y)
					{
						index = i;
						pos_x = x;
						pos_y = y;
						break;
					}
				}
			}

			if(index > -1 && Event.Type == sf::Event::MouseButtonReleased)
			{
				index = -1;
			}
		}

		if(in.IsKeyDown(sf::Key::Escape))
			App.Close();

		if(index > -1)
		{
		   int off_x = in.GetMouseX() - pos_x;
		   int off_y = in.GetMouseY() - pos_y;
		   pos_x = in.GetMouseX();
		   pos_y = in.GetMouseY();
		   sprite_r[index].Move(off_x,off_y);		   
		}

		App.Clear();
		
		App.Draw(sprite_r[3]);
		App.Draw(sprite_r[2]);		
		App.Draw(sprite_r[1]);
		App.Draw(sprite_r[0]);
		App.Draw(sprite_b);

		App.Display();
	}

	return 0;
}