Implement abstraction for note sprites

This commit is contained in:
NaiJi ✨ 2021-04-19 00:44:09 +03:00
parent 8a7602af78
commit bbed8247ea
10 changed files with 113 additions and 24 deletions

View File

@ -5,23 +5,22 @@ project(project-kyoku LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") 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) file(GLOB SOURCES "*.h" "*.cpp" "*/*.h" "*/*.cpp")
set(HEADER_FILES application.h note.h debughelper.h timeline.h timelineviews/timelineviewmanager.h timelineviews/classicviewmanager.h)
# STATIC # # STATIC #
# You need to build SFML from sources with cmake # You need to build SFML from sources with cmake
set(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-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-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-window.so.2.5
${CMAKE_SOURCE_DIR}/SFML-2.5.1/lib/libsfml-audio.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) #set(SFML_INCL_DIR ${CMAKE_SOURCE_DIR}/SFML-2.5.1/include)
include_directories(${SFML_INCL_DIR}) #include_directories(${SFML_INCL_DIR})
add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) #add_executable(project-kyoku ${SOURCES})
target_link_libraries(project-kyoku ${SFML_LIB_DIR}) #target_link_libraries(project-kyoku ${SFML_LIB_DIR})
# DYNAMIC # # DYNAMIC #
# You only need to install SFML from your package manager # You only need to install SFML from your package manager
#find_package(SFML REQUIRED graphics window system) find_package(SFML REQUIRED graphics window system)
#add_executable(project-kyoku ${SOURCES} ${HEADER_FILES} ) add_executable(project-kyoku ${SOURCES})
#target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network) target_link_libraries(project-kyoku sfml-system sfml-audio sfml-graphics sfml-network)

View File

@ -25,7 +25,7 @@ void Application::run()
_music.openFromFile(song_filename); _music.openFromFile(song_filename);
_music.play(); _music.play();
_music.setVolume(2); _music.setVolume(30);
_game_window.display(); _game_window.display();

View File

@ -0,0 +1,12 @@
#include "classicarrow.h"
ClassicArrow::ClassicArrow()
{}
ClassicArrow::~ClassicArrow()
{}
void ClassicArrow::update()
{
}

View File

@ -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

View File

@ -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;
}

36
notesprites/notesprite.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef NOTESPRITE_H
#define NOTESPRITE_H
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
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

View File

@ -52,7 +52,7 @@ std::shared_ptr<Sprite> ClassicViewManager::createSprite(Button kind_of_button)
void ClassicViewManager::initNoteGraphics(Note *note) void ClassicViewManager::initNoteGraphics(Note *note)
{ {
const auto type = note->type(); const auto type = note->type();
for (const auto sprite : _sprite_dispatcher.at(static_cast<int>(type))) for (const auto& sprite : _sprite_dispatcher.at(static_cast<int>(type)))
{ {
if (!sprite->isAttached()) if (!sprite->isAttached())
{ {

View File

@ -20,10 +20,7 @@ private:
enum Button enum Button
{ {
ARROW_UP,
ARROW_RIGHT,
ARROW_DOWN,
ARROW_LEFT,
SHOULDER_RIGHT, SHOULDER_RIGHT,
SHOULDER_LEFT, SHOULDER_LEFT,

View File

@ -2,6 +2,3 @@
TimelineViewManager::TimelineViewManager() TimelineViewManager::TimelineViewManager()
{} {}
TimelineViewManager::~TimelineViewManager()
{}

View File

@ -7,7 +7,7 @@ class TimelineViewManager
{ {
public: public:
explicit TimelineViewManager(); explicit TimelineViewManager();
virtual ~TimelineViewManager(); virtual ~TimelineViewManager() = 0;
virtual void initNoteGraphics(Note *note) = 0; virtual void initNoteGraphics(Note *note) = 0;
}; };