mirror of
https://github.com/NoelFB/tiny_link.git
synced 2025-07-01 19:45:27 +08:00
more rooms and enemies!
This commit is contained in:
@ -1,17 +1,29 @@
|
||||
#include "hurtable.h"
|
||||
#include "animator.h"
|
||||
|
||||
using namespace TL;
|
||||
|
||||
void Hurtable::update()
|
||||
{
|
||||
if (collider && on_hurt && m_cooldown_timer <= 0)
|
||||
if (collider && on_hurt && stun_timer <= 0)
|
||||
{
|
||||
if (collider->check(hurt_by))
|
||||
{
|
||||
m_cooldown_timer = cooldown;
|
||||
stun_timer = 0.5f;
|
||||
flicker_timer = 0.5f;
|
||||
on_hurt(this);
|
||||
}
|
||||
}
|
||||
|
||||
m_cooldown_timer -= Time::delta;
|
||||
stun_timer -= Time::delta;
|
||||
|
||||
if (flicker_timer > 0)
|
||||
{
|
||||
flicker_timer -= Time::delta;
|
||||
|
||||
if (Time::on_interval(0.05f))
|
||||
entity()->visible = !entity()->visible;
|
||||
if (flicker_timer <= 0)
|
||||
entity()->visible = true;
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,11 @@ namespace TL
|
||||
{
|
||||
class Hurtable : public Component
|
||||
{
|
||||
private:
|
||||
float m_cooldown_timer = 0;
|
||||
|
||||
public:
|
||||
float stun_timer = 0;
|
||||
float flicker_timer = 0;
|
||||
Collider* collider = nullptr;
|
||||
uint32_t hurt_by = 0;
|
||||
float cooldown = 1.0f;
|
||||
std::function<void(Hurtable* self)> on_hurt;
|
||||
|
||||
void update() override;
|
||||
|
@ -13,7 +13,10 @@ bool Mover::move_x(int amount)
|
||||
{
|
||||
if (collider->check(Mask::solid, Point(sign, 0)))
|
||||
{
|
||||
stop_x();
|
||||
if (on_hit_x)
|
||||
on_hit_x(this);
|
||||
else
|
||||
stop_x();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -37,7 +40,10 @@ bool Mover::move_y(int amount)
|
||||
{
|
||||
if (collider->check(Mask::solid, Point(0, sign)))
|
||||
{
|
||||
stop_y();
|
||||
if (on_hit_y)
|
||||
on_hit_y(this);
|
||||
else
|
||||
stop_y();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../world.h"
|
||||
#include "collider.h"
|
||||
#include <blah.h>
|
||||
#include <functional>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
@ -16,6 +17,8 @@ namespace TL
|
||||
Collider* collider = nullptr;
|
||||
Vec2 speed;
|
||||
float gravity = 0;
|
||||
std::function<void(Mover*)> on_hit_x;
|
||||
std::function<void(Mover*)> on_hit_y;
|
||||
|
||||
bool move_x(int amount);
|
||||
bool move_y(int amount);
|
||||
|
@ -65,8 +65,16 @@ void Player::update()
|
||||
anim->scale.x = Calc::abs(anim->scale.x) * m_facing;
|
||||
}
|
||||
|
||||
// START
|
||||
if (m_state == st_start)
|
||||
{
|
||||
anim->play("sword");
|
||||
m_start_timer -= Time::delta;
|
||||
if (m_start_timer <= 0)
|
||||
m_state = st_normal;
|
||||
}
|
||||
// NORMAL STATE
|
||||
if (m_state == st_normal)
|
||||
else if (m_state == st_normal)
|
||||
{
|
||||
// Current Animation
|
||||
if (m_on_ground)
|
||||
|
@ -13,6 +13,7 @@ namespace TL
|
||||
static constexpr int st_normal = 0;
|
||||
static constexpr int st_attack = 1;
|
||||
static constexpr int st_hurt = 2;
|
||||
static constexpr int st_start = 3;
|
||||
|
||||
int health = 3;
|
||||
|
||||
@ -24,12 +25,13 @@ namespace TL
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
int m_state = st_normal;
|
||||
int m_state = st_start;
|
||||
int m_facing = 1;
|
||||
float m_jump_timer = 0;
|
||||
float m_attack_timer = 0;
|
||||
float m_hurt_timer = 0;
|
||||
float m_invincible_timer = 0;
|
||||
float m_start_timer = 1;
|
||||
Collider* m_attack_collider = nullptr;
|
||||
bool m_on_ground;
|
||||
};
|
||||
|
Reference in New Issue
Block a user