forked from NaiJi/project-kyoku
Implement states
parent
d9788b31b8
commit
5b7076ac1c
@ -0,0 +1,45 @@
|
||||
#include "classicnoteactivestate.h"
|
||||
#include "../classicnote.h"
|
||||
#include "../classicsprite.h"
|
||||
|
||||
auto ClassicNoteActiveState::value() const -> Value
|
||||
{
|
||||
return Value::ACTIVE;
|
||||
}
|
||||
|
||||
auto ClassicNoteActiveState::update(const ClassicNote* note, const microsec& offset) -> Value
|
||||
{
|
||||
float i;
|
||||
auto update_time = offset - note->getApearanceTime(); // This all will be inside ::update
|
||||
i = update_time / note->getOneTrailPercent() * 0.01; // of an animation object
|
||||
|
||||
const auto& coordinates = note->getCoordinates();
|
||||
const auto& sprite = note->sprite();
|
||||
float xa = getPt( coordinates.x + 20. , coordinates.x + 90. , i );
|
||||
float ya = getPt( coordinates.y - 600. , coordinates.y - 150. , i );
|
||||
float xb = getPt( coordinates.x + 90. , coordinates.x , i );
|
||||
float yb = getPt( coordinates.y - 150. , coordinates.y , i );
|
||||
|
||||
sprite->update(getPt( xa , xb , i ), getPt( ya , yb , i ));
|
||||
if (i >= 1)
|
||||
{
|
||||
sprite->trailFade();
|
||||
}
|
||||
|
||||
if (!note->isActive(offset))
|
||||
return Value::DYING;
|
||||
|
||||
return value();
|
||||
}
|
||||
|
||||
constexpr int ClassicNoteActiveState::getPt(float n1, float n2, float perc) const
|
||||
{
|
||||
float diff = n2 - n1;
|
||||
return n1 + (diff * perc);
|
||||
}
|
||||
|
||||
void ClassicNoteActiveState::onEntering(const ClassicNote* note)
|
||||
{
|
||||
(void)note;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
#ifndef CLASSICNOTEACTIVESTATE_H
|
||||
#define CLASSICNOTEACTIVESTATE_H
|
||||
|
||||
#include "classicnotestate.h"
|
||||
|
||||
class ClassicNoteActiveState : public ClassicNoteState
|
||||
{
|
||||
public:
|
||||
virtual Value value() const override;
|
||||
virtual Value update(const ClassicNote* note, const microsec& offset) override;
|
||||
virtual void onEntering(const ClassicNote* note) override;
|
||||
|
||||
private:
|
||||
inline constexpr int getPt(float n1 , float n2 , float perc) const;
|
||||
};
|
||||
|
||||
#endif // CLASSICNOTEACTIVESTATE_H
|
@ -0,0 +1,26 @@
|
||||
#include "classicnotedyingstate.h"
|
||||
#include "../classicnote.h"
|
||||
#include "../classicsprite.h"
|
||||
|
||||
auto ClassicNoteDyingState::value() const -> Value
|
||||
{
|
||||
return Value::DYING;
|
||||
}
|
||||
|
||||
auto ClassicNoteDyingState::update(const ClassicNote* note, const microsec& offset) -> Value
|
||||
{
|
||||
(void) offset;
|
||||
const auto& sprite = note->sprite();
|
||||
|
||||
sprite->update();
|
||||
if (sprite->isDead())
|
||||
return Value::NONE;
|
||||
|
||||
return value();
|
||||
}
|
||||
|
||||
void ClassicNoteDyingState::onEntering(const ClassicNote* note)
|
||||
{
|
||||
note->sprite()->pulse();
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
#ifndef CLASSICNOTEDYINGSTATE_H
|
||||
#define CLASSICNOTEDYINGSTATE_H
|
||||
|
||||
#include "classicnotestate.h"
|
||||
|
||||
class ClassicNoteDyingState : public ClassicNoteState
|
||||
{
|
||||
public:
|
||||
virtual Value value() const override;
|
||||
virtual Value update(const ClassicNote* note, const microsec& offset) override;
|
||||
virtual void onEntering(const ClassicNote* note) override;
|
||||
};
|
||||
|
||||
#endif // CLASSICNOTEDYINGSTATE_H
|
@ -0,0 +1,49 @@
|
||||
#include "classicnoteflyingstate.h"
|
||||
#include "../classicnote.h"
|
||||
#include "../classicsprite.h"
|
||||
|
||||
auto ClassicNoteFlyingState::value() const -> Value
|
||||
{
|
||||
return Value::FLYING;
|
||||
}
|
||||
|
||||
auto ClassicNoteFlyingState::update(const ClassicNote* note, const microsec& offset) -> Value
|
||||
{
|
||||
float i;
|
||||
auto update_time = offset - note->getApearanceTime(); // This all will be inside ::update
|
||||
i = update_time / note->getOneTrailPercent() * 0.01; // of an animation object
|
||||
|
||||
const auto& coordinates = note->getCoordinates();
|
||||
const auto& sprite = note->sprite();
|
||||
float xa = getPt( coordinates.x + 20. , coordinates.x + 90. , i );
|
||||
float ya = getPt( coordinates.y - 600. , coordinates.y - 150. , i );
|
||||
float xb = getPt( coordinates.x + 90. , coordinates.x , i );
|
||||
float yb = getPt( coordinates.y - 150. , coordinates.y , i );
|
||||
|
||||
sprite->update(getPt( xa , xb , i ), getPt( ya , yb , i ));
|
||||
if (i >= 1)
|
||||
{
|
||||
sprite->trailFade();
|
||||
}
|
||||
|
||||
if (note->isActive(offset))
|
||||
return Value::ACTIVE;
|
||||
|
||||
return value();
|
||||
}
|
||||
|
||||
constexpr int ClassicNoteFlyingState::getPt(float n1, float n2, float perc) const
|
||||
{
|
||||
float diff = n2 - n1;
|
||||
return n1 + (diff * perc);
|
||||
}
|
||||
|
||||
void ClassicNoteFlyingState::onEntering(const ClassicNote* note)
|
||||
{
|
||||
const auto& coordinates = note->getCoordinates();
|
||||
const auto& sprite = note->sprite();
|
||||
|
||||
sprite->setCoordinates(coordinates.x, coordinates.y,
|
||||
coordinates.x + 20, coordinates.y - 600);
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
#ifndef CLASSICNOTEFLYINGSTATE_H
|
||||
#define CLASSICNOTEFLYINGSTATE_H
|
||||
|
||||
#include "classicnotestate.h"
|
||||
|
||||
class ClassicNoteFlyingState : public ClassicNoteState
|
||||
{
|
||||
public:
|
||||
virtual Value value() const override;
|
||||
virtual Value update(const ClassicNote* note, const microsec& offset) override;
|
||||
virtual void onEntering(const ClassicNote* note) override;
|
||||
|
||||
private:
|
||||
inline constexpr int getPt(float n1 , float n2 , float perc) const;
|
||||
};
|
||||
|
||||
#endif // CLASSICNOTEFLYINGSTATE_H
|
@ -0,0 +1,20 @@
|
||||
#include "classicnotenonestate.h"
|
||||
#include "../classicnote.h"
|
||||
#include "../classicsprite.h"
|
||||
|
||||
auto ClassicNoteNoneState::value() const -> Value
|
||||
{
|
||||
return Value::NONE;
|
||||
}
|
||||
|
||||
auto ClassicNoteNoneState::update(const ClassicNote* note, const microsec& offset) -> Value
|
||||
{
|
||||
(void) offset;
|
||||
(void) note;
|
||||
}
|
||||
|
||||
void ClassicNoteNoneState::onEntering(const ClassicNote* note)
|
||||
{
|
||||
note->sprite()->reset();
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
#ifndef CLASSICNOTENONESTATE_H
|
||||
#define CLASSICNOTENONESTATE_H
|
||||
|
||||
#include "classicnotestate.h"
|
||||
|
||||
class ClassicNoteNoneState : public ClassicNoteState
|
||||
{
|
||||
public:
|
||||
virtual Value value() const override;
|
||||
virtual Value update(const ClassicNote* note, const microsec& offset) override;
|
||||
virtual void onEntering(const ClassicNote* note) override;
|
||||
};
|
||||
|
||||
#endif // CLASSICNOTENONESTATE_H
|
Loading…
Reference in New Issue