本文整理汇总了C++中Music::play方法的典型用法代码示例。如果您正苦于以下问题:C++ Music::play方法的具体用法?C++ Music::play怎么用?C++ Music::play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Music
的用法示例。
在下文中一共展示了Music::play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void operator ()()
{
while (Flc::flc.FrameCount >= introSoundTrack[trackPosition].frameNumber)
{
int command = introSoundTrack[trackPosition].sound;
if (command & 0x200)
{
#ifndef __NO_MUSIC
switch(command)
{
case 0x200:
Log(LOG_DEBUG) << "Playing gmintro1";
m = rp->getMusic("GMINTRO1");
m->play(1);
break;
case 0x201:
Log(LOG_DEBUG) << "Playing gmintro2";
m = rp->getMusic("GMINTRO2");
m->play(1);
break;
case 0x202:
Log(LOG_DEBUG) << "Playing gmintro3";
m = rp->getMusic("GMINTRO3");
m->play(1);
Mix_HookMusicFinished(musicDone);
break;
}
#endif
}
else if (command & 0x400)
{
Flc::flc.HeaderSpeed = (1000.0/70.0) * (command & 0xff);
Log(LOG_DEBUG) << "Frame delay now: " << Flc::flc.HeaderSpeed;
}
else if (command <= 0x19)
{
for (soundInFile **sounds = introSounds; *sounds; ++sounds) // try hybrid sound set, then intro.cat or sample3.cat alone
{
soundInFile *sf = (*sounds) + command;
int channel = trackPosition % 4; // use at most four channels to play sound effects
Log(LOG_DEBUG) << "playing: " << sf->catFile << ":" << sf->sound << " for index " << command;
s = rp->getSound(sf->catFile, sf->sound);
if (s)
{
s->play(channel);
Mix_Volume(channel, sf->volume);
break;
}
else Log(LOG_DEBUG) << "Couldn't play " << sf->catFile << ":" << sf->sound;
}
}
++trackPosition;
}
}
示例2: operator
void operator()()
{
while (_flcPlayer->getFrameCount() >= introSoundTrack[trackPosition].frameNumber)
{
int command = introSoundTrack[trackPosition].sound;
if (command & 0x200)
{
#ifndef __NO_MUSIC
switch(command)
{
case 0x200:
Log(LOG_DEBUG) << "Playing gmintro1";
m = mod->getMusic("GMINTRO1");
m->play(1);
break;
case 0x201:
Log(LOG_DEBUG) << "Playing gmintro2";
m = mod->getMusic("GMINTRO2");
m->play(1);
break;
case 0x202:
Log(LOG_DEBUG) << "Playing gmintro3";
m = mod->getMusic("GMINTRO3");
m->play(1);
//Mix_HookMusicFinished(_FlcPlayer::stop);
break;
}
#endif
}
else if (command & 0x400)
{
int newSpeed = (command & 0xff);
_flcPlayer->setHeaderSpeed(newSpeed);
Log(LOG_DEBUG) << "Frame delay now: " << newSpeed;
}
else if (command <= 0x19)
{
for (soundInFile **sounds = introSounds; *sounds; ++sounds) // try hybrid sound set, then intro.cat or sample3.cat alone
{
soundInFile *sf = (*sounds) + command;
int channel = trackPosition % 4; // use at most four channels to play sound effects
double ratio = (double)Options::soundVolume / MIX_MAX_VOLUME;
Log(LOG_DEBUG) << "playing: " << sf->catFile << ":" << sf->sound << " for index " << command;
s = mod->getSound(sf->catFile, sf->sound, false);
if (s)
{
s->play(channel);
Mix_Volume(channel, sf->volume * ratio);
break;
}
else Log(LOG_DEBUG) << "Couldn't play " << sf->catFile << ":" << sf->sound;
}
}
++trackPosition;
}
}
示例3: cargaCosas
void cargaCosas(){
music.openFromFile("Song5.ogg");
buffer.loadFromFile("canon.wav");
sound.setBuffer(buffer);
music.setLoop(true);
music.play();
}
示例4: finish
void finish()
{
RenderWindow window(VideoMode(500,500),"", Style::None);
Texture text;
text.loadFromFile("images/finish.png");
Sprite finish; finish.setTexture(text);
Music music;
music.openFromFile("music/finish.ogg");
music.play();
while(window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if(IntRect(420,461,57,36).contains(Mouse::getPosition(window)))
{
if(Mouse::isButtonPressed(Mouse::Left))
{
music.stop();
window.close();
}
}
}
window.clear();
window.draw(finish);
window.display();
}
}
示例5: menu
void menu(RenderWindow & window, Music &musicInMenu)
{
init_texture textu;
bool kek = false;
musicInMenu.play();
bool isMenu = 1;
int menuNum = 0;
while (isMenu)
{
textu.menu1.setColor(Color::White);
textu.menu2.setColor(Color::White);
textu.menu3.setColor(Color::White);
menuNum = 0;
window.clear(Color(129, 181, 221));
if (IntRect(100, 30, 300, 50).contains(Mouse::getPosition(window))) { textu.menu1.setColor(Color::Blue); menuNum = 1; }
if (IntRect(100, 90, 300, 50).contains(Mouse::getPosition(window))) { textu.menu3.setColor(Color::Blue); menuNum = 3; }
if (IntRect(100, 150, 300, 50).contains(Mouse::getPosition(window))) { textu.menu2.setColor(Color::Blue); menuNum = 2; }
window.draw(textu.menuBg);
window.draw(textu.menu1);
window.draw(textu.menu2);
window.draw(textu.menu3);
if (kek) { window.draw(textu.training); if (IntRect(1200, 90, 50, 50).contains(Mouse::getPosition(window)) && Mouse::isButtonPressed(Mouse::Left)) { kek = false; } }
if (Mouse::isButtonPressed(Mouse::Left))
{
if (menuNum == 1) isMenu = false;
if (menuNum == 2) { window.close(); isMenu = false; }
if (menuNum == 3) { kek = true; }
}
window.display();
}
}
示例6: main
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();
}
}
示例7: menu
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();
}
}
示例8: menu
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();
}
示例9: menu
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();
//.........这里部分代码省略.........
示例10: gra
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));
//.........这里部分代码省略.........
示例11: onStart
void HelpScreen::onStart() {
Music *music = (Music*) ResourcesManager::getResource("MenuMusic");
music->play(1000);
userInterface->startFadeIn(200);
}
示例12: main
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;
}
//.........这里部分代码省略.........
示例13: 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);
//.........这里部分代码省略.........
示例14: main
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);
//.........这里部分代码省略.........
示例15: playSettings
void MasterClass::playSettings()
{
Vector2u window_size = window->getSize();
Image img = window->capture();
Texture texture;
//texture.loadFromImage(img);
texture.loadFromFile("res/tex/decor/settings_menu.png");
Vector2u texture_size = texture.getSize();
Sprite sprite(texture);
// 0 -> pas transparent et 255 -> transparent
//sprite.setColor(sf::Color(255, 255, 255, 128));
sprite.scale((float)window_size.x/texture_size.x, (float)window_size.y/texture_size.y);
View view = window->getView();
sprite.setPosition(view.getCenter().x - (float)window_size.x/2, 0);
Font font;
font.loadFromFile("res/font/arcade.ttf");
vector<String> vectItems;
vectItems.push_back("Reprendre");
const int resume = 0;
vectItems.push_back("<- Volume musique +>");
const int musicsVolume = 1;
vectItems.push_back("<- Volume bruitages +>");
const int soundEffectsVolume = 2;
vectItems.push_back("Menu principal");
const int mainMenu = 3;
Menu menu(vectItems, window, font, Menu::CENTER, (unsigned int)window_size.y*0.0444);
SoundBuffer buffer;
Sound s;
buffer.loadFromFile("res/snd/enemy/rebel/death1.wav");
s.setBuffer(buffer);
Music music;
music.openFromFile("res/snd/level/The_Military_System.wav");
music.setVolume(config.musicsVolume);
music.setLoop(true);
music.play();
while (window->isOpen() && state == SETTINGS)
{
sf::Event event;
while(window->pollEvent(event))
{
if (event.type == Event::KeyPressed)
{
switch(event.key.code)
{
case Keyboard::Escape :
state = previousState;
break;
case Keyboard::Up :
menu.moveUp();
break;
case Keyboard::Down :
menu.moveDown();
break;
case Keyboard::Return :
switch(menu.getSelectedItemIndex())
{
case resume :
state = previousState;
break;
case mainMenu :
previousState = state;
state = MAINMENU;
break;
default :
break;
}
break;
case Keyboard::Left :
switch(menu.getSelectedItemIndex())
{
case musicsVolume :
config.musicsVolume -= 10;
if(config.musicsVolume < 0)
config.musicsVolume = 0;
music.setVolume(config.musicsVolume);
break;
case soundEffectsVolume :
config.soundEffectsVolume -= 10;
if(config.soundEffectsVolume < 0)
config.soundEffectsVolume = 0;
s.setVolume(config.soundEffectsVolume);
s.play();
break;
default :
break;
}
break;
//.........这里部分代码省略.........