Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 |
while (window.isOpen()) { CurrentState->HandleEvents(*this); window.clear(); CurrentState->Update(*this); CurrentState->Draw(*this); window.display(); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
void Statsstate::Draw(Game& game) { game.window.draw(sBackground); /*game.window.draw(shSwapLoose); game.window.draw(shNoSwapWin); game.window.draw(shNoSwapLoose); game.window.draw(shSwapWin);*/ } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
if (!tBackground.loadFromFile("pics\\Texturen\\stats.png")) { std::cout << "Textur konnte nicht geladen werden!" << std::endl; } tBackground.setSmooth(true); sBackground.setTexture(tBackground); [...] shSwapWin.setFillColor(sf::Color(0.f, 170.f, 130.f)); if (swapWin + swapLoose != 0) { shSwapWin.setSize(sf::Vector2f(100.f, (static_cast<float> (swapWin) / (swapWin + swapLoose)) * 289)); } else if (swapWin + swapLoose == 0) { shSwapWin.setSize(sf::Vector2f(100.f, 0)); } shSwapWin.setOrigin(0, shSwapWin.getGlobalBounds().height); shSwapWin.setPosition(203.f,661.f); |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# include "game.h" Game::Game() { window.create(sf::VideoMode(1600, 900), "Let's make a Deal!"/*, sf::Style::Fullscreen*/); running = true; } void Game::Run() { while (window.isOpen()) { CurrentState->HandleEvents(*this); window.clear(); CurrentState->Update(*this); CurrentState->Draw(*this); window.display(); } } bool Game::isRunning() { return running; } void Game::ChangeState(gameStates newState) { switch (newState) { case gameStates::INTRO: CurrentState = std::move(std::unique_ptr<Introstate>(new Introstate)); break; case gameStates::MAINMENU: CurrentState = std::move(std::unique_ptr<MainMenuState>(new MainMenuState)); break; } } void Game::ChangeState(gameStates newState, int sWin, int sLoose, int nSWin, int nSLoose) { int tmpSWin = sWin; int tmpSLoose = sLoose; int tmpNSWin = nSWin; int tmpNSLoose = nSLoose; if (newState == gameStates::PLAY) { CurrentState = std::move(std::unique_ptr<Playstate>(new Playstate(tmpSWin, tmpSLoose, tmpNSWin, tmpNSLoose))); } else if (newState == gameStates::STATS) { CurrentState = std::move(std::unique_ptr<Statsstate>(new Statsstate(tmpSWin, tmpSLoose, tmpNSWin, tmpNSLoose))); } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
void Playstate::HandleEvents(Game& game) { sf::Event event; while (game.window.pollEvent(event)) { if (event.type == sf::Event::Closed) { game.window.close(); game.running = false; } if (event.type == sf::Event::MouseButtonReleased) { if (event.mouseButton.button == 0) { if (bStatsSelected) { game.ChangeState(Game::gameStates::STATS, swapWin, swapLoose, noSwapWin, noSwapLoose); } } } } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Statsstate::Statsstate(int sWin, int sLoose, int nSWin, int nSLoose) { swapWin = sWin; swapLoose = sLoose; noSwapWin = nSWin; noSwapLoose = nSLoose; if (!tBackground.loadFromFile("pics\\Texturen\\stats.png")) { std::cout << "Textur konnte nicht geladen werden!" << std::endl; } tBackground.setSmooth(true); sBackground.setTexture(tBackground); shSwapWin.setFillColor(sf::Color(0.f, 170.f, 130.f)); if (swapWin + swapLoose != 0) { shSwapWin.setSize(sf::Vector2f(100.f, (static_cast<float> (swapWin) / (swapWin + swapLoose)) * 289)); } else if (swapWin + swapLoose == 0) { shSwapWin.setSize(sf::Vector2f(100.f, 0)); } shSwapWin.setOrigin(0, shSwapWin.getGlobalBounds().height); shSwapWin.setPosition(203.f,661.f); [...] } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#ifndef STATSSTATE_HPP #define STATSSTATE_HPP #include "game.h" #include "Gamestate.h" class Statsstate : public Gamestate { public: Statsstate(int sWin, int sLoose, int nSWin, int nSLoose); ~Statsstate(); void HandleEvents(Game& game); // Zum Beenden, zurückkehren in die Spielklasse void Update(Game& game); // Abfrage, wo sich die Maus gerade befindet void Draw(Game& game); // Zeichnen der einzelnen Objekte private: bool bContinueSelected; bool bNewGameSelected; sf::Texture tBackground; sf::Sprite sBackground; int swapWin; [...] // weitere Variablen }; #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
Game::Game() { window.create(sf::VideoMode(1600, 900), "Let's make a Deal!"/*, sf::Style::Fullscreen*/); running = true; } |
Werbeanzeige