SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › Текст над врагами
В этой теме 3 ответа, 3 участника, последнее обновление Vladdd 7 года/лет, 10 мес. назад.
Просмотр 4 сообщений - с 1 по 4 (из 4 всего)
-
АвторСообщения
-
Подскажите как реализовать текст над врагами, над каждым только.
а то получалось что у них общий текст был(Можно в класс Enemy добавить поле с текстом и отрисовывать этот текст в цикле отрисовки врагов
над каждым – работа в классе. либо класс текста какой то, который будет принимать список врагов и там уже реализовать
C++123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741#include <SFML/Graphics.hpp>#include <SFML/Audio.hpp>#include "SFML/Audio/Music.hpp"#include "SFML/Audio/Listener.hpp"#include <ctime>#include "character.h"#include <sstream>#include "HUD.h"#include "menu.h"static View view;void setPlayerCoordinateForView(float x, float y, View &view) { //функция для считывания координат игрокаfloat tempX; float tempY;//считываем коорд игрока и проверяем их, чтобы убрать краяtempX = x;tempY = y;if (tempX < 684) tempX = 684;//убираем из вида левую сторонуif (tempX > 2462) tempX = 2462;//убираем из вида левую сторонуif (tempY < 400) tempY = 400;//верхнюю сторонуif (tempY > 768) tempY = 768;//нижнюю сторонуview.setCenter(tempX, tempY); //следим за игроком, передавая его координаты.}bool startGame(){RenderWindow window(VideoMode(1366, 768), "Game", Style::Fullscreen);view.reset(FloatRect(0, 0, 1366, 768));int VisibleDistX = 683;int VisibleDistY = 384;float timerEnd = 0;menu(window);//вызов меню////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Звук Игры //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////SoundBuffer bufferPS, bufferC, bufferSI, bufferTI, bufferES, bufferPH, bufferBE, bufferSH, bufferPJ, bufferPD, bufferAS, bufferB, bufferPAH, bufferEL;bufferPS.loadFromFile("C:/VSS/projects/Game/Game/Sound/PShoot.ogg");// тут загружаем в буфер что тоbufferC.loadFromFile("C:/VSS/projects/Game/Game/Sound/Coin.ogg");bufferSI.loadFromFile("C:/VSS/projects/Game/Game/Sound/SelectItem.ogg");bufferTI.loadFromFile("C:/VSS/projects/Game/Game/Sound/TakeItem.ogg");bufferES.loadFromFile("C:/VSS/projects/Game/Game/Sound/EShoot.ogg");bufferPH.loadFromFile("C:/VSS/projects/Game/Game/Sound/PHit.ogg");bufferBE.loadFromFile("C:/VSS/projects/Game/Game/Sound/BoxExplode.ogg");bufferSH.loadFromFile("C:/VSS/projects/Game/Game/Sound/SHit.ogg");bufferPJ.loadFromFile("C:/VSS/projects/Game/Game/Sound/PJump.ogg");bufferPD.loadFromFile("C:/VSS/projects/Game/Game/Sound/PDead.ogg");bufferAS.loadFromFile("C:/VSS/projects/Game/Game/Sound/ArrowShoot.ogg");bufferPAH.loadFromFile("C:/VSS/projects/Game/Game/Sound/PArrowHit.ogg");bufferEL.loadFromFile("C:/VSS/projects/Game/Game/Sound/EndLvl.ogg");Sound soundPlayerShoot, soundCoin, soundSelectItem,soundTakeItem, soundEnemyShoot, soundPlayerHit,soundBoxExplode, soundShieldHit, soundPlayerJump,soundPlayerDead, soundPlayerArrowHit, soundArrowShoot, soundEndLevel;soundPlayerShoot.setBuffer(bufferPS);soundCoin.setBuffer(bufferC);soundSelectItem.setBuffer(bufferSI);soundTakeItem.setBuffer(bufferTI);soundEnemyShoot.setBuffer(bufferES);soundPlayerHit.setBuffer(bufferPH);soundBoxExplode.setBuffer(bufferBE);soundShieldHit.setBuffer(bufferSH);soundPlayerJump.setBuffer(bufferPJ);soundPlayerDead.setBuffer(bufferPD);soundPlayerArrowHit.setBuffer(bufferPAH);soundArrowShoot.setBuffer(bufferAS);soundEndLevel.setBuffer(bufferEL);soundCoin.setVolume(25);soundPlayerJump.setVolume(25);soundEnemyShoot.setVolume(50);soundShieldHit.setVolume(70);soundPlayerHit.setVolume(50);soundTakeItem.setVolume(50);Music music;//создаем объект музыкиmusic.openFromFile("C:/VSS/projects/Game/Game/Sound/Sound3.ogg");//загружаем файлmusic.setVolume(45);////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Текст Игры /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Font fontInterface, fontMission;fontInterface.loadFromFile("C:/VSS/projects/Game/Game/Shrift/a_LCDNovaObl.ttf");fontMission.loadFromFile("C:/VSS/projects/Game/Game/Shrift/a_LCDNovaObl.ttf");Text MISSIONCOINS("", fontMission, 16), MISSIONENEMY("", fontMission, 16), MISSIONLVL("", fontMission, 16);MISSIONCOINS.setColor(Color::Yellow);MISSIONENEMY.setColor(Color::Yellow);MISSIONLVL.setColor(Color::Yellow);Text HEALTH("", fontInterface, 14), BULLETS("", fontInterface, 16), COINS("", fontInterface, 16), MEDIC("", fontInterface, 16);HEALTH.setColor(Color::Black);BULLETS.setColor(Color::White);COINS.setColor(Color::White);MEDIC.setColor(Color::White);LifeBar HUD_interface;Level lvl; // создали экземпляр класса уровеньlvl.LoadFromFile("C:/VSS/projects/Game/Game/MapGame.tmx");Object player = lvl.GetObject("player");//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Загрузка анимаций и картинок /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Image backGround_i, HUD_i, GameOver_i, q_i, q_i1, q_i2, EndGame_i;EndGame_i.loadFromFile("C:/VSS/projects/Game/Game/Images/End.png");q_i2.loadFromFile("C:/VSS/projects/Game/Game/Images/Enemies.png");q_i2.createMaskFromColor(Color(255, 255, 255));q_i1.loadFromFile("C:/VSS/projects/Game/Game/Images/CoinsEnemy.png");q_i1.createMaskFromColor(Color(255, 255, 255));q_i.loadFromFile("C:/VSS/projects/Game/Game/Images/Player.png");q_i.createMaskFromColor(Color(255, 255, 255));backGround_i.loadFromFile("C:/VSS/projects/Game/Game/Images/bg.png");HUD_i.loadFromFile("C:/VSS/projects/Game/Game/Images/HUD_i.png");GameOver_i.loadFromFile("C:/VSS/projects/Game/Game/Images/GO.jpg");HUD_i.createMaskFromColor(Color(255, 255, 255));Texture backGround_t, HUD_t, GameOver_t, q, q1, q2, EndGame_t;EndGame_t.loadFromImage(EndGame_i);q2.loadFromImage(q_i2);q1.loadFromImage(q_i1);q.loadFromImage(q_i);backGround_t.loadFromImage(backGround_i);HUD_t.loadFromImage(HUD_i);GameOver_t.loadFromImage(GameOver_i);Sprite backGround, HUD, GameOver, EndGame;EndGame.setTexture(EndGame_t);backGround.setTexture(backGround_t);HUD.setTexture(HUD_t);GameOver.setTexture(GameOver_t);AnimationManager anim_Player, anim_Enemies, anim_Coins, anim_Bullets, anim_Enemy_Bullets, anim_ArrowsButtons, anim_Shield;anim_Shield.loadFromXML("C:/VSS/projects/Game/Game/Animations/Coin.tmx", q1);anim_ArrowsButtons.loadFromXML("C:/VSS/projects/Game/Game/Animations/ArrowButton.tmx", q2);anim_Enemy_Bullets.loadFromXML("C:/VSS/projects/Game/Game/Animations/EnemyBullet.tmx", q2);anim_Bullets.loadFromXML("C:/VSS/projects/Game/Game/Animations/Bullet.tmx", q);anim_Coins.loadFromXML("C:/VSS/projects/Game/Game/Animations/Coin.tmx", q1);anim_Enemies.loadFromXML("C:/VSS/projects/Game/Game/Animations/EnemyEagle.tmx", q2);anim_Player.loadFromXML("C:/VSS/projects/Game/Game/Animations/Player.tmx", q);Player p(anim_Player, lvl, player.rect.left, player.rect.top);list<Entity*> entities; // создаю список, сюда буду кидать объекты.например врагов.list<Entity*>::iterator it; // итератор чтобы проходить по эл-там списка////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Заносим объекты в вектор ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////vector<Object>enemyEagle, coinY, coinB, bullets, healthpoints, buttons, arrowbases, shields;enemyEagle = lvl.GetObjects("EnemyEagle");for (int i = 0; i < enemyEagle.size(); i++) {//проходимся по элементам этого вектора(а именно по врагам)entities.push_back(new Enemy("EnemyEagle", anim_Enemies, lvl, enemyEagle[i].rect.left, enemyEagle[i].rect.top));enemyEagle[i].rect.left;//коорд XenemyEagle[i].rect.top;//коорд Yp.enemyScore++;}coinY = lvl.GetObjects("coinY");for (int i = 0; i < coinY.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("CoinY", anim_Coins, lvl, coinY[i].rect.left, coinY[i].rect.top));coinY[i].rect.left;//коорд XcoinY[i].rect.top;//коорд Y}coinB = lvl.GetObjects("coinG");for (int i = 0; i < coinB.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("CoinG", anim_Coins, lvl, coinB[i].rect.left, coinB[i].rect.top));coinB[i].rect.left;//коорд XcoinB[i].rect.top;//коорд Y}bullets = lvl.GetObjects("bullets");for (int i = 0; i < bullets.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("Bullets", anim_Coins, lvl, bullets[i].rect.left, bullets[i].rect.top));bullets[i].rect.left;//коорд Xbullets[i].rect.top;//коорд Y}healthpoints = lvl.GetObjects("healthpoint");for (int i = 0; i < healthpoints.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("HealthPoint", anim_Coins, lvl, healthpoints[i].rect.left, healthpoints[i].rect.top));healthpoints[i].rect.left;//коорд Xhealthpoints[i].rect.top;//коорд Y}buttons = lvl.GetObjects("button");for (int i = 0; i < buttons.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("Button", anim_ArrowsButtons, lvl, buttons[i].rect.left, buttons[i].rect.top));buttons[i].rect.left;//коорд Xbuttons[i].rect.top;//коорд Y}arrowbases = lvl.GetObjects("arrowbase");for (int i = 0; i < arrowbases.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("ArrowBase", anim_ArrowsButtons, lvl, arrowbases[i].rect.left, arrowbases[i].rect.top));arrowbases[i].rect.left;//коорд Xarrowbases[i].rect.top;//коорд Y}shields = lvl.GetObjects("shield");for (int i = 0; i < shields.size(); i++)//проходимся по элементам этого вектора(а именно по врагам){entities.push_back(new Bonus("Shield", anim_Shield, lvl, shields[i].rect.left, shields[i].rect.top));shields[i].rect.left;//коорд Xshields[i].rect.top;//коорд Y}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Основной цикл //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Clock clock;while (window.isOpen()){Event event;float time = clock.getElapsedTime().asMicroseconds();clock.restart();time = time / 800;while (window.pollEvent(event)){if (event.type == Event::Closed){window.close();cout << "Завершение программы..." << endl;}if (event.type == sf::Event::MouseButtonPressed){if (event.key.code == sf::Mouse::Left && (p.state == p.stay) && (p.bulletScore != 0) && !(p.block) && (p.life) && !p.EndLevel){entities.push_back(new Bullet("Bullet", anim_Bullets, lvl, p.x, p.y + 4, p.dir));p.bulletScore--;soundPlayerShoot.play();}}if (event.type == sf::Event::KeyPressed){if (event.key.code == sf::Keyboard::L && (p.medicScore != 0) && p.life && !p.EndLevel){soundSelectItem.play();p.health += 30;p.medicScore--;}}if (event.type == sf::Event::KeyPressed){if (event.key.code == sf::Keyboard::M){music.play();music.setLoop(true);}}if (event.type == sf::Event::KeyPressed){if (event.key.code == sf::Keyboard::N){music.stop();}}if (event.type == sf::Event::KeyPressed){if (event.key.code == sf::Keyboard::Space && (p.onGround) && p.life && p.state != p.climb && !p.EndLevel){soundPlayerJump.play();}}if (event.type == sf::Event::KeyPressed){if (event.key.code == sf::Keyboard::T && (p.Exit) && p.enemyScore == 0 && p.playerScore == 150){p.EndLevel = true;soundEndLevel.play();music.stop();}}}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Restart of game ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////if (Keyboard::isKeyPressed(Keyboard::F8)){return true;}if (Keyboard::isKeyPressed(Keyboard::Escape)){return false;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Update для всех ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////view.setCenter(p.x, p.y);p.update(time);setPlayerCoordinateForView(p.x, p.y, view);for (it = entities.begin(); it != entities.end(); it++){//1. монеты, патроны, аптечка, щит.if ((*it)->Name == "Shield"){Entity *shield = *it;if (shield->health > 0)if (p.getRect().intersects(shield->getRect())){p.isShield = true;p.shieldHealth = 100;shield->life = false;soundTakeItem.play();}}if ((*it)->Name == "CoinY"){Entity *coinY = *it;if (coinY->health > 0)if (p.getRect().intersects(coinY->getRect())){p.playerScore += 2;coinY->life = false;soundCoin.play();}}if ((*it)->Name == "CoinG"){Entity *coinG = *it;if (coinG->health > 0)if (p.getRect().intersects(coinG->getRect())){p.playerScore++;coinG->life = false;soundCoin.play();}}if ((*it)->Name == "Bullets"){Entity *bullets = *it;if (bullets->health > 0)if (p.getRect().intersects(bullets->getRect())){p.bulletScore += 15;bullets->life = false;soundTakeItem.play();}}if ((*it)->Name == "HealthPoint"){Entity *hp = *it;if (hp->health > 0)if (p.getRect().intersects(hp->getRect())){p.medicScore++;hp->life = false;soundTakeItem.play();}}//2. врагиif ((*it)->Name == "EnemyEagle"){if ((*it)->x < p.x + 400 && (*it)->x > p.x - 400) {if ((*it)->y < p.y + 150 && (*it)->y > p.y - 150) {Entity *enemy = *it;if ((*it)->health <= 0) continue;if (p.health > 0){if (p.getRect().intersects(enemy->getRect())){if ((p.dy > 0) && (p.onGround == false)){p.dy = -0.5;enemy->dx = 0;enemy->health = 0;p.enemyScore--;if (p.health <= 0 || !p.life){soundPlayerDead.play();}}if (p.dx < 0 && p.onGround) // Если игрок идет влево{if (!p.hit){p.health -= 50;soundPlayerHit.play();}enemy->health = 0;p.hit = true;p.enemyScore--;if (p.health <= 0 || !p.life){soundPlayerDead.play();}}if (p.dx > 0 && p.onGround) // Если игрок идет вправо{if (!p.hit){p.health -= 50;soundPlayerHit.play();}enemy->health = 0;p.hit = true;p.enemyScore--;if (p.health <= 0 || !p.life){soundPlayerDead.play();}}}if (p.getRect().intersects(enemy->getEnemyview())){if (enemy->dx > 0){enemy->dx = 0;enemy->shoot = true;enemy->detection = true;}if (enemy->dx < 0){enemy->dx = 0;enemy->shoot = true;enemy->detection = true;}}if (!(p.getRect().intersects(enemy->getEnemyview()))){if (enemy->dx == 0 && enemy->dir == 1){enemy->dx = -0.05;enemy->shoot = false;}if (enemy->dx == 0 && enemy->dir == 0){enemy->dx = 0.05;enemy->shoot = false;}}if (enemy->isShoot == true){entities.push_back(new Bullet("EBullet", anim_Enemy_Bullets, lvl, enemy->x + 12, enemy->y + 6, enemy->dir));soundEnemyShoot.play();enemy->isShoot = false;}//3. пулиfor (list<Entity*>::iterator it2 = entities.begin(); it2 != entities.end(); it2++){Entity *bullet = *it2;if (bullet->Name == "Bullet"){if (bullet->health > 0){if (enemy->getRect().intersects(bullet->getRect())){if (bullet->dx > 0){if (enemy->dx > 0) { enemy->dir = 1; enemy->dx = -0.05; }bullet->x = enemy->x - bullet->w;bullet->dx = 0;bullet->health = 0;enemy->health -= 10;if (enemy->health <= 0){p.enemyScore--;}}if (bullet->dx < 0){if (enemy->dx < 0) { enemy->dir = 0; enemy->dx = 0.05; }bullet->x = enemy->x + enemy->w;bullet->dx = 0;bullet->health = 0;enemy->health -= 10;if (enemy->health <= 0){p.enemyScore--;}}}}}Entity *enemybullet = *it2;if (enemybullet->Name == "EBullet"){if (enemybullet->health > 0){if (enemybullet->getRect().intersects(p.getRect()) && !p.block){if (enemybullet->dx > 0){enemybullet->x = p.x - enemybullet->w + 10;enemybullet->dx = 0;enemybullet->health = 0;p.health -= 35;p.hit = true;soundPlayerHit.play();if (p.health <= 0 || !p.life){if (enemy->dir == 0) { enemy->dx = 0.05; }if (enemy->dir == 1) { enemy->dx = -0.05; }enemy->isShoot = false;enemy->shoot = false;enemy->detection = false;p.dx = 0;soundPlayerDead.play();music.stop();}}if (enemybullet->dx < 0){enemybullet->x = p.x + p.w - 10;enemybullet->dx = 0;enemybullet->health = 0;p.health -= 35;p.hit = true;soundPlayerHit.play();if (p.health <= 0 || !p.life){if (enemy->dir == 0) { enemy->dx = 0.05; }if (enemy->dir == 1) { enemy->dx = -0.05; }enemy->isShoot = false;enemy->shoot = false;enemy->detection = false;p.dx = 0;soundPlayerDead.play();music.stop();}}}if (enemybullet->getRect().intersects(p.getRect()) && p.block){if (enemybullet->dx > 0){enemybullet->x = p.x - enemybullet->w + 10;enemybullet->dx = 0;enemybullet->health = 0;p.shieldHealth -= 20;soundShieldHit.play();}if (enemybullet->dx < 0){enemybullet->x = p.x + p.w - 10;enemybullet->dx = 0;enemybullet->health = 0;p.shieldHealth -= 20;soundShieldHit.play();}}}}}}}}}// 4. Кнопкаif ((*it)->Name == "Button"){if ((*it)->x < p.x + 400 && (*it)->x > p.x - 400) {if ((*it)->y < p.y + 150 && (*it)->y > p.y - 150) {if (p.getRect().intersects((*it)->getRect())){(*it)->onButton = true;(*it)->ArrowShoot = false;}if (!(p.getRect().intersects((*it)->getRect()))){(*it)->onButton = false;}}}}if ((*it)->ArrowShoot){for (list<Entity*>::iterator it3 = entities.begin(); it3 != entities.end(); it3++){Entity *base = *it3;if (base->Name == "ArrowBase"){entities.push_back(new Bullet("Arrow", anim_ArrowsButtons, lvl, base->x, base->y, base->dir));soundArrowShoot.play();}}}if ((*it)->Name == "Arrow"){if ((*it)->x < p.x + 400 && (*it)->x > p.x - 400) {if ((*it)->y < p.y + 150 && (*it)->y > p.y - 150) {Entity *arrow = *it;if (p.life == true || p.health > 0){if (arrow->getRect().intersects(p.getRect()) && p.block){if (arrow->dx > 0 && p.block){arrow->x = p.x - arrow->w;p.shieldHealth -= 30;arrow->dx = 0;arrow->health = 0;}}if (arrow->getRect().intersects(p.getRect()) && !p.block){if (arrow->dx > 0 && !p.block){soundPlayerArrowHit.play();arrow->x = p.x - arrow->w;arrow->dx = 0;arrow->health = 0;p.health -= 30;if (p.health <= 0 || !p.life){p.dx = 0;soundPlayerDead.play();}}}}}}}}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Проверка на жизнь объекта //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////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++;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Отрисовка объектов /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////window.setView(view);window.clear(Color(4, 128, 202));HUD_interface.update(p.health, p.shieldHealth);window.draw(backGround);lvl.Draw(window);for (it = entities.begin(); it != entities.end(); it++){(*it)->draw(window);if ((*it)->Name == "EnemyEagle"){(*it)->drawEnemyhealthBar(window);(*it)->updatehealthBar((*it)->health);}}p.draw(window);HUD_interface.draw(window);////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Text of HUD ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ostringstream playerHealth, playerScore, bulletScore, medicScore, enemyScore;playerHealth << p.health;playerScore << p.playerScore;bulletScore << p.bulletScore;medicScore << p.medicScore;enemyScore << p.enemyScore;MISSIONCOINS.setString("Соберите все \n\nмонеты: 150 шт.");MISSIONCOINS.setPosition(view.getCenter().x + 530, view.getCenter().y + 241);window.draw(MISSIONCOINS);if (p.playerScore == 150) { MISSIONCOINS.setColor(Color::Green); }if (p.playerScore != 150) { MISSIONCOINS.setColor(Color::Yellow); }MISSIONENEMY.setString("Убейте всех врагов \n\nна карте. ");MISSIONENEMY.setPosition(view.getCenter().x + 530, view.getCenter().y + 295);window.draw(MISSIONENEMY);if (p.enemyScore == 0) { MISSIONENEMY.setColor(Color::Green); }if (p.enemyScore != 0) { MISSIONENEMY.setColor(Color::Yellow); }MISSIONLVL.setString("Найдите выход.");MISSIONLVL.setPosition(view.getCenter().x + 530, view.getCenter().y + 350);window.draw(MISSIONLVL);if (p.Exit) { MISSIONLVL.setColor(Color::Green); }if (!p.Exit) { MISSIONLVL.setColor(Color::Yellow); }HEALTH.setString(playerHealth.str() + "/100");HEALTH.setPosition(view.getCenter().x - 646, view.getCenter().y + 233);window.draw(HEALTH);COINS.setString(playerScore.str());COINS.setPosition(view.getCenter().x + 476, view.getCenter().y + 344);window.draw(COINS);BULLETS.setString(bulletScore.str());BULLETS.setPosition(view.getCenter().x + 476, view.getCenter().y + 317);window.draw(BULLETS);if (p.bulletScore == 0) { BULLETS.setColor(Color::Red); }if (p.bulletScore != 0) { BULLETS.setColor(Color::White); }MEDIC.setString(medicScore.str());MEDIC.setPosition(view.getCenter().x + 476, view.getCenter().y + 290);window.draw(MEDIC);if (p.medicScore == 0) { MEDIC.setColor(Color::Red); }if (p.medicScore != 0) { MEDIC.setColor(Color::White); }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// End text of HUD ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////EndGame.setPosition(view.getCenter().x - 683, view.getCenter().y - 384);if (p.EndLevel){timerEnd += time;if (timerEnd > 6000){window.draw(EndGame);music.stop();}}GameOver.setPosition(view.getCenter().x - 683, view.getCenter().y - 384);if (p.GameOver){window.draw(GameOver);music.stop();}window.display();}}void gameRunning(){if (startGame()) { gameRunning(); };}int main(){setlocale(LC_ALL, "rus");cout << " _______________________________________\n";cout << "| Программа запуска игры \"MegaMan\". |\n";cout << "| Версия игры [Alpha 0.01]. |\n";cout << "| Дата запуска игры: " << __DATE__ << " |\n";cout << "| Время запуска игры: " << __TIME__ << " |\n";cout << "| Загрузка текстур..................100% |\n";cout << "| Загрузка набора тайлов............100% |\n";cout << "| Загрузка игрока...................100% |\n";cout << "| Загрузка врагов...................100% |\n";cout << "| Загрузка бонусов..................100% |\n";cout << "| Загрузка карты....................100% |\n";cout << "| Загружаем меню... |\n";cout << " _______________________________________\n";gameRunning();return 0;} -
АвторСообщения
Просмотр 4 сообщений - с 1 по 4 (из 4 всего)
Для ответа в этой теме необходимо авторизоваться.