From bbed8247ead2509d69e56c353208e6c568de1fe0 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Mon, 19 Apr 2021 00:44:09 +0300 Subject: [PATCH] Implement abstraction for note sprites --- CMakeLists.txt | 27 ++++++++++---------- application.cpp | 2 +- notesprites/classicarrow.cpp | 12 +++++++++ notesprites/classicarrow.h | 27 ++++++++++++++++++++ notesprites/notesprite.cpp | 21 ++++++++++++++++ notesprites/notesprite.h | 36 +++++++++++++++++++++++++++ timelineviews/classicviewmanager.cpp | 2 +- timelineviews/classicviewmanager.h | 5 +--- timelineviews/timelineviewmanager.cpp | 3 --- timelineviews/timelineviewmanager.h | 2 +- 10 files changed, 113 insertions(+), 24 deletions(-) create mode 100644 notesprites/classicarrow.cpp create mode 100644 notesprites/classicarrow.h create mode 100644 notesprites/notesprite.cpp create mode 100644 notesprites/notesprite.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f5792bc..7091b0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,23 +5,22 @@ project(project-kyoku LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -set(SOURCES application.cpp note.cpp debughelper.cpp main.cpp timeline.cpp timelineviews/timelineviewmanager.cpp timelineviews/classicviewmanager.cpp) -set(HEADER_FILES application.h note.h debughelper.h timeline.h timelineviews/timelineviewmanager.h timelineviews/classicviewmanager.h) +file(GLOB SOURCES "*.h" "*.cpp" "*/*.h" "*/*.cpp") # STATIC # # You need to build SFML from sources with cmake -set(SFML_LIB_DIR - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5 - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5 - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5 - ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-audio.so.2.5) -set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include) -include_directories(${SFML_INCL_DIR}) -add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) -target_link_libraries(project-kyoku ${SFML_LIB_DIR}) +#set(SFML_LIB_DIR +# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-graphics.so.2.5 +# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-system.so.2.5 +# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-window.so.2.5 +# ${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-audio.so.2.5) +#set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include) +#include_directories(${SFML_INCL_DIR}) +#add_executable(project-kyoku ${SOURCES}) +#target_link_libraries(project-kyoku ${SFML_LIB_DIR}) # DYNAMIC # # You only need to install SFML from your package manager -#find_package(SFML REQUIRED graphics window system) -#add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) -#target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network) +find_package(SFML REQUIRED graphics window system) +add_executable(project-kyoku ${SOURCES}) +target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network) diff --git a/application.cpp b/application.cpp index e9c53a4..3916a4b 100644 --- a/application.cpp +++ b/application.cpp @@ -25,7 +25,7 @@ void Application::run() _music.openFromFile(song_filename); _music.play(); - _music.setVolume(2); + _music.setVolume(30); _game_window.display(); diff --git a/notesprites/classicarrow.cpp b/notesprites/classicarrow.cpp new file mode 100644 index 0000000..bbbc0c4 --- /dev/null +++ b/notesprites/classicarrow.cpp @@ -0,0 +1,12 @@ +#include "classicarrow.h" + +ClassicArrow::ClassicArrow() +{} + +ClassicArrow::~ClassicArrow() +{} + +void ClassicArrow::update() +{ + +} diff --git a/notesprites/classicarrow.h b/notesprites/classicarrow.h new file mode 100644 index 0000000..0d1573c --- /dev/null +++ b/notesprites/classicarrow.h @@ -0,0 +1,27 @@ +#ifndef CLASSICARROW_H +#define CLASSICARROW_H + +#include "notesprite.h" + +class ClassicArrow : public NoteSprite +{ +public: + + enum class Type + { + ARROW_UP, + ARROW_RIGHT, + ARROW_DOWN, + ARROW_LEFT + }; + + explicit ClassicArrow(); + virtual ~ClassicArrow() override; + + virtual void update() override; + +private: + +}; + +#endif // CLASSICARROW_H diff --git a/notesprites/notesprite.cpp b/notesprites/notesprite.cpp new file mode 100644 index 0000000..50f2a2e --- /dev/null +++ b/notesprites/notesprite.cpp @@ -0,0 +1,21 @@ +#include "notesprite.h" + +NoteSprite::NoteSprite() : + _state(State::DETACHED), + _attached(false) +{} + +void NoteSprite::attach() noexcept +{ + _attached = true; +} + +void NoteSprite::detach() noexcept +{ + _attached = false; +} + +void NoteSprite::initState(State nextState) noexcept +{ + _state = nextState; +} diff --git a/notesprites/notesprite.h b/notesprites/notesprite.h new file mode 100644 index 0000000..7102aae --- /dev/null +++ b/notesprites/notesprite.h @@ -0,0 +1,36 @@ +#ifndef NOTESPRITE_H +#define NOTESPRITE_H + +#include +#include + +class NoteSprite : public sf::Drawable, public sf::Transformable +{ +public: + + enum class State + { + APPEARING, + ACTIVE, + TAPPED, + DYING, + + DETACHED + }; + + explicit NoteSprite(); + virtual ~NoteSprite() = 0; + + virtual void update() = 0; + + virtual void attach() noexcept final; + virtual void detach() noexcept final; + + virtual void initState(State nextState) noexcept final; + +protected: + State _state; + bool _attached; +}; + +#endif // NOTESPRITE_H diff --git a/timelineviews/classicviewmanager.cpp b/timelineviews/classicviewmanager.cpp index 03bc5fa..177f468 100644 --- a/timelineviews/classicviewmanager.cpp +++ b/timelineviews/classicviewmanager.cpp @@ -52,7 +52,7 @@ std::shared_ptr ClassicViewManager::createSprite(Button kind_of_button) void ClassicViewManager::initNoteGraphics(Note *note) { const auto type = note->type(); - for (const auto sprite : _sprite_dispatcher.at(static_cast(type))) + for (const auto& sprite : _sprite_dispatcher.at(static_cast(type))) { if (!sprite->isAttached()) { diff --git a/timelineviews/classicviewmanager.h b/timelineviews/classicviewmanager.h index 2aa4ee1..4d9198f 100644 --- a/timelineviews/classicviewmanager.h +++ b/timelineviews/classicviewmanager.h @@ -20,10 +20,7 @@ private: enum Button { - ARROW_UP, - ARROW_RIGHT, - ARROW_DOWN, - ARROW_LEFT, + SHOULDER_RIGHT, SHOULDER_LEFT, diff --git a/timelineviews/timelineviewmanager.cpp b/timelineviews/timelineviewmanager.cpp index 15593cb..5ea914e 100644 --- a/timelineviews/timelineviewmanager.cpp +++ b/timelineviews/timelineviewmanager.cpp @@ -2,6 +2,3 @@ TimelineViewManager::TimelineViewManager() {} - -TimelineViewManager::~TimelineViewManager() -{} diff --git a/timelineviews/timelineviewmanager.h b/timelineviews/timelineviewmanager.h index 59eb2e5..24d5815 100644 --- a/timelineviews/timelineviewmanager.h +++ b/timelineviews/timelineviewmanager.h @@ -7,7 +7,7 @@ class TimelineViewManager { public: explicit TimelineViewManager(); - virtual ~TimelineViewManager(); + virtual ~TimelineViewManager() = 0; virtual void initNoteGraphics(Note *note) = 0; };