it's done!!!

This commit is contained in:
Noel Berry 2021-01-03 21:54:18 -08:00
parent f721b86bb9
commit fc57d2e47c
7 changed files with 51 additions and 10 deletions

View File

@ -6,6 +6,7 @@
#include "orb.h"
#include "../masks.h"
#include "../factory.h"
#include "../game.h"
using namespace TL;
@ -183,8 +184,13 @@ void GhostFrog::update()
{
if (Vec2(orb->entity()->position - orb->target()).length() < 16)
{
auto sign = Calc::sign(orb->entity()->position.x - x);
if (sign != 0)
m_facing = sign;
anim->play("reflect");
orb->on_hit();
m_reflect_count++;
m_timer = 0;
}
@ -195,7 +201,7 @@ void GhostFrog::update()
{
Factory::pop(world(), entity()->position + Point(0, -8));
orb->entity()->destroy();
on_hurt(nullptr);
get<Hurtable>()->hurt();
m_timer = 0;
}
}
@ -205,6 +211,7 @@ void GhostFrog::update()
else if (m_state == st_dead_state)
{
anim->play("dead");
world()->game->shake(1.0f);
if (Time::on_interval(0.25f))
{
@ -219,6 +226,7 @@ void GhostFrog::update()
Factory::pop(world(), entity()->position + Point(x * 12, -8 + y * 12));
Time::pause_for(0.3f);
world()->game->shake(0.1f);
entity()->destroy();
}
}

View File

@ -3,17 +3,20 @@
using namespace TL;
void Hurtable::update()
{
if (collider && on_hurt && stun_timer <= 0)
{
if (collider->check(hurt_by))
void Hurtable::hurt()
{
Time::pause_for(0.1f);
stun_timer = 0.5f;
flicker_timer = 0.5f;
on_hurt(this);
}
void Hurtable::update()
{
if (collider && on_hurt && stun_timer <= 0)
{
if (collider->check(hurt_by))
hurt();
}
stun_timer -= Time::delta;

View File

@ -17,6 +17,7 @@ namespace TL
uint32_t hurt_by = 0;
std::function<void(Hurtable* self)> on_hurt;
void hurt();
void update() override;
};
}

View File

@ -14,7 +14,7 @@ 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 = 30;
static constexpr int max_health = 4;
int health = max_health;

View File

@ -18,6 +18,8 @@ namespace
void Game::startup()
{
world.game = this;
// load our content
Content::load();
@ -29,7 +31,7 @@ void Game::startup()
m_draw_colliders = false;
// load first room
load_room(Point(12, 0));
load_room(Point(0, 0));
camera = Vec2(room.x * width, room.y * height);
}
@ -154,6 +156,7 @@ void Game::shutdown()
void Game::update()
{
// Toggle Collider Render
if (Input::pressed(Key::F1))
m_draw_colliders = !m_draw_colliders;
@ -169,8 +172,23 @@ void Game::update()
// Normal Update
if (!m_transition)
{
// Screen Shake
m_shake_timer -= Time::delta;
if (m_shake_timer > 0)
{
if (Time::on_interval(0.05f))
{
m_shake.x = Calc::rand_int(0, 2) == 0 ? -1 : 1;
m_shake.y = Calc::rand_int(0, 2) == 0 ? -1 : 1;
}
}
else
m_shake = Point::zero;
// Upodate Objects
world.update();
// Check for transition / death
auto player = world.first<Player>();
if (player)
{
@ -281,7 +299,7 @@ void Game::render()
buffer->clear(0x150e22);
// push camera offset
batch.push_matrix(Mat3x2::create_translation(-camera));
batch.push_matrix(Mat3x2::create_translation(-camera + m_shake));
// draw gameplay objects
world.render(batch);
@ -364,3 +382,8 @@ void Game::render()
batch.clear();
}
}
void Game::shake(float time)
{
m_shake_timer = time;
}

View File

@ -31,6 +31,7 @@ namespace TL
void shutdown();
void update();
void render();
void shake(float time);
private:
bool m_draw_colliders;
@ -39,5 +40,7 @@ namespace TL
Point m_next_room;
Point m_last_room;
Vector<Entity*> m_last_entities;
Point m_shake;
float m_shake_timer = 0;
};
}

View File

@ -3,6 +3,7 @@
namespace TL
{
class Game;
class World;
class Entity;
@ -110,6 +111,8 @@ namespace TL
public:
static constexpr int max_component_types = 256;
Game* game;
World() = default;
World(const World&) = delete;
World(World&&) = delete;