NoteTile create
This commit is contained in:
parent
607edc1d48
commit
e429118bc9
3 changed files with 54 additions and 0 deletions
1
SimpleGame/src/Include/NotePlaceEnum.hpp
Normal file
1
SimpleGame/src/Include/NotePlaceEnum.hpp
Normal file
|
@ -0,0 +1 @@
|
|||
enum NotePlaceEnum { Left, Middle, Right };
|
28
SimpleGame/src/Include/NoteTile.hpp
Normal file
28
SimpleGame/src/Include/NoteTile.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <NotePlaceEnum.hpp>
|
||||
#include <SFML/Graphics/StencilMode.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class NoteTile {
|
||||
private:
|
||||
static std::vector<std::unique_ptr<NoteTile>> existing_tiles;
|
||||
// logic things
|
||||
float play_time;
|
||||
float good_interval;
|
||||
NotePlaceEnum place;
|
||||
// used for Graphics
|
||||
sf::Vector2f position;
|
||||
// probably some tileSprite class here in the future <-
|
||||
|
||||
// Constructor private, use create to create
|
||||
NoteTile(float play_time, float good_interval, NotePlaceEnum place);
|
||||
|
||||
public:
|
||||
// Good key press for this note, is if player press good place, within
|
||||
// [play_time - good_interval/2, play_time + good_interval/2]
|
||||
static void create(float play_time, float good_interval, NotePlaceEnum place);
|
||||
// Should be called when one of arrows key pressed, return True if it's a good
|
||||
// press
|
||||
bool CheckPress(float press_time, NotePlaceEnum key_pressed);
|
||||
};
|
25
SimpleGame/src/Source/NoteTile.cpp
Normal file
25
SimpleGame/src/Source/NoteTile.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "NoteTile.hpp"
|
||||
|
||||
std::vector<std::unique_ptr<NoteTile>> NoteTile::existing_tiles;
|
||||
|
||||
// private
|
||||
NoteTile::NoteTile(float play_time, float good_interval, NotePlaceEnum place)
|
||||
: play_time(play_time), good_interval(good_interval), place(place) {
|
||||
NoteTile::existing_tiles.push_back(std::unique_ptr<NoteTile>(this));
|
||||
}
|
||||
|
||||
// public
|
||||
void NoteTile::create(float play_time, float good_interval,
|
||||
NotePlaceEnum place) {
|
||||
NoteTile(play_time, good_interval, place);
|
||||
}
|
||||
|
||||
bool NoteTile::CheckPress(float press_time, NotePlaceEnum) {
|
||||
for (const auto ¬e_tile : NoteTile::existing_tiles) {
|
||||
if (note_tile->play_time - note_tile->good_interval / 2 < press_time &&
|
||||
note_tile->play_time + note_tile->good_interval / 2 > press_time) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue