From b5a253a865da92abff2f42b63fc674eba774c48a Mon Sep 17 00:00:00 2001 From: Crizomb Date: Sat, 14 Jun 2025 23:32:34 +0200 Subject: [PATCH] background --- SimpleGame/src/CMakeLists.txt | 13 +++++++------ SimpleGame/src/Include/Game.hpp | 2 ++ SimpleGame/src/Include/GameData.hpp | 11 ++++++++--- SimpleGame/src/Source/Game.cpp | 16 +++++++++++++--- SimpleGame/src/Source/GameData.cpp | 5 +++++ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 SimpleGame/src/Source/GameData.cpp diff --git a/SimpleGame/src/CMakeLists.txt b/SimpleGame/src/CMakeLists.txt index 5117e0c..a6f1fe0 100644 --- a/SimpleGame/src/CMakeLists.txt +++ b/SimpleGame/src/CMakeLists.txt @@ -18,12 +18,13 @@ else() endif() add_executable(simpleGame - Source/Game.cpp Include/Game.hpp Include/GameData.hpp - Source/Main.cpp - Source/AudioEmitter.cpp Include/AudioEmitter.hpp - Source/NoteSprite.cpp Include/NoteSprite.hpp - Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp - Source/TilePattern.cpp Include/TilePattern.hpp + Source/Game.cpp Include/Game.hpp + Source/GameData.cpp Include/GameData.hpp + Source/Main.cpp + Source/AudioEmitter.cpp Include/AudioEmitter.hpp + Source/NoteSprite.cpp Include/NoteSprite.hpp + Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp + Source/TilePattern.cpp Include/TilePattern.hpp ) target_include_directories(simpleGame PRIVATE diff --git a/SimpleGame/src/Include/Game.hpp b/SimpleGame/src/Include/Game.hpp index ab3ca4c..b8f737b 100644 --- a/SimpleGame/src/Include/Game.hpp +++ b/SimpleGame/src/Include/Game.hpp @@ -45,6 +45,8 @@ private: sf::Text ScoreMultiplierText{mFont}; int score = 0; int score_multiplier = 1; // number of good press without misses + + sf::Sprite backGround; }; #endif // BOOK_GAME_HPP diff --git a/SimpleGame/src/Include/GameData.hpp b/SimpleGame/src/Include/GameData.hpp index 9a241b0..b56f9ab 100644 --- a/SimpleGame/src/Include/GameData.hpp +++ b/SimpleGame/src/Include/GameData.hpp @@ -1,12 +1,17 @@ #pragma once -static constexpr unsigned int SCREEN_WIDTH = 1080; +static constexpr unsigned int SCREEN_WIDTH = 1280; static constexpr unsigned int SCREEN_HEIGHT = 720; -static constexpr unsigned int NOTE_PRESS_HEIGHT = SCREEN_HEIGHT * 0.9; +static constexpr unsigned int NOTE_PRESS_HEIGHT = SCREEN_HEIGHT * 0.8; static constexpr unsigned int MIDDLE_WIDTH = SCREEN_WIDTH / 2; static constexpr unsigned int MIDDLE_HEIGHT = SCREEN_HEIGHT / 2; static constexpr unsigned int NOTE_PLACE_X_POS[3] = { - SCREEN_WIDTH * 3 / 10, SCREEN_WIDTH * 5 / 10, SCREEN_WIDTH * 7 / 10}; + SCREEN_WIDTH * 6 / 10, SCREEN_WIDTH * 7 / 10, SCREEN_WIDTH * 8 / 10}; + +namespace sf { +class Texture; +}; +extern sf::Texture placeHolder; diff --git a/SimpleGame/src/Source/Game.cpp b/SimpleGame/src/Source/Game.cpp index 1de082d..d766cbb 100644 --- a/SimpleGame/src/Source/Game.cpp +++ b/SimpleGame/src/Source/Game.cpp @@ -6,6 +6,8 @@ #include "TilePattern.hpp" #include #include +#include +#include #include #include #include @@ -14,8 +16,9 @@ #include const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f); +sf::Texture bgTexture; -Game::Game() { +Game::Game() : backGround(placeHolder) { assert(mFont.openFromFile("media/Sansation.ttf")); mStatisticsText.setPosition({5.f, 5.f}); mStatisticsText.setCharacterSize(10); @@ -41,6 +44,14 @@ Game::Game() { ScoreMultiplierText.setPosition({SCREEN_WIDTH - 200, 25}); ScoreMultiplierText.setFillColor(sf::Color::Black); ScoreMultiplierText.setCharacterSize(20); + + if (!bgTexture.loadFromFile("media/sprites/bureau.png")) { + printf("sprite bureau not loaded\n"); + } + backGround.setTexture(bgTexture, true); + float sx = backGround.getTexture().getSize().x; + float sy = backGround.getTexture().getSize().y; + backGround.setScale(sf::Vector2f(SCREEN_WIDTH / sx, SCREEN_HEIGHT / sy)); } void generateTilePatternAndMusic(AudioEmitter &audio_emitter) { @@ -109,6 +120,7 @@ void Game::update(const sf::Time elapsedTime) {} void Game::render() { mWindow.clear(sf::Color::Yellow); + mWindow.draw(backGround); mWindow.draw(leftPressZone); mWindow.draw(middlePressZone); mWindow.draw(rightPressZone); @@ -139,6 +151,4 @@ void Game::update_scores(bool good_action) { ScoreText.setString(std::format("Score = {}", score)); ScoreMultiplierText.setString( std::format("ScoreMultiplier = {}", score_multiplier)); - printf("good action : %d\n score %d\n score_multiplier %d\n ", good_action, - score, score_multiplier); } diff --git a/SimpleGame/src/Source/GameData.cpp b/SimpleGame/src/Source/GameData.cpp new file mode 100644 index 0000000..438450f --- /dev/null +++ b/SimpleGame/src/Source/GameData.cpp @@ -0,0 +1,5 @@ +#include "GameData.hpp" +#include +#include + +sf::Texture placeHolder = sf::Texture(sf::Vector2u(200, 200));