background
This commit is contained in:
parent
785453b009
commit
b5a253a865
5 changed files with 35 additions and 12 deletions
|
@ -18,12 +18,13 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(simpleGame
|
add_executable(simpleGame
|
||||||
Source/Game.cpp Include/Game.hpp Include/GameData.hpp
|
Source/Game.cpp Include/Game.hpp
|
||||||
Source/Main.cpp
|
Source/GameData.cpp Include/GameData.hpp
|
||||||
Source/AudioEmitter.cpp Include/AudioEmitter.hpp
|
Source/Main.cpp
|
||||||
Source/NoteSprite.cpp Include/NoteSprite.hpp
|
Source/AudioEmitter.cpp Include/AudioEmitter.hpp
|
||||||
Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp
|
Source/NoteSprite.cpp Include/NoteSprite.hpp
|
||||||
Source/TilePattern.cpp Include/TilePattern.hpp
|
Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp
|
||||||
|
Source/TilePattern.cpp Include/TilePattern.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(simpleGame PRIVATE
|
target_include_directories(simpleGame PRIVATE
|
||||||
|
|
|
@ -45,6 +45,8 @@ private:
|
||||||
sf::Text ScoreMultiplierText{mFont};
|
sf::Text ScoreMultiplierText{mFont};
|
||||||
int score = 0;
|
int score = 0;
|
||||||
int score_multiplier = 1; // number of good press without misses
|
int score_multiplier = 1; // number of good press without misses
|
||||||
|
|
||||||
|
sf::Sprite backGround;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BOOK_GAME_HPP
|
#endif // BOOK_GAME_HPP
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
|
|
||||||
#pragma once
|
#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 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_WIDTH = SCREEN_WIDTH / 2;
|
||||||
static constexpr unsigned int MIDDLE_HEIGHT = SCREEN_HEIGHT / 2;
|
static constexpr unsigned int MIDDLE_HEIGHT = SCREEN_HEIGHT / 2;
|
||||||
|
|
||||||
static constexpr unsigned int NOTE_PLACE_X_POS[3] = {
|
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;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include "TilePattern.hpp"
|
#include "TilePattern.hpp"
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <SFML/Window/Keyboard.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
@ -14,8 +16,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f);
|
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"));
|
assert(mFont.openFromFile("media/Sansation.ttf"));
|
||||||
mStatisticsText.setPosition({5.f, 5.f});
|
mStatisticsText.setPosition({5.f, 5.f});
|
||||||
mStatisticsText.setCharacterSize(10);
|
mStatisticsText.setCharacterSize(10);
|
||||||
|
@ -41,6 +44,14 @@ Game::Game() {
|
||||||
ScoreMultiplierText.setPosition({SCREEN_WIDTH - 200, 25});
|
ScoreMultiplierText.setPosition({SCREEN_WIDTH - 200, 25});
|
||||||
ScoreMultiplierText.setFillColor(sf::Color::Black);
|
ScoreMultiplierText.setFillColor(sf::Color::Black);
|
||||||
ScoreMultiplierText.setCharacterSize(20);
|
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) {
|
void generateTilePatternAndMusic(AudioEmitter &audio_emitter) {
|
||||||
|
@ -109,6 +120,7 @@ void Game::update(const sf::Time elapsedTime) {}
|
||||||
|
|
||||||
void Game::render() {
|
void Game::render() {
|
||||||
mWindow.clear(sf::Color::Yellow);
|
mWindow.clear(sf::Color::Yellow);
|
||||||
|
mWindow.draw(backGround);
|
||||||
mWindow.draw(leftPressZone);
|
mWindow.draw(leftPressZone);
|
||||||
mWindow.draw(middlePressZone);
|
mWindow.draw(middlePressZone);
|
||||||
mWindow.draw(rightPressZone);
|
mWindow.draw(rightPressZone);
|
||||||
|
@ -139,6 +151,4 @@ void Game::update_scores(bool good_action) {
|
||||||
ScoreText.setString(std::format("Score = {}", score));
|
ScoreText.setString(std::format("Score = {}", score));
|
||||||
ScoreMultiplierText.setString(
|
ScoreMultiplierText.setString(
|
||||||
std::format("ScoreMultiplier = {}", score_multiplier));
|
std::format("ScoreMultiplier = {}", score_multiplier));
|
||||||
printf("good action : %d\n score %d\n score_multiplier %d\n ", good_action,
|
|
||||||
score, score_multiplier);
|
|
||||||
}
|
}
|
||||||
|
|
5
SimpleGame/src/Source/GameData.cpp
Normal file
5
SimpleGame/src/Source/GameData.cpp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#include "GameData.hpp"
|
||||||
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
|
sf::Texture placeHolder = sf::Texture(sf::Vector2u(200, 200));
|
Loading…
Add table
Add a link
Reference in a new issue