bunch of stuff

This commit is contained in:
Noel Berry
2021-01-03 18:55:56 -08:00
parent 36182673ef
commit cdccb14f2e
26 changed files with 214 additions and 20 deletions

View File

@ -72,15 +72,18 @@ void Collider::set_cells(int x, int y, int w, int h, bool value)
bool Collider::check(uint32_t mask, Point offset) const
{
auto other = world()->first<Collider>();
while (other)
if (world())
{
if (other != this &&
(other->mask & mask) == mask &&
overlaps(other, offset))
return true;
auto other = world()->first<Collider>();
while (other)
{
if (other != this &&
(other->mask & mask) == mask &&
overlaps(other, offset))
return true;
other = (Collider*)other->next();
other = (Collider*)other->next();
}
}
return false;

10
src/components/enemy.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include "../world.h"
namespace TL
{
class Enemy : public Component
{
};
}

View File

@ -9,6 +9,7 @@ void Hurtable::update()
{
if (collider->check(hurt_by))
{
Time::pause_for(0.1f);
stun_timer = 0.5f;
flicker_timer = 0.5f;
on_hurt(this);

View File

@ -87,6 +87,10 @@ bool Mover::on_ground(int dist) const
void Mover::update()
{
// apply friction maybe
if (friction > 0 && on_ground())
speed.x = Calc::approach(speed.x, 0, friction * Time::delta);
// apply gravity
if (gravity != 0 && (!collider || !collider->check(Mask::solid, Point(0, 1))))
speed.y += gravity * Time::delta;

View File

@ -17,6 +17,7 @@ namespace TL
Collider* collider = nullptr;
Vec2 speed;
float gravity = 0;
float friction = 0;
std::function<void(Mover*)> on_hit_x;
std::function<void(Mover*)> on_hit_y;

View File

@ -68,6 +68,9 @@ void Player::update()
// START
if (m_state == st_start)
{
while (hitbox->check(Mask::solid))
entity()->position.y++;
anim->play("sword");
m_start_timer -= Time::delta;
if (m_start_timer <= 0)

View File

@ -14,8 +14,9 @@ namespace TL
static constexpr int st_attack = 1;
static constexpr int st_hurt = 2;
static constexpr int st_start = 3;
static constexpr int max_health = 3;
int health = 3;
int health = max_health;
VirtualStick input_move;
VirtualButton input_jump;