moved input code to player.c
This commit is contained in:
parent
30c1e780a1
commit
6cc16cf1f8
36
src/player.c
36
src/player.c
|
@ -1,8 +1,25 @@
|
|||
#include "player.h"
|
||||
#include "debug.h"
|
||||
#include "program.h"
|
||||
#include "rigidbody.h"
|
||||
#include "input.h"
|
||||
|
||||
static Vector directional = ZeroVector;
|
||||
|
||||
static
|
||||
void player_input_h(int val) {
|
||||
directional.x = val * 0.1f;
|
||||
}
|
||||
static
|
||||
void player_input_v(int val) {
|
||||
directional.y = -val * 0.1f;
|
||||
}
|
||||
|
||||
void player_spawn(Player* self, Vector at) {
|
||||
self->transform.position = at;
|
||||
input_add_axis_action(SDL_SCANCODE_A, SDL_SCANCODE_D, &player_input_h);
|
||||
input_add_axis_action(SDL_SCANCODE_S, SDL_SCANCODE_W, &player_input_v);
|
||||
|
||||
}
|
||||
|
||||
void player_start(Player* self) {
|
||||
|
@ -10,11 +27,14 @@ void player_start(Player* self) {
|
|||
}
|
||||
|
||||
void player_update(Player* self, float dt) {
|
||||
|
||||
Vector velocity = rigidbody_get_velocity(self->rigidbody);
|
||||
ASSERT_RETURN(!visnanf(velocity),, "Velocity is NaN (2)");
|
||||
velocity = vmovetowardsf(velocity, vmulff(directional, 100.f), 10000.f * dt);
|
||||
ASSERT_RETURN(!visnanf(velocity),, "Velocity is NaN (3)");
|
||||
rigidbody_set_velocity(self->rigidbody, velocity);
|
||||
}
|
||||
|
||||
void player_collision(Player* self, Collision hit) {
|
||||
LOG_INFO("AAAAA %p", hit.other.data);
|
||||
}
|
||||
|
||||
Sprite* player_get_sprite(Player* self) {
|
||||
|
@ -32,15 +52,3 @@ RigidBody* player_get_rigidbody(Player* self) {
|
|||
Shape* player_get_shape(Player* self) {
|
||||
return self->shape;
|
||||
}
|
||||
|
||||
Vector* player_get_position(Player* self) {
|
||||
return &self->transform.position;
|
||||
}
|
||||
|
||||
Vector* player_get_scale(Player* self) {
|
||||
return &self->transform.scale;
|
||||
}
|
||||
|
||||
float* player_get_rotation(Player* self) {
|
||||
return &self->transform.rotation;
|
||||
}
|
||||
|
|
|
@ -28,15 +28,8 @@ extern Transform* player_get_transform(Player* self);
|
|||
extern RigidBody* player_get_rigidbody(Player* self);
|
||||
extern Shape* player_get_shape(Player* self);
|
||||
|
||||
extern Vector* player_get_position(Player* self);
|
||||
extern Vector* player_get_scale(Player* self);
|
||||
extern float* player_get_rotation(Player* self);
|
||||
|
||||
impl_Transformable_for(Player,
|
||||
player_get_transform,
|
||||
player_get_position,
|
||||
player_get_scale,
|
||||
player_get_rotation
|
||||
player_get_transform
|
||||
)
|
||||
|
||||
impl_SpriteEntity_for(Player,
|
||||
|
|
Loading…
Reference in a new issue