basic components

This commit is contained in:
Noel Berry
2021-01-02 16:20:01 -08:00
parent 8db43ce18e
commit 4e05170023
20 changed files with 636 additions and 9 deletions

View File

@ -1,5 +1,9 @@
#include "game.h"
#include "content.h"
#include "masks.h"
#include "components/animator.h"
#include "components/collider.h"
#include "components/mover.h"
using namespace TL;
@ -13,6 +17,22 @@ void Game::startup()
// set batcher to use Nearest Filter
batch.default_sampler = TextureSampler(TextureFilter::Nearest);
// add a test entity
auto en = world.add_entity(Point(100, 60));
auto an = en->add(Animator("player"));
auto col = en->add(Collider::make_rect(RectI(-4, -8, 8, 8)));
auto mover = en->add(Mover());
mover->collider = col;
mover->speed = Vec2(5, 20);
an->play("idle");
auto floor = world.add_entity(Point(50, 100));
auto c2 = floor->add(Collider::make_rect(RectI(0, 0, 100, 16)));
c2->mask = Mask::solid;
m_draw_colliders = true;
}
void Game::shutdown()
@ -22,16 +42,30 @@ void Game::shutdown()
void Game::update()
{
if (Input::pressed(Key::F1))
m_draw_colliders = !m_draw_colliders;
world.update();
}
void Game::render()
{
// draw gameplay stuff
{
buffer->clear(Color::red);
buffer->clear(0x4488aa);
world.render(batch);
if (m_draw_colliders)
{
auto collider = world.first<Collider>();
while (collider)
{
collider->render(batch);
collider = (Collider*)collider->next();
}
}
batch.str(Content::font, "Hello World", Vec2(32, 32), Color::white);
batch.render(buffer);
batch.clear();
}