mirror of
https://github.com/NoelFB/tiny_link.git
synced 2025-07-01 19:45:27 +08:00
simple level loading
This commit is contained in:
@ -55,7 +55,7 @@ void Animator::render(Batch& batch)
|
||||
if (in_valid_state())
|
||||
{
|
||||
batch.push_matrix(
|
||||
Mat3x2::create_transform(entity()->position, m_sprite->origin, Vec2::one, 0));
|
||||
Mat3x2::create_transform(entity()->position, m_sprite->origin, scale, 0));
|
||||
|
||||
auto& anim = m_sprite->animations[m_animation_index];
|
||||
auto& frame = anim.frames[m_frame_index];
|
||||
|
@ -16,6 +16,7 @@ namespace TL
|
||||
float m_frame_counter = 0;
|
||||
|
||||
public:
|
||||
Vec2 scale = Vec2::one;
|
||||
|
||||
Animator() = default;
|
||||
Animator(const String& sprite);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "player.h"
|
||||
#include "mover.h"
|
||||
#include "animator.h"
|
||||
|
||||
using namespace TL;
|
||||
|
||||
@ -34,31 +35,50 @@ void Player::update()
|
||||
input_jump.update();
|
||||
|
||||
auto mover = get<Mover>();
|
||||
auto on_ground = mover->on_ground();
|
||||
auto anim = get<Animator>();
|
||||
auto was_on_ground = m_on_ground;
|
||||
m_on_ground = mover->on_ground();
|
||||
int input = input_move.value_i().x;
|
||||
|
||||
// Sprite Stuff
|
||||
{
|
||||
// land squish
|
||||
if (!was_on_ground && m_on_ground)
|
||||
anim->scale = Vec2(facing * 1.5f, 0.7f);
|
||||
|
||||
// lerp scale back to one
|
||||
anim->scale = Calc::approach(anim->scale, Vec2(facing, 1.0f), Time::delta * 4);
|
||||
|
||||
// set facing
|
||||
anim->scale.x = Calc::abs(anim->scale.x) * facing;
|
||||
}
|
||||
|
||||
// Horizontal Movement
|
||||
{
|
||||
|
||||
// Acceleration
|
||||
mover->speed.x += input * (on_ground ? ground_accel : air_accel) * Time::delta;
|
||||
mover->speed.x += input * (m_on_ground ? ground_accel : air_accel) * Time::delta;
|
||||
|
||||
// Maxspeed
|
||||
auto maxspd = (on_ground ? max_ground_speed : max_air_speed);
|
||||
auto maxspd = (m_on_ground ? max_ground_speed : max_air_speed);
|
||||
if (Calc::abs(mover->speed.x) > maxspd)
|
||||
{
|
||||
mover->speed.x = Calc::approach(
|
||||
mover->speed.x,
|
||||
mover->speed.x,
|
||||
Calc::sign(mover->speed.x) * maxspd,
|
||||
2000 * Time::delta);
|
||||
}
|
||||
|
||||
if (input == 0 && on_ground)
|
||||
// Friction
|
||||
if (input == 0 && m_on_ground)
|
||||
mover->speed.x = Calc::approach(mover->speed.x, 0, friction * Time::delta);
|
||||
|
||||
// Facing Direction
|
||||
if (input != 0 && m_on_ground)
|
||||
facing = input;
|
||||
}
|
||||
|
||||
// Gravity
|
||||
if (!on_ground)
|
||||
if (!m_on_ground)
|
||||
{
|
||||
float grav = gravity;
|
||||
if (Calc::abs(mover->speed.y) < 20 && input_jump.down())
|
||||
@ -71,6 +91,7 @@ void Player::update()
|
||||
{
|
||||
if (input_jump.pressed() && mover->on_ground())
|
||||
{
|
||||
anim->scale = Vec2(facing * 0.65f, 1.4f);
|
||||
mover->speed.x = input * max_air_speed;
|
||||
m_jump_timer = jump_time;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ namespace TL
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
int facing = 1;
|
||||
float m_jump_timer = 0;
|
||||
bool m_on_ground;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user