townengine/apps/platformer/player.h

66 lines
1.2 KiB
C
Raw Normal View History

2024-07-08 00:44:20 +00:00
#ifndef PLAYER_H
#define PLAYER_H
#include "twn_game_api.h"
2024-07-08 00:44:20 +00:00
typedef struct World World;
2024-07-08 00:44:20 +00:00
typedef enum PlayerAction {
2024-07-08 00:44:20 +00:00
PLAYER_ACTION_GROUND,
PLAYER_ACTION_FALL,
PLAYER_ACTION_JUMP,
} PlayerAction;
2024-07-08 00:44:20 +00:00
typedef struct Player {
World *world;
2024-07-08 00:44:20 +00:00
/* visual */
float sprite_w;
float sprite_h;
/* body */
Rect rect;
2024-07-08 00:44:20 +00:00
/* state */
PlayerAction action;
2024-07-08 00:44:20 +00:00
/* physics */
Rect collider_x;
Rect collider_y;
2024-07-08 00:44:20 +00:00
int collider_thickness;
float dx;
float dy;
float max_dx;
float run_horizontal_speed;
float horizontal_damping;
float current_gravity_multiplier;
float terminal_velocity;
/* jumping */
float jump_force_initial;
float jump_force_increase; /* aka "jump power", increment of dy per tick */
int jump_air_ticks;
int jump_air_timer;
int jump_coyote_ticks;
int jump_coyote_timer;
int jump_buffer_ticks;
int jump_buffer_timer;
/* gravity multipliers */
float jump_default_multiplier;
float jump_boosted_multiplier;
float jump_corner_correction_offset; /* from center */
} Player;
2024-07-08 00:44:20 +00:00
Player *player_create(World *world);
void player_destroy(Player *player);
void player_calc(Player *player);
2024-07-08 00:44:20 +00:00
#endif