本文整理汇总了C++中Level::GetObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::GetObject方法的具体用法?C++ Level::GetObject怎么用?C++ Level::GetObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level::GetObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start_game
bool start_game(int &levelNumber, RenderWindow &window)
{
init_sounds sound;
init_texture texture;
Level lvl;
change_level(lvl, levelNumber);
if (levelNumber == 1 && !wasInMenu)
{
wasInMenu = true; menu(window, sound.musicInMenu);
}
sound.musicInMenu.stop();
std::list<Entity*> entities;
std::list<Entity*>::iterator it;
std::vector<Object> e;
init_map_objects(e, entities, lvl, enemiesNumber, texture);
Object pl = lvl.GetObject("player");
PLAYER Player(texture.anim_player, lvl, float(pl.rect.left), float(pl.rect.top));
Clock clock;
return playing(window, clock, Player, it, entities, lvl, levelNumber);
}
示例2: 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)
//.........这里部分代码省略.........
示例3: 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) {
//.........这里部分代码省略.........
示例4: 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;
//.........这里部分代码省略.........
示例5: mainLevel
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);
//.........这里部分代码省略.........
示例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")
//.........这里部分代码省略.........
示例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));
//.........这里部分代码省略.........