From 09f74932ea3465d16ea257b8f1f2acdcd39456da Mon Sep 17 00:00:00 2001 From: NaiJi Date: Wed, 28 Apr 2021 19:14:18 +0300 Subject: [PATCH] Implement classic arrow sprite interface --- CMakeLists.txt | 25 +++++++++---------- application.cpp | 2 +- notesprites/classicarrow.h | 19 ++++++++++++--- notesprites/notegraphicsentity.cpp | 15 ++++++++++++ notesprites/notegraphicsentity.h | 31 ++++++++++++++++++++++++ notesprites/notesprite.cpp | 21 ---------------- notesprites/notesprite.h | 36 ---------------------------- timeline.cpp | 2 +- timelineviews/classicviewmanager.cpp | 2 +- timelineviews/classicviewmanager.h | 12 +--------- 10 files changed, 79 insertions(+), 86 deletions(-) create mode 100644 notesprites/notegraphicsentity.cpp create mode 100644 notesprites/notegraphicsentity.h delete mode 100644 notesprites/notesprite.cpp delete mode 100644 notesprites/notesprite.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7091b0b..3d190bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,18 +9,19 @@ 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}) -#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}) +include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/notesprites ${CMAKE_SOURCE_DIR}/timelineviews) +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}) -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 3916a4b..d7291c0 100644 --- a/application.cpp +++ b/application.cpp @@ -2,7 +2,7 @@ #include #include -#include "timelineviews/classicviewmanager.h" +#include "classicviewmanager.h" const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 60.f); diff --git a/notesprites/classicarrow.h b/notesprites/classicarrow.h index 0d1573c..1bbfc33 100644 --- a/notesprites/classicarrow.h +++ b/notesprites/classicarrow.h @@ -1,9 +1,11 @@ #ifndef CLASSICARROW_H #define CLASSICARROW_H -#include "notesprite.h" +#include "notegraphicsentity.h" -class ClassicArrow : public NoteSprite +#include + +class ClassicArrow : public NoteGraphicsEntity { public: @@ -20,8 +22,19 @@ public: virtual void update() override; -private: + virtual void onKeyPressed() override; + virtual void onKeyReleased() override; + + virtual void show() override; + virtual void killAsExpired() override; + virtual void reset() override; + virtual bool isActive() const override; + +private: + sf::RectangleShape static_sprite; + sf::RectangleShape trail_sprite; + sf::VertexArray trail_vertex; }; #endif // CLASSICARROW_H diff --git a/notesprites/notegraphicsentity.cpp b/notesprites/notegraphicsentity.cpp new file mode 100644 index 0000000..ff4f052 --- /dev/null +++ b/notesprites/notegraphicsentity.cpp @@ -0,0 +1,15 @@ +#include "notegraphicsentity.h" + +NoteGraphicsEntity::NoteGraphicsEntity() : + _attached(false) +{} + +void NoteGraphicsEntity::attach() noexcept +{ + _attached = true; +} + +void NoteGraphicsEntity::detach() noexcept +{ + _attached = false; +} diff --git a/notesprites/notegraphicsentity.h b/notesprites/notegraphicsentity.h new file mode 100644 index 0000000..52e1f3d --- /dev/null +++ b/notesprites/notegraphicsentity.h @@ -0,0 +1,31 @@ +#ifndef NOTEGRAPHICSENTITY_H +#define NOTEGRAPHICSENTITY_H + +#include +#include + +class NoteGraphicsEntity : public sf::Drawable, public sf::Transformable +{ +public: + explicit NoteGraphicsEntity(); + virtual ~NoteGraphicsEntity() = 0; + + virtual void update() = 0; + + virtual void attach() noexcept final; + virtual void detach() noexcept final; + + virtual void onKeyPressed() = 0; + virtual void onKeyReleased() = 0; + + virtual void show() = 0; + virtual void killAsExpired() = 0; + virtual void reset() = 0; + + virtual bool isActive() const = 0; + +protected: + bool _attached; +}; + +#endif diff --git a/notesprites/notesprite.cpp b/notesprites/notesprite.cpp deleted file mode 100644 index 50f2a2e..0000000 --- a/notesprites/notesprite.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#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 deleted file mode 100644 index 7102aae..0000000 --- a/notesprites/notesprite.h +++ /dev/null @@ -1,36 +0,0 @@ -#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/timeline.cpp b/timeline.cpp index a8ffe39..374b75f 100644 --- a/timeline.cpp +++ b/timeline.cpp @@ -1,6 +1,6 @@ #include "timeline.h" #include "note.h" -#include "timelineviews/timelineviewmanager.h" +#include "timelineviewmanager.h" #include #include diff --git a/timelineviews/classicviewmanager.cpp b/timelineviews/classicviewmanager.cpp index 177f468..a7500cb 100644 --- a/timelineviews/classicviewmanager.cpp +++ b/timelineviews/classicviewmanager.cpp @@ -1,5 +1,5 @@ #include "classicviewmanager.h" -#include "../note.h" +#include "note.h" #include static constexpr std::size_t RESERVED_SIZE = 20; diff --git a/timelineviews/classicviewmanager.h b/timelineviews/classicviewmanager.h index 4d9198f..33e90f2 100644 --- a/timelineviews/classicviewmanager.h +++ b/timelineviews/classicviewmanager.h @@ -2,6 +2,7 @@ #define CLASSICDIVAVIEWMANAGER_H #include "timelineviewmanager.h" +#include "classicarrow.h" #include #include @@ -17,17 +18,6 @@ public: virtual void initNoteGraphics(Note *note) override; private: - - enum Button - { - - - SHOULDER_RIGHT, - SHOULDER_LEFT, - - AMOUNT_OF_KINDS - }; - using SpritePoll = std::vector>; using SpriteDispatcher = std::array; SpriteDispatcher _sprite_dispatcher;