forked from NaiJi/project-kyoku
parent
ac88cd9dfa
commit
833dd2b781
@ -1,15 +0,0 @@ |
||||
cmake_minimum_required(VERSION 2.8.8) |
||||
|
||||
project(core) |
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
||||
include_directories(${CMAKE_SOURCE_DIR}/include) |
||||
|
||||
file(GLOB_RECURSE HEADERS "shared/*.h") |
||||
file(GLOB_RECURSE SOURCES "src/*.cpp") |
||||
|
||||
add_library(core STATIC ${SOURCES} ${HEADERS}) |
||||
target_include_directories(core PRIVATE ${CMAKE_SOURCE_DIR}/tools/shared) |
||||
target_link_libraries(core tools) |
||||
|
||||
target_include_directories(project-kyoku PRIVATE ${CMAKE_SOURCE_DIR}/core/shared) |
@ -1,10 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <SFML/Window/Event.hpp> |
||||
#include "tools/mathutils.h" |
||||
|
||||
struct PlayerInput |
||||
{ |
||||
microsec timestamp; |
||||
sf::Event event; |
||||
}; |
@ -1,10 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <SFML/System/Time.hpp> |
||||
#include "tools/mathutils.h" |
||||
|
||||
struct UpdateData |
||||
{ |
||||
const microsec timestamp; |
||||
const sf::Time dt; |
||||
}; |
@ -0,0 +1,37 @@ |
||||
#pragma once |
||||
|
||||
#include <type_traits> |
||||
|
||||
#include "core/point.h" |
||||
#include "core/vector.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> |
||||
struct Area |
||||
{ |
||||
T left = 0; |
||||
T top = 0; |
||||
T width = 0; |
||||
T height = 0; |
||||
|
||||
inline kku::Point position() const noexcept |
||||
{ |
||||
return kku::Point{static_cast<float>(left), |
||||
static_cast<float>(top) }; |
||||
} |
||||
|
||||
inline void moveBy(const kku::Vector2<T>& vector) |
||||
{ |
||||
top += vector.second; |
||||
left += vector.first; |
||||
} |
||||
|
||||
inline bool contains(const kku::Point& point) const |
||||
{ |
||||
return point.x >= left ; // debug it when on computer
|
||||
} |
||||
}; |
||||
|
||||
} |
@ -1,19 +1,24 @@ |
||||
#pragma once |
||||
|
||||
#include "tools/mathutils.h" |
||||
#include "core/time.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
struct BPMSection |
||||
{ |
||||
int bpm = 120; // Hi, osu
|
||||
int fraction = 2; |
||||
unsigned int bpm = 120; // Hi, osu
|
||||
unsigned int fraction = 2; |
||||
microsec offset_start = 0; |
||||
microsec interval = 0; |
||||
}; |
||||
|
||||
struct BPMSectionCompt |
||||
struct BPMSectionComparator |
||||
{ |
||||
bool operator()(const BPMSection& lhs, const BPMSection& rhs) const noexcept |
||||
{ |
||||
return lhs.offset_start < rhs.offset_start; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,14 @@ |
||||
#pragma once |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
struct Color |
||||
{ |
||||
unsigned char red = 0; |
||||
unsigned char green = 0; |
||||
unsigned char blue = 0; |
||||
unsigned char alpha = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,26 @@ |
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
|
||||
#include "core/music.h" |
||||
#include "core/text.h" |
||||
#include "core/resourceholder.h" |
||||
#include "core/rectangle.h" |
||||
#include "core/vector.h" |
||||
#include "core/line.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
class CoreFactory |
||||
{ |
||||
public: |
||||
virtual ~CoreFactory() = default; |
||||
virtual std::shared_ptr<kku::Music> getMusic() const = 0; |
||||
virtual std::shared_ptr<kku::Text> getText(kku::Font::Id id) const = 0; |
||||
virtual std::shared_ptr<kku::Rectangle> getRectangle() const = 0; |
||||
virtual std::shared_ptr<kku::Line> getLine() const = 0; |
||||
virtual kku::Vector2<std::size_t> getRenderSize() const = 0; |
||||
}; |
||||
|
||||
} |
@ -1,15 +1,20 @@ |
||||
#pragma once |
||||
|
||||
#include "core/inputtype.h" |
||||
#include "core/gameevent.h" |
||||
#include "core/updatedata.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
class Game |
||||
{ |
||||
public: |
||||
virtual ~Game() = default; |
||||
|
||||
virtual void run() = 0; |
||||
virtual void input(PlayerInput&& inputdata) = 0; |
||||
virtual void input(GameEvent&& inputdata) = 0; |
||||
virtual void update(UpdateData&& updatedata) = 0; |
||||
virtual void display() const = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
#pragma once |
||||
|
||||
#include "core/systemevent.h" |
||||
#include "core/time.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
struct GameEvent |
||||
{ |
||||
const microsec timestamp = 0; |
||||
const SystemEvent event; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,18 @@ |
||||
#pragma once |
||||
|
||||
#include "core/point.h" |
||||
#include "core/color.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
class Line |
||||
{ |
||||
public: |
||||
virtual ~Line() = default; |
||||
virtual void setPosition(const kku::Point& p1, const kku::Point& p2) = 0; |
||||
virtual void setColor(const kku::Color& c1, const kku::Color& c2) = 0; |
||||
virtual void display() = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,32 @@ |
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
#include "core/time.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
class Music |
||||
{ |
||||
public: |
||||
virtual ~Music() = default; |
||||
|
||||
virtual bool open(const std::string& filepath) = 0; |
||||
|
||||
virtual void play() = 0; |
||||
virtual void pause() = 0; |
||||
virtual void stop() = 0; |
||||
|
||||
virtual bool isPlaying() const = 0; |
||||
|
||||
virtual void setVolume(float volume) = 0; |
||||
|
||||
virtual void setOffset(const kku::microsec& offset) = 0; |
||||
virtual void moveOffset(const kku::microsec& delta) = 0; |
||||
|
||||
virtual kku::microsec fetchOffset() = 0; |
||||
virtual kku::microsec getDuration() const = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,46 @@ |
||||
#pragma once |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
struct Point |
||||
{ |
||||
float x; |
||||
float y; |
||||
|
||||
constexpr inline explicit Point() noexcept : |
||||
x(0.), y(0.) |
||||
{} |
||||
|
||||
constexpr inline explicit Point(int x, int y) noexcept : |
||||
x(x), y(y) |
||||
{} |
||||
|
||||
constexpr inline explicit Point(float x, float y) noexcept : |
||||
x(x), y(y) |
||||
{} |
||||
|
||||
constexpr inline Point operator+(const Point& right) const noexcept |
||||
{ |
||||
return Point{right.x + x, right.y + y}; |
||||
} |
||||
|
||||
constexpr inline Point operator-(const Point& right) const noexcept |
||||
{ |
||||
return Point{right.x - x, right.y - y}; |
||||
} |
||||
|
||||
inline void moveBy(float x, float y) noexcept |
||||
{ |
||||
this->x += x; |
||||
this->y += y; |
||||
} |
||||
|
||||
inline void scaleBy(float factor) noexcept |
||||
{ |
||||
x *= factor; |
||||
y *= factor; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,26 @@ |
||||
#pragma once |
||||
|
||||
#include "core/area.h" |
||||
#include "core/color.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
class Rectangle |
||||
{ |
||||
public: |
||||
virtual ~Rectangle() = default; |
||||
virtual void setRect(const Area<float>& rect) = 0; |
||||
virtual Area<float> getRect() const = 0; |
||||
|
||||
virtual void setPosition(const Point& position) = 0; |
||||
virtual Point getPosition() const = 0; |
||||
virtual void move(const kku::Vector2<float>& delta) = 0; |
||||
|
||||
virtual void setColor(const Color& color) = 0; |
||||
virtual bool contains(const kku::Point& position) const = 0; |
||||
|
||||
virtual void display() = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
#include <map> |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
template <typename Resource, typename Id> |
||||
class ResourceHolder |
||||
{ |
||||
public: |
||||
inline void load(Id id, std::unique_ptr<Resource>&& resource) noexcept |
||||
{ |
||||
_resources[id] = std::move(resource); |
||||
} |
||||
|
||||
inline const std::shared_ptr<Resource>& get(Id id) const |
||||
{ |
||||
return _resources.find(id)->second; |
||||
} |
||||
|
||||
private: |
||||
std::map<Id, std::shared_ptr<Resource>> _resources; |
||||
}; |
||||
|
||||
namespace Font |
||||
{ |
||||
enum class Id |
||||
{ |
||||
GUI |
||||
}; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,65 @@ |
||||
#pragma once |
||||
|
||||
#include <variant> |
||||
|
||||
#include "core/point.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
struct SystemEvent |
||||
{ |
||||
enum class Type |
||||
{ |
||||
None = 0, |
||||
|
||||
Resize = 1, |
||||
|
||||
KeyPress = 2, |
||||
KeyRelease = 3, |
||||
|
||||
MouseWheelScroll = 4, |
||||
MouseMove = 5, |
||||
MousePress = 6, |
||||
MouseRelease = 7 |
||||
}; |
||||
|
||||
struct Size |
||||
{ |
||||
std::size_t width = 0; |
||||
std::size_t height = 0; |
||||
}; |
||||
|
||||
struct Key |
||||
{ |
||||
char view = char(0); |
||||
bool alt = false; |
||||
bool control = false; |
||||
bool shift = false; |
||||
}; |
||||
|
||||
struct Mouse |
||||
{ |
||||
Point position; |
||||
|
||||
bool scrolled_up = false; |
||||
|
||||
enum class Button |
||||
{ |
||||
None = 0, |
||||
Wheel = 1, |
||||
Left = 2, |
||||
Right = 3 |
||||
}; |
||||
|
||||
Button button = Button::Left; |
||||
}; |
||||
|
||||
struct None |
||||
{}; |
||||
|
||||
Type type = Type::None; |
||||
std::variant<Size, Key, Mouse, None> data; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,24 @@ |
||||
#pragma once |
||||
|
||||
#include <string> |
||||
#include "core/color.h" |
||||
#include "core/point.h" |
||||
#include "core/vector.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
class Text |
||||
{ |
||||
public: |
||||
virtual ~Text() = default; |
||||
virtual void setString(const std::string& string) = 0; |
||||
virtual void setCharacterSize(std::size_t pixels) = 0; |
||||
virtual void setPosition(const Point& point) = 0; |
||||
virtual void move(const kku::Vector2<float>& delta) = 0; |
||||
virtual void setColor(const Color& color) = 0; |
||||
|
||||
virtual void display() = 0; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,22 @@ |
||||
#pragma once |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
using microsec = long long; |
||||
|
||||
struct TimeRange |
||||
{ |
||||
const microsec begin = 0; |
||||
const microsec end = 0; |
||||
|
||||
constexpr inline explicit TimeRange() noexcept : |
||||
begin(0), end(0) |
||||
{} |
||||
|
||||
constexpr inline explicit TimeRange(microsec x, microsec y) noexcept : |
||||
begin(x), end(y) |
||||
{} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
#pragma once |
||||
|
||||
#include "core/time.h" |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
struct UpdateData |
||||
{ |
||||
const microsec timestamp; |
||||
const microsec dt; |
||||
}; |
||||
|
||||
} |
||||
|
||||
|
@ -0,0 +1,22 @@ |
||||
#pragma once |
||||
|
||||
#include <utility> |
||||
|
||||
namespace kku |
||||
{ |
||||
|
||||
/* Meaning an element of a vector space in math.
|
||||
* Don't mistake for std::vector<T> |
||||
* For now we don't need it as a special class, |
||||
* so let it be a wrapper. */ |
||||
|
||||
template <typename T> |
||||
using Vector2 = std::pair<T, T>; |
||||
|
||||
template <typename T> |
||||
inline constexpr auto makeVector(T&& l, T&& r) -> Vector2<T> |
||||
{ |
||||
return std::make_pair(std::forward<T>(l), std::forward<T>(r)); |
||||
} |
||||
|
||||
} |
@ -1,35 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <stack> |
||||
#include <memory> |
||||
#include <functional> |
||||
|
||||
#include <SFML/Window/Event.hpp> |
||||
#include <SFML/Graphics/Drawable.hpp> |
||||
#include <SFML/Graphics/Rect.hpp> |
||||
|
||||
class GUIState : public sf::Drawable |
||||
{ |
||||
public: |
||||
|
||||
enum Tag { |
||||
SPLASH_SCREEN, |
||||
MAIN_MENU, |
||||
GAME_PICKER, |
||||
GAME, |
||||
EDITOR_PICKER, |
||||
EDITOR, |
||||
SETTINGS, |
||||
|
||||
AMOUNT |
||||
}; |
||||
|
||||
virtual ~GUIState() = default; |
||||
|
||||
virtual void input(const sf::Event& event) = 0; |
||||
virtual void update(const sf::Time& dt) = 0; |
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override = 0; |
||||
|
||||
virtual void enter(sf::Vector2u&& render_size) = 0; |
||||
virtual void leave() = 0; |
||||
}; |
@ -1,24 +0,0 @@ |
||||
cmake_minimum_required(VERSION 2.8.8) |
||||
|
||||
project(classicmode) |
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
||||
include_directories(${CMAKE_SOURCE_DIR}/include) |
||||
|
||||
file(GLOB_RECURSE HEADERS "shared/*.h" ) |
||||
|
||||
file(GLOB_RECURSE SOURCES "editor/*.h" "editor/*.cpp" |
||||
"graphics/*.h" "graphics/*.cpp" |
||||
"game/*.h" "game/*.cpp" |
||||
"sfml/*.h" "sfml/*.cpp" |
||||
|
||||
"./classicfactory.cpp") |
||||
|
||||
add_library(classicmode STATIC ${SOURCES} ${HEADERS}) |
||||
target_include_directories(classicmode PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) |
||||
target_include_directories(classicmode PRIVATE ${CMAKE_SOURCE_DIR}/tools/shared) |
||||
target_include_directories(classicmode PRIVATE ${CMAKE_SOURCE_DIR}/core/shared) |
||||
target_link_libraries(classicmode tools core) |
||||
|
||||
target_include_directories(project-kyoku PRIVATE ${CMAKE_SOURCE_DIR}/modes/classicmode/shared) |
||||
|
@ -1,37 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
|
||||
#include "core/editor.h" |
||||
#include "core/timeline.h" |
||||
|
||||
#include "game/classicnote.h" |
||||
#include "classicmode/classicactions.h" |
||||
|
||||
class ClassicGraphicsManager; |
||||
|
||||
class ClassicEditor : public Editor |
||||
{ |
||||
public: |
||||
explicit ClassicEditor(const std::shared_ptr<Timeline<ClassicNote>>& timeline, |
||||
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager); |
||||
|
||||
virtual void input(PlayerInput&& inputdata) override; |
||||
virtual void update(UpdateData&& updatedata) override; |
||||
virtual void display() const override; |
||||
virtual void recalculate(const microsec& timestamp) override; |
||||
|
||||
void selectNoteType(Type type) noexcept; |
||||
|
||||
private: |
||||
inline microsec adjustOffset(microsec offset) const noexcept; |
||||
|
||||
Context _context; |
||||
|
||||
const std::shared_ptr<Timeline<ClassicNote>> _timeline; |
||||
const std::shared_ptr<ClassicGraphicsManager> _graphics_manager; |
||||
|
||||
Type _selected_type; |
||||
microsec _current_time; |
||||
microsec _scroll_step; |
||||
}; |
@ -1,41 +0,0 @@ |
||||
#include "mockclassicnote.h" |
||||
#include "graphics/classicgraphicsmanager.h" |
||||
#include "graphics/animations/classicanimationscenario.h" |
||||
|
||||
MockClassicNote::MockClassicNote(MockArrowNoteInitializer&& init) : |
||||
ClassicNote({nullptr, {}, init.initializer.perfect_offset}), |
||||
_state(State::NONE), |
||||
_context(init.initializer.context) |
||||
{ |
||||
_elements.resize(init.elements.size()); |
||||
|
||||
for (std::size_t i = 0; i < _elements.size(); ++i) |
||||
{ |
||||
_elements[i].coordinates = init.elements[i].coordinates; |
||||
_elements[i].type = init.elements[i].type; |
||||
} |
||||
} |
||||
|
||||
void MockClassicNote::putToGame() |
||||
{ |
||||
_state = State::FLYING; |
||||
} |
||||
|
||||
void MockClassicNote::update(const microsec &music_offset) |
||||
{ |
||||
switch (_state) |
||||
{ |
||||
default: return; |
||||
break; |
||||
|
||||
case State::FLYING: |
||||
if (music_offset > offset()) |
||||
_state = State::DEAD; |
||||
break; |
||||
} |
||||
|
||||
for (auto& element : _elements) |
||||
if (element.animations[_state]) |
||||
element.animations[_state]->update(music_offset); |
||||
} |
||||
|
@ -1,28 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <memory> |
||||
#include <array> |
||||
|
||||
#include "mockelement.h" |
||||
#include "game/classicnote.h" |
||||
#include "initializers/mockarrownoteinitializer.h" |
||||
|
||||
class MockClassicNote : public ClassicNote |
||||
{ |
||||
public: |
||||
explicit MockClassicNote(MockArrowNoteInitializer&& init); |
||||
virtual ~MockClassicNote() override = default; |
||||
|
||||
virtual void putToGame() override; |
||||
virtual void update(const microsec &music_offset) override; |
||||
virtual void input(PlayerInput&& inputdata) override; |
||||
|
||||
virtual void display(const ClassicGraphicsManager * const manager) const override; |
||||
virtual void setGraphics(ClassicGraphicsManager * const manager, TimeRange&& range) override; |
||||
|
||||
private: |
||||
std::vector<MockElement> _elements; |
||||
|
||||
State _state; |
||||
const Context *_context; |
||||
}; |
@ -1,21 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include "classicmode/classicactions.h" |
||||
#include "tools/mathutils.h" |
||||
|
||||
#include <vector> |
||||
#include <memory> |
||||
#include <array> |
||||
|
||||
class ClassicSprite; |
||||
class ClassicAnimationScenario; |
||||
|
||||
struct MockElement |
||||
{ |
||||
std::shared_ptr<ClassicSprite> sprite; |
||||
std::array<std::shared_ptr<ClassicAnimationScenario>, 4> animations; |
||||
Type type = Type::NONE; |
||||
|
||||
Coordinates coordinates; |
||||
std::vector<Coordinates> falling_curve_interpolation; |
||||
}; |
@ -1,116 +0,0 @@ |
||||
#include "classicgame.h" |
||||
#include "classicnote.h" |
||||
#include "classicmapcreator.h" |
||||
#include "graphics/classicscenegraphicsmanager.h" |
||||
#include "holdmanager.h" |
||||
|
||||
ClassicGame::ClassicGame(const std::shared_ptr<Timeline<ClassicNote>>& timeline, |
||||
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager) : |
||||
_timeline(timeline), |
||||
_graphics_manager(graphics_manager), |
||||
_hold_manager(std::make_unique<HoldManager>()) |
||||
{ |
||||
_slap_buffer.loadFromFile("Tick.ogg"); |
||||
_slap.setBuffer(_slap_buffer); |
||||
_slap.setVolume(50); |
||||
|
||||
_keys_to_buttons = |
||||
{ |
||||
{sf::Keyboard::Up, Type::UP}, // Load from settings
|
||||
{sf::Keyboard::Right, Type::RIGHT}, |
||||
{sf::Keyboard::Down, Type::DOWN}, |
||||
{sf::Keyboard::Left, Type::LEFT}, |
||||
|
||||
{sf::Keyboard::W, Type::UP}, |
||||
{sf::Keyboard::D, Type::RIGHT}, |
||||
{sf::Keyboard::S, Type::DOWN}, |
||||
{sf::Keyboard::A, Type::LEFT}, |
||||
|
||||
{sf::Keyboard::E, Type::SLIDER_RIGHT}, |
||||
{sf::Keyboard::Q, Type::SLIDER_LEFT} |
||||
}; |
||||
|
||||
_buttons_to_pressed_actions= |
||||
{ |
||||
{Type::UP, Action::PRESS_UP}, |
||||
{Type::RIGHT, Action::PRESS_RIGHT}, |
||||
{Type::DOWN, Action::PRESS_DOWN}, |
||||
{Type::LEFT, Action::PRESS_LEFT}, |
||||
|
||||
{Type::SLIDER_RIGHT, Action::PRESS_SLIDER_RIGHT}, |
||||
{Type::SLIDER_LEFT, Action::PRESS_SLIDER_LEFT} |
||||
}; |
||||
|
||||
_buttons_to_released_actions= |
||||
{ |
||||
{Type::UP, Action::RELEASE_UP}, |
||||
{Type::RIGHT, Action::RELEASE_RIGHT}, |
||||
{Type::DOWN, Action::RELEASE_DOWN}, |
||||
{Type::LEFT, Action::RELEASE_LEFT}, |
||||
|
||||
{Type::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT}, |
||||
{Type::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT} |
||||
}; |
||||
} |
||||
|
||||
ClassicGame::~ClassicGame() |
||||
{} |
||||
|
||||
void ClassicGame::run() |
||||
{ |
||||
_context.hold_manager = _hold_manager; |
||||
|
||||
auto beatmap = classic::createBeatmap("aa", _context); |
||||
_timeline->setNotes(beatmap.notes); |
||||
} |
||||
|
||||
void ClassicGame::input(PlayerInput&& inputdata) |
||||
{ |
||||
switch (inputdata.event.type) |
||||
{ |
||||
default: |
||||
return; |
||||
break; |
||||
|
||||
case sf::Event::KeyPressed: |
||||
{ |
||||
auto note_it = _timeline->getActiveNote(inputdata.timestamp); |
||||
|
||||
if (!_timeline->isExpired(note_it)) |
||||
{ |
||||
auto note = (*note_it); |
||||
note->input(std::move(inputdata)); |
||||
_slap.play(); |
||||
} |
||||
} |
||||
break; |
||||
|
||||
case sf::Event::KeyReleased: |
||||
{ |
||||
_hold_manager->checkRelease(inputdata.event.key.code); |
||||
} |
||||
break; |
||||
|
||||
} |
||||
} |
||||
|
||||
void ClassicGame::update(UpdateData&& updatedata) |
||||
{ |
||||
// UNCOMMENT TO TEST AUTOPLAY
|
||||
auto note_it = _timeline->getActiveNote(updatedata.timestamp); |
||||
|
||||
if (!_timeline->isExpired(note_it) && updatedata.timestamp >= (*note_it)->offset()) |
||||
{ |
||||
auto note = (*note_it); |
||||
note->input(PlayerInput{updatedata.timestamp, sf::Event{}}); |
||||
_slap.play(); |
||||
} |
||||
|
||||
_timeline->update(updatedata.timestamp); |
||||
_graphics_manager->update(updatedata.timestamp); |
||||
} |
||||
|
||||
void ClassicGame::display() const |
||||
{ |
||||
_graphics_manager->display(); |
||||
} |
@ -1,37 +0,0 @@ |
||||
#include "classicdyinganimationscenario.h" |
||||
#include "graphics/classicsprite.h" |
||||
|
||||
void ClassicDyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec &time_end) |
||||
{ |
||||
_sprite = sprite; |
||||
_time_begin = time_begin; |
||||
_time_end = time_end; |
||||
|
||||
_sprite->setColor(sf::Color(140, 140, 140)); |
||||
_sprite->setTrailColor(sf::Color(0, 0, 0, 0)); |
||||
_sprite->setTrailCoordinates(Coordinates(0, 0)); |
||||
} |
||||
|
||||
void ClassicDyingAnimationScenario::update(const microsec& music_offset) |
||||
{ |
||||
(void) music_offset; |
||||
|
||||
auto fill_color = _sprite->color(); |
||||
|
||||
if (fill_color.a == 0) |
||||
{ |
||||
fill_color.a = 0; |
||||
_sprite->setColor(fill_color); |
||||
return; |
||||
} |
||||
|
||||
auto new_alpha = fill_color.a - 15; |
||||
fill_color.a = new_alpha < 0 ? 0 : new_alpha; |
||||
|
||||
_sprite->setColor(fill_color); |
||||
} |
||||
|
||||
bool ClassicDyingAnimationScenario::isDone() const |
||||
{ |
||||
return _sprite->color().a == 0; |
||||
} |
@ -1,55 +0,0 @@ |
||||
#include "classicflyinganimationscenario.h" |
||||
#include "graphics/classicsprite.h" |
||||
|
||||
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const microsec& time_begin, const microsec &time_end) |
||||
{ |
||||
_sprite = sprite; |
||||
_time_begin = time_begin; |
||||
_time_end = time_end; |
||||
|
||||
_percentage = ((_time_end - _time_begin) * 0.01); |
||||
} |
||||
|
||||
float ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) const |
||||
{ |
||||
float diff = n2 - n1; |
||||
|
||||
return n1 + ( diff * perc ); |
||||
} |
||||
|
||||
void ClassicFlyingAnimationScenario::update(const microsec& music_offset) |
||||
{ |
||||
const auto crd = _sprite->coordinates(); |
||||
auto update_time = music_offset - _time_begin; |
||||
float i = update_time / _percentage * 0.01; |
||||
|
||||
float xa = getPoint( crd.x + 20. , crd.x + 90. , i ); |
||||
float ya = getPoint( crd.y - 600. , crd.y - 150. , i ); |
||||
float xb = getPoint( crd.x + 90. , crd.x , i ); |
||||
float yb = getPoint( crd.y - 150. , crd.y , i ); |
||||
|
||||
_sprite->setTrailCoordinates(Coordinates(getPoint( xa , xb , i ), getPoint( ya , yb , i ))); |
||||
|
||||
bool pastPerfectScore = (i >= 1); |
||||
|
||||
if (pastPerfectScore) |
||||
fadeTrailSprite(); |
||||
} |
||||
|
||||
bool ClassicFlyingAnimationScenario::isDone() const |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
void ClassicFlyingAnimationScenario::fadeTrailSprite() const |
||||
{ |
||||
auto fill_color = _sprite->trailColor(); |
||||
|
||||
if (fill_color.a == 0) |
||||
return; |
||||
|
||||
auto new_alpha = fill_color.a - 35; |
||||
fill_color.a = new_alpha < 0 ? 0 : new_alpha; |
||||
|
||||
_sprite->setTrailColor(fill_color); |
||||
} |
@ -1,37 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include "game/classicnote.h" |
||||
#include "graphics/classicgraphicsmanager.h" |
||||
#include "core/timeline.h" |
||||
|
||||
class ClassicSprite; |
||||
|
||||
class ClassicSceneGraphicsManager : public ClassicGraphicsManager |
||||
{ |
||||
public: |
||||
explicit ClassicSceneGraphicsManager(const std::shared_ptr<Timeline<ClassicNote>>& timeline, |
||||
const std::shared_ptr<ClassicSpriteFactory>& factory, |
||||
const microsec& visibility_offset); |
||||
|
||||
virtual void display() const override; |
||||
virtual void update(const microsec& offset) override; |
||||
|
||||
virtual void display(const std::vector<ArrowElement>& elements) const override; |
||||
virtual void setGraphics(std::vector<ArrowElement>& elements, TimeRange&& range) override; |
||||
|
||||
protected: |
||||
using Iterator = Timeline<ClassicNote>::Iterator; |
||||
|
||||
Iterator _first; |
||||
Iterator _last; |
||||
|
||||
const std::shared_ptr<Timeline<ClassicNote>> _timeline; |
||||
|
||||
inline bool nothingToDraw() const noexcept; |
||||
inline bool isVisiblyClose(const Iterator& iterator, const microsec& music_offset) const noexcept; |
||||