Delete roundtarget
This commit is contained in:
parent
05f8b11dec
commit
dbb296ff5d
5 changed files with 2 additions and 74 deletions
|
@ -19,7 +19,6 @@ endif()
|
|||
|
||||
add_executable(simpleGame
|
||||
Source/Game.cpp Include/Game.hpp Source/Main.cpp
|
||||
Source/RoundTarget.cpp Include/RoundTarget.hpp
|
||||
Source/AudioEmitter.cpp Include/AudioEmitter.hpp
|
||||
Source/NoteSprite.cpp Include/NoteSprite.hpp
|
||||
Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#define BOOK_GAME_HPP
|
||||
|
||||
#include "AudioEmitter.hpp"
|
||||
#include "RoundTarget.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
class Game {
|
||||
|
@ -25,7 +24,6 @@ private:
|
|||
|
||||
sf::RenderWindow mWindow{sf::VideoMode({640, 480}), "SFML Application"};
|
||||
sf::Texture mTexture;
|
||||
RoundTarget mTarget{35.f, sf::Color::Red, 320.f, 300.f};
|
||||
sf::Font mFont;
|
||||
sf::Text mStatisticsText{mFont};
|
||||
sf::Time mStatisticsUpdateTime;
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef SIMPLE_GAME_ROUND_TARGET_H
|
||||
#define SIMPLE_GAME_ROUND_TARGET_H
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
class RoundTarget {
|
||||
public:
|
||||
RoundTarget(float radius, sf::Color color, float x, float y);
|
||||
void drawCurrent(sf::RenderWindow &window) const;
|
||||
void handlePlayerInput(const sf::Keyboard::Key &key, const bool &isPressed);
|
||||
void update(const sf::Time &elapsedTime);
|
||||
|
||||
private:
|
||||
static constexpr float TargetSpeed{100.f};
|
||||
bool mIsMovingUp{false};
|
||||
bool mIsMovingDown{false};
|
||||
bool mIsMovingRight{false};
|
||||
bool mIsMovingLeft{false};
|
||||
sf::CircleShape mShape;
|
||||
};
|
||||
|
||||
#endif // SIMPLE_GAME_ROUND_TARGET_H
|
|
@ -52,24 +52,18 @@ void Game::run() {
|
|||
|
||||
void Game::processEvents(AudioEmitter &audioEmitter) {
|
||||
while (const std::optional event = mWindow.pollEvent()) {
|
||||
if (const auto *keyPressed = event->getIf<sf::Event::KeyPressed>()) {
|
||||
mTarget.handlePlayerInput(keyPressed->code, true);
|
||||
} else if (const auto *keyReleased =
|
||||
event->getIf<sf::Event::KeyReleased>()) {
|
||||
mTarget.handlePlayerInput(keyReleased->code, false);
|
||||
} else if (event->is<sf::Event::Closed>()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
audioEmitter.audioEnd();
|
||||
mWindow.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::update(const sf::Time elapsedTime) { mTarget.update(elapsedTime); }
|
||||
void Game::update(const sf::Time elapsedTime) {}
|
||||
|
||||
void Game::render() {
|
||||
mWindow.clear(sf::Color::Yellow);
|
||||
NoteTile::update(1.0 / 60, mWindow);
|
||||
mTarget.drawCurrent(mWindow);
|
||||
mWindow.draw(mStatisticsText);
|
||||
mWindow.display();
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
#include "RoundTarget.hpp"
|
||||
|
||||
RoundTarget::RoundTarget(const float radius, const sf::Color color, float x,
|
||||
float y) {
|
||||
mShape.setRadius(radius);
|
||||
mShape.setFillColor(color);
|
||||
mShape.setPosition({x, y});
|
||||
}
|
||||
|
||||
void RoundTarget::drawCurrent(sf::RenderWindow &window) const {
|
||||
/*printf("sphere pos (%f, %f)\n", mShape.getPosition().x,*/
|
||||
/* mShape.getPosition().y);*/
|
||||
window.draw(mShape);
|
||||
}
|
||||
|
||||
void RoundTarget::handlePlayerInput(const sf::Keyboard::Key &key,
|
||||
const bool &isPressed) {
|
||||
using enum sf::Keyboard::Key;
|
||||
if (key == Z)
|
||||
mIsMovingUp = isPressed;
|
||||
else if (key == S)
|
||||
mIsMovingDown = isPressed;
|
||||
else if (key == Q)
|
||||
mIsMovingLeft = isPressed;
|
||||
else if (key == D)
|
||||
mIsMovingRight = isPressed;
|
||||
}
|
||||
|
||||
void RoundTarget::update(const sf::Time &elapsedTime) {
|
||||
sf::Vector2f movement{0.f, 0.f};
|
||||
if (mIsMovingUp)
|
||||
movement.y -= TargetSpeed;
|
||||
if (mIsMovingDown)
|
||||
movement.y += TargetSpeed;
|
||||
if (mIsMovingLeft)
|
||||
movement.x -= TargetSpeed;
|
||||
if (mIsMovingRight)
|
||||
movement.x += TargetSpeed;
|
||||
|
||||
mShape.move(movement * elapsedTime.asSeconds());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue