basic player movement

This commit is contained in:
Noel Berry
2021-01-02 17:05:12 -08:00
parent 4e05170023
commit c38b1e1418
11 changed files with 179 additions and 19 deletions

View File

@ -1,9 +1,8 @@
#include "game.h"
#include "content.h"
#include "masks.h"
#include "components/animator.h"
#include "components/collider.h"
#include "components/mover.h"
#include "factory.h"
using namespace TL;
@ -18,21 +17,21 @@ 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;
load_map();
}
void Game::load_map()
{
world.clear();
// add a test player
Factory::player(&world, Point(50, 50));
auto floor = world.add_entity(Point(0, 100));
auto c2 = floor->add(Collider::make_rect(RectI(0, 0, 320, 16)));
c2->mask = Mask::solid;
}
void Game::shutdown()
@ -44,6 +43,8 @@ void Game::update()
{
if (Input::pressed(Key::F1))
m_draw_colliders = !m_draw_colliders;
if (Input::pressed(Key::F2))
load_map();
world.update();
}