当前位置: 首页>>代码示例>>C++>>正文


C++ Level::GetObjects方法代码示例

本文整理汇总了C++中Level::GetObjects方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::GetObjects方法的具体用法?C++ Level::GetObjects怎么用?C++ Level::GetObjects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Level的用法示例。


在下文中一共展示了Level::GetObjects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{

	RenderWindow window(VideoMode(1200, 800), "sds");
	Level lv;
	lv.LoadFromFile("Test map.tmx");
	std::vector<Object> mapObj;
	
	mapObj = lv.GetObjects("solid");
	//Event event;


	Texture hero; ///Текстура нашего игрока 
	hero.loadFromFile("ScarletRun2Right.png");
	Texture heroLeft;
	heroLeft.loadFromFile("ScarletRun2Left.png");

	Animation PlayerAnim[4];
	PlayerAnim[0].setSpriteSheet(hero);
	PlayerAnim[0].loadFromXml("SkarletMoveRight.xml");
	PlayerAnim[1].setSpriteSheet(hero);
	PlayerAnim[1].loadFromXml("SkarletMoveRight.xml");
	PlayerAnim[2].setSpriteSheet(hero);
	PlayerAnim[2].loadFromXml("SkarletMoveRight.xml");
	PlayerAnim[3].setSpriteSheet(heroLeft);
	PlayerAnim[3].loadFromXml("SkarletMoveLeft.xml");


	Hero her;
	her.setHeroAnimation(PlayerAnim);
	her.setHeroPossition(0, 20);
	her.setHeroAnimationSpeed(1.0f);
	her.setHeroSpeed(20);

	sf::Clock frameClock;// Наши часики 

	float speed = 80.f;
	
	
	while (window.isOpen())
	{

		sf::Time frameTime = frameClock.restart();
		

			window.clear();
			lv.Draw(window);
			her.updateAndDrawHero(frameTime, mapObj, window);
			window.display();
			
		}

	
	
	return 0;
}
开发者ID:kychka,项目名称:sfml-game-test,代码行数:56,代码来源:Source.cpp

示例2:

	Bulet::Bullet(Image &image, String Name, Level &lvl,float X, float Y, int W, int H, int dir):Entity(image, Name, X, Y, W, H)//всё так же, только взяли в конце состояние игрока (int dir)
	{
		obj = lvl.GetObjects("solid");//инициализируем .получаем нужные объекты для взаимодействия пули с картой
		x = X;
		y = Y;
		direction = dir;
		speed = 0.8;
		w = h = 16;
		life = true;
	}//bullet
开发者ID:Sega88,项目名称:Sfmlgame,代码行数:10,代码来源:Bulet.cpp

示例3: StartGame

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)
//.........这里部分代码省略.........
开发者ID:Lokdemok,项目名称:Informatics-and-Programming,代码行数:101,代码来源:main.cpp

示例4: startGame

bool startGame (int & startLevel, RenderWindow & window, int & lives) {

    view.reset(FloatRect(0, 0, 700, 600));


    Level lvl;

    switch (startLevel) {
    case 1:
        lvl.LoadFromFile("level1.tmx");
        break;
    case 2:
        lvl.LoadFromFile("level2.tmx");
        break;
    case 3:
        lvl.LoadFromFile("level3.tmx");
        break;
    }
    //lvl.LoadFromFile("level1.tmx");

    SoundBuffer coinBuffer;
    coinBuffer.loadFromFile("sounds/coin.wav");
    Sound coinSound;
    coinSound.setBuffer(coinBuffer);
    SoundBuffer deathBuffer;
    deathBuffer.loadFromFile("sounds/mariodie.wav");
    Sound deathSound;
    deathSound.setBuffer(deathBuffer);
    SoundBuffer stageBuffer;
    stageBuffer.loadFromFile("sounds/stage.wav");
    Sound stageSound;
    stageSound.setBuffer(stageBuffer);

    Image heroImage;
    heroImage.loadFromFile("images/mario.png");
    heroImage.createMaskFromColor(Color(255, 255, 255));
    Image easyEnemyImage;
    easyEnemyImage.loadFromFile("images/EasyEnemy.png");
    easyEnemyImage.createMaskFromColor(Color(255, 255, 255));
    Image coinImage;
    coinImage.loadFromFile("images/coin.png");
    coinImage.createMaskFromColor(Color(255, 255, 255));
    Image mediumEnemyImage;
    mediumEnemyImage.loadFromFile("images/MediumEnemy.png");
    mediumEnemyImage.createMaskFromColor(Color(255, 255, 255));
    Image movePlatformImage;
    movePlatformImage.loadFromFile("images/MovingPlatform.png");

    std::list<Entity*> entities;
    std::list<Entity*>::iterator it;
    std::list<Entity*>::iterator it2;

    std::vector<Object> e = lvl.GetObjects("EasyEnemy");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Enemy(easyEnemyImage, "EasyEnemy", lvl, e[i].rect.left, e[i].rect.top, 15, 25));
    }
    e = lvl.GetObjects("coin");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Coin(coinImage, "coin", lvl, e[i].rect.left, e[i].rect.top, 15, 15));
    }
    e = lvl.GetObjects("MediumEnemy");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Enemy(mediumEnemyImage, "MediumEnemy", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("exit");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Exit(mediumEnemyImage, "exit", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("fire");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Fire(mediumEnemyImage, "fire", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("MovingPlatform");
    for (int i = 0; i < e.size(); i++)
        entities.push_back(new MovingPlatform(movePlatformImage, "MovingPlatform", lvl, e[i].rect.left, e[i].rect.top, 95, 22));

    Object player = lvl.GetObject("player");
    Player p(heroImage, "Player", lvl, player.rect.left, player.rect.top, 22, 38);

    Clock clock;

    while (window.isOpen())
    {

        float time = clock.getElapsedTime().asMicroseconds();

        clock.restart();
        time = time / 800;

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

        for (it = entities.begin(); it != entities.end();) {
            Entity *b = *it;
            b->update(time);
            if (b->life == false) {
//.........这里部分代码省略.........
开发者ID:SorochynskyiVladyslav,项目名称:CoursesRepository,代码行数:101,代码来源:main.cpp

示例5: RunGame

void RunGame()
{
	RenderWindow window(VideoMode(640, 480), "The Game!");
    menu(window);
	View view( FloatRect(0, 0, 450, 280) );

	Level lvl;
	int loadlevel = menu(window);


	//std::cout << "Which lvl would u prefer to load 1 or 2?\n";
	//std::cin >> loadlevel;

	switch(loadlevel){
    case 1:
        lvl.LoadFromFile("files/Level1.tmx");
        std::cout <<"\nLoaded lvl1";
        break;
    case 2:
        lvl.LoadFromFile("files/Level2.tmx");
        std::cout << "\nLoaded lvl2";
    default:
        system("exit");
        break;
	}


	Texture enemy_t, moveplatform_t, megaman_t, bullet_t, bg;
	bg.loadFromFile("files/images/bg.png");
	enemy_t.loadFromFile("files/images/enemy.png");
	moveplatform_t.loadFromFile("files/images/movingPlatform.png");
	megaman_t.loadFromFile("files/images/megaman.png");
	bullet_t.loadFromFile("files/images/bullet.png");


	AnimationManager anim;
	anim.loadFromXML("files/anim_megaman.xml",megaman_t);
	anim.animList["jump"].loop = 0;

	AnimationManager anim2;
	anim2.create("move",bullet_t,7,10,8,8,1,0);
	anim2.create("explode",bullet_t,27,7,18,18,4,0.01,29,false);

	AnimationManager anim3;
	anim3.create("move",enemy_t,0,0,16,16,2,0.002,18);
	anim3.create("dead",enemy_t,58,0,16,16,1,0);

	AnimationManager anim4;
	anim4.create("move",moveplatform_t,0,0,95,22,1,0);

    Sprite background(bg);
    background.setOrigin(bg.getSize().x/2,bg.getSize().y/2);

	std::list<Entity*>  entities;
	std::list<Entity*>::iterator it;

	std::vector<Object> e = lvl.GetObjects("enemy");
	for (int i=0;i < e.size();i++)
		entities.push_back(new ENEMY(anim3, lvl, e[i].rect.left, e[i].rect.top) );

	e = lvl.GetObjects("MovingPlatform");
	for (int i=0;i < e.size();i++)
		entities.push_back(new MovingPlatform(anim4, lvl, e[i].rect.left, e[i].rect.top) );

	Object pl = lvl.GetObject("player");
	PLAYER MegaMan(anim, lvl, pl.rect.left, pl.rect.top);

	HealthBar healthBar;

	Clock clock;
    int enemyCount = 0;
	/////////////////// основной цикл  /////////////////////
	while (window.isOpen())
	{



		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();

		time = time/500;  // здесь регулируем скорость игры

		if (time > 40) time = 40;

		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == Event::Closed || Keyboard::isKeyPressed(Keyboard::Escape))
				window.close();

			if (event.type == Event::KeyPressed)
				if (event.key.code==Keyboard::Space)
		        	entities.push_back(new Bullet(anim2,lvl,MegaMan.x+18,MegaMan.y+18,MegaMan.dir) );
		}


		if (Keyboard::isKeyPressed(Keyboard::Left)) MegaMan.key["L"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Right)) MegaMan.key["R"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Up)) MegaMan.key["Up"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Down)) MegaMan.key["Down"]=true;
//.........这里部分代码省略.........
开发者ID:lemeshkob,项目名称:Repo1,代码行数:101,代码来源:Game.hpp

示例6: RunGame

void RunGame()
{
	///////////// инициализация ///////////////////////////
	RenderWindow window(VideoMode(1366, 768), "The Game!", Style::Fullscreen);

	View view( FloatRect(0, 0, 450, 280) );

	Level lvl;
	lvl.LoadFromFile("files/Level2.tmx");

	Texture enemy_t, moveplatform_t, megaman_t, bullet_t, bg;
	bg.loadFromFile("files/images/bg.png");
	enemy_t.loadFromFile("files/images/enemy.png");
	moveplatform_t.loadFromFile("files/images/movingPlatform.png");
	megaman_t.loadFromFile("files/images/megaman.png");
	bullet_t.loadFromFile("files/images/bullet.png");


	AnimationManager anim;
	anim.loadFromXML("files/anim_megaman.xml",megaman_t);
	anim.animList["jump"].loop = 0;

	AnimationManager anim2;
	anim2.create("move",bullet_t,7,10,8,8,1,0);
	anim2.create("explode",bullet_t,27,7,18,18,4,0.01,29,false);

	AnimationManager anim3;
	anim3.create("move",enemy_t,0,0,16,16,2,0.002,18);
	anim3.create("dead",enemy_t,58,0,16,16,1,0);

	AnimationManager anim4;
	anim4.create("move",moveplatform_t,0,0,95,22,1,0);

    Sprite background(bg);
    background.setOrigin(bg.getSize().x/2,bg.getSize().y/2);

	std::list<Entity*>  entities;
	std::list<Entity*>::iterator it;

	std::vector<Object> e = lvl.GetObjects("enemy");
	for (int i=0;i < e.size();i++)
		entities.push_back(new ENEMY(anim3, lvl, e[i].rect.left, e[i].rect.top) );

	e = lvl.GetObjects("MovingPlatform");
	for (int i=0;i < e.size();i++)
		entities.push_back(new MovingPlatform(anim4, lvl, e[i].rect.left, e[i].rect.top) );

	Object pl = lvl.GetObject("player");
	PLAYER Mario(anim, lvl, pl.rect.left, pl.rect.top);

	HealthBar healthBar;

	Clock clock;

	/////////////////// основной цикл  /////////////////////
	while (window.isOpen())
	{
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();

		time = time/500;  // здесь регулируем скорость игры

		if (time > 40) time = 40;

		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == Event::Closed || Keyboard::isKeyPressed(Keyboard::Escape))
				window.close();

			if (event.type == Event::KeyPressed)
				if (event.key.code==Keyboard::Space)
		        	entities.push_back(new Bullet(anim2,lvl,Mario.x+18,Mario.y+18,Mario.dir) );
		}


		if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.key["L"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.key["R"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Up)) Mario.key["Up"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Down)) Mario.key["Down"]=true;
		if (Keyboard::isKeyPressed(Keyboard::Space)) Mario.key["Space"]=true;


		for(it=entities.begin();it!=entities.end();)
		{
			Entity *b = *it;
			b->update(time);
			if (b->life==false)	{ it  = entities.erase(it); delete b;}
			else it++;
		}


		Mario.update(time);
		healthBar.update(Mario.Health);


		for(it=entities.begin();it!=entities.end();it++)
		{
			//1. враги
			if ((*it)->Name=="Enemy")
//.........这里部分代码省略.........
开发者ID:lemeshkob,项目名称:Repo1,代码行数:101,代码来源:Game.hpp

示例7: main

int main()
{
	srand(time(NULL));

	Level lvl;
    lvl.LoadFromFile("/home/oawad/Downloads/sfml/platformer/platformer.tmx");


    b2Vec2 gravity(0.0f, 1.0f);
    b2World world(gravity);

	sf::Vector2i tileSize = lvl.GetTileSize();

	std::vector<Object> block = lvl.GetObjects("block");
	for(int i = 0; i < block.size(); i++)
	{
		b2BodyDef bodyDef;
		bodyDef.type = b2_staticBody;
		bodyDef.position.Set(block[i].rect.left + tileSize.x / 2 * (block[i].rect.width / tileSize.x - 1),
			block[i].rect.top + tileSize.y / 2 * (block[i].rect.height / tileSize.y - 1));
		b2Body* body = world.CreateBody(&bodyDef);
		b2PolygonShape shape;
		shape.SetAsBox(block[i].rect.width / 2, block[i].rect.height / 2);
		body->CreateFixture(&shape,1.0f);
	}

	coin = lvl.GetObjects("coin");
	for(int i = 0; i < coin.size(); i++)
	{
		b2BodyDef bodyDef;
		bodyDef.type = b2_dynamicBody;
		bodyDef.position.Set(coin[i].rect.left + tileSize.x / 2 * (coin[i].rect.width / tileSize.x - 1),
			coin[i].rect.top + tileSize.y / 2 * (coin[i].rect.height / tileSize.y - 1));
		bodyDef.fixedRotation = true;
		b2Body* body = world.CreateBody(&bodyDef);
		b2PolygonShape shape;
		shape.SetAsBox(coin[i].rect.width / 2, coin[i].rect.height / 2);
		body->CreateFixture(&shape,1.0f);
		coinBody.push_back(body);
	}

	enemy = lvl.GetObjects("enemy");
	for(int i = 0; i < enemy.size(); i++)
	{
		b2BodyDef bodyDef;
		bodyDef.type = b2_dynamicBody;
		bodyDef.position.Set(enemy[i].rect.left +
			tileSize.x / 2 * (enemy[i].rect.width / tileSize.x - 1),
			enemy[i].rect.top + tileSize.y / 2 * (enemy[i].rect.height / tileSize.y - 1));
		bodyDef.fixedRotation = true;
		b2Body* body = world.CreateBody(&bodyDef);
		b2PolygonShape shape;
		shape.SetAsBox(enemy[i].rect.width / 2, enemy[i].rect.height / 2);
		body->CreateFixture(&shape,1.0f);
		enemyBody.push_back(body);
	}


	player = lvl.GetObject("player");
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	bodyDef.position.Set(player.rect.left, player.rect.top);
	bodyDef.fixedRotation = true;
	playerBody = world.CreateBody(&bodyDef);
	b2PolygonShape shape; shape.SetAsBox(player.rect.width / 2, player.rect.height / 2);
	b2FixtureDef fixtureDef;
	fixtureDef.shape = &shape;
	fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f;
	playerBody->CreateFixture(&fixtureDef);



	sf::Vector2i screenSize(800, 600);

	sf::RenderWindow window;
	window.create(sf::VideoMode(screenSize.x, screenSize.y), "Game");


	sf::View view;
	view.reset(sf::FloatRect(0.0f, 0.0f, screenSize.x, screenSize.y));
	view.setViewport(sf::FloatRect(0.0f, 0.0f, 2.0f, 2.0f));

    while(window.isOpen())
    {
        sf::Event evt;

        while(window.pollEvent(evt))
        {
			switch(evt.type)
			{
			case sf::Event::Closed:
                window.close();
				break;

			case sf::Event::KeyPressed:
				if(evt.key.code == sf::Keyboard::W && playerBody->GetLinearVelocity().y == 0)
					playerBody->SetLinearVelocity(b2Vec2(0.0f, -15.0f));

				if(evt.key.code == sf::Keyboard::D)
					playerBody->SetLinearVelocity(b2Vec2(5.0f, 0.0f));
//.........这里部分代码省略.........
开发者ID:oawad79,项目名称:RussianSFML,代码行数:101,代码来源:main.cpp


注:本文中的Level::GetObjects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。