chore(format): Geany did some automatic formatting

This commit is contained in:
Sara 2023-11-23 18:35:27 +01:00
parent 08a5befc82
commit dd0af050c9

View file

@ -2,24 +2,17 @@
#include "debug.h" #include "debug.h"
#include "game_world.h" #include "game_world.h"
static inline static inline void InternalPlayerInitInput(Player* self)
void InternalPlayerInitInput(Player* self) { {
// HORIZONTAL // HORIZONTAL
playerinput_add(self->input, CompositeAxis1D_as_InputAxis(compositeaxis1d_new( playerinput_add(self->input, CompositeAxis1D_as_InputAxis(compositeaxis1d_new(KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_A)), KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_D)), InputEvent_Float)), (InputDelegateFn)PlayerInputHorizontal);
KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_A)),
KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_D)),
InputEvent_Float
)), (InputDelegateFn)PlayerInputHorizontal);
// VERTICAL // VERTICAL
playerinput_add(self->input, CompositeAxis1D_as_InputAxis(compositeaxis1d_new( playerinput_add(self->input, CompositeAxis1D_as_InputAxis(compositeaxis1d_new(KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_S)), KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_W)), InputEvent_Float)), (InputDelegateFn)PlayerInputVertical);
KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_S)),
KeyBind_as_InputAxis(keybind_new(SDL_SCANCODE_W)),
InputEvent_Float
)), (InputDelegateFn)PlayerInputVertical);
} }
Player* MakePlayer() { Player* MakePlayer()
{
Player* self = malloc(sizeof(Player)); Player* self = malloc(sizeof(Player));
ASSERT_RETURN(self != NULL, NULL, "Could not allocate enough space for Player instance"); ASSERT_RETURN(self != NULL, NULL, "Could not allocate enough space for Player instance");
@ -34,21 +27,21 @@ Player* MakePlayer() {
.faceDirection = 0, .faceDirection = 0,
.animationStateMachine = state_machine_init(self, PlayerIdle()), .animationStateMachine = NULL,
.animFrame = 0,
.animFrameInterval = 1.0f / 4.0f,
.animFrameTimer = 0.0f,
.stand = idle, .idle = animation_sprite_new(idle, 4.0f),
.walk = walk, .walk = animation_sprite_new(walk, 4.0f),
.sprite = sprite_from_spritesheet(walk, 0), .current_anim = self->idle
}; };
self->animationStateMachine = state_machine_init(self, PlayerIdle());
return self; return self;
} }
Player* SpawnPlayer(Vector location) { Player* SpawnPlayer(Vector location)
{
Player* self = MakePlayer(); Player* self = MakePlayer();
self->transform.position = location; self->transform.position = location;
game_world_add_entity(Player_as_BehaviourEntity(self)); game_world_add_entity(Player_as_BehaviourEntity(self));
@ -57,53 +50,42 @@ Player* SpawnPlayer(Vector location) {
void PlayerStart(Player* self) { } void PlayerStart(Player* self) { }
void PlayerUpdate(Player* self, float deltaTime) { void PlayerUpdate(Player* self, float deltaTime)
{
state_machine_update(self->animationStateMachine, deltaTime); state_machine_update(self->animationStateMachine, deltaTime);
} }
void PlayerDestroy(Player* self) { void PlayerDestroy(Player* self)
{
state_machine_destroy(self->animationStateMachine); state_machine_destroy(self->animationStateMachine);
spritesheet_destroy(self->walk);
spritesheet_destroy(self->stand); animation_sprite_destroy(self->idle);
sprite_destroy(self->sprite); animation_sprite_destroy(self->walk);
} }
void PlayerDraw(Player* self) { void PlayerDraw(Player* self)
sprite_entity_draw(Player_as_SpriteEntity(self)); {
animation_sprite_draw(self->current_anim, &self->transform);
} }
void PlayerInputHorizontal(Player* self, InputEvent event) { } void PlayerInputHorizontal(Player* self, InputEvent event) { }
void PlayerInputVertical(Player* self, InputEvent event) { } void PlayerInputVertical(Player* self, InputEvent event) { }
Sprite* PlayerGetSprite(Player* self) { Transform* PlayerGetTransform(Player* self)
return self->sprite; {
}
Transform* PlayerGetTransform(Player* self) {
return &self->transform; return &self->transform;
} }
const State* PlayerAnimationUpdate(Player* self, float deltaTime) {
self->animFrameTimer += deltaTime;
if (self->animFrameTimer > self->animFrameInterval) {
self->animFrameTimer = 0.f;
++self->animFrame;
size_t nextFrame = self->animFrame * 8 + self->faceDirection;
sprite_set_tile(self->sprite, nextFrame);
}
return state_machine_get_current_state(self->animationStateMachine);
}
void PlayerAnimationExit(Player* self) { } void PlayerAnimationExit(Player* self) { }
void PlayerIdleEnter(Player* self) { void PlayerIdleEnter(Player* self)
self->sprite = sprite_from_spritesheet(self->stand, 0); {
self->current_anim = self->idle;
animation_sprite_play_from(self->current_anim, 0.f);
} }
const State* PlayerIdleUpdate(Player* self, float deltaTime) { const State* PlayerIdleUpdate(Player* self, float deltaTime)
PlayerAnimationUpdate(self, deltaTime); {
return PlayerIdle(); return PlayerIdle();
} }