Compare commits

..

4 Commits

2 changed files with 17 additions and 26 deletions

View File

@ -593,7 +593,6 @@ void TELY_DLL_Init(void *user_data)
entity->flags |= FP_GameEntityFlag_Clickable; entity->flags |= FP_GameEntityFlag_Clickable;
entity->flags |= FP_GameEntityFlag_MoveByKeyboard; entity->flags |= FP_GameEntityFlag_MoveByKeyboard;
entity->flags |= FP_GameEntityFlag_MoveByMouse; entity->flags |= FP_GameEntityFlag_MoveByMouse;
entity->flags |= FP_GameEntityFlag_MoveByGamepad;
entity->flags |= FP_GameEntityFlag_NonTraversable; entity->flags |= FP_GameEntityFlag_NonTraversable;
entity->facing_left = true; entity->facing_left = true;
game->clicked_entity = entity->handle; game->clicked_entity = entity->handle;
@ -653,7 +652,6 @@ void TELY_DLL_Init(void *user_data)
entity->flags |= FP_GameEntityFlag_Clickable; entity->flags |= FP_GameEntityFlag_Clickable;
entity->flags |= FP_GameEntityFlag_MoveByKeyboard; entity->flags |= FP_GameEntityFlag_MoveByKeyboard;
entity->flags |= FP_GameEntityFlag_MoveByMouse; entity->flags |= FP_GameEntityFlag_MoveByMouse;
entity->flags |= FP_GameEntityFlag_MoveByGamepad;
entity->flags |= FP_GameEntityFlag_MobSpawner; entity->flags |= FP_GameEntityFlag_MobSpawner;
entity->spawn_cap = 1; entity->spawn_cap = 1;
} }
@ -699,13 +697,12 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
dir_vector.x = +1.f; dir_vector.x = +1.f;
// NOTE: Gamepad movement input // NOTE: Gamepad movement input
// NOTE: button_codes 0 should be the first gamepad connected, we can for (uint32_t gamepad = 0; gamepad < MAX_GAMEPADS; gamepad++) {
// get this working with other gamepads later
uint32_t gamepad = 0;
if (input->button_codes[gamepad]) { if (input->button_codes[gamepad]) {
dir_vector.x += input->left_stick[gamepad].x; dir_vector.x += input->left_stick[gamepad].x;
dir_vector.y += input->left_stick[gamepad].y; dir_vector.y += input->left_stick[gamepad].y;
} }
}
if (dir_vector.x && dir_vector.y) { if (dir_vector.x && dir_vector.y) {
dir_vector.x *= 0.7071067811865475244f; dir_vector.x *= 0.7071067811865475244f;
@ -724,11 +721,11 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
FP_GameEntity *entity = it.entity; FP_GameEntity *entity = it.entity;
entity->alive_time_s += input->delta_s; entity->alive_time_s += input->delta_s;
// NOTE: Move entity by keyboard and gamepad =============================================== // NOTE: Move entity by keyboard ===========================================================
Dqn_V2 acceleration = {}; Dqn_V2 acceleration = {};
if (game->clicked_entity == entity->handle && if (game->clicked_entity == entity->handle &&
(entity->action.state == FP_GameEntityState_Run || entity->action.state == FP_GameEntityState_Idle)) { (entity->action.state == FP_GameEntityState_Run || entity->action.state == FP_GameEntityState_Idle)) {
if (entity->flags & (FP_GameEntityFlag_MoveByKeyboard || FP_GameEntityFlag_MoveByGamepad)) { if (entity->flags & FP_GameEntityFlag_MoveByKeyboard) {
acceleration = dir_vector * 10000000.f; acceleration = dir_vector * 10000000.f;
if (dir_vector.x) if (dir_vector.x)
entity->facing_left = dir_vector.x < 0.f; entity->facing_left = dir_vector.x < 0.f;
@ -917,8 +914,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
if (action->flags & FP_GameEntityActionFlag_StateTransition) { if (action->flags & FP_GameEntityActionFlag_StateTransition) {
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, action_to_anim_mapping); FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, action_to_anim_mapping);
} else if (we_are_clicked_entity) { } else if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) {
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackA); FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackA);
} else if (dir_vector.x || dir_vector.y) { } else if (dir_vector.x || dir_vector.y) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_Run); FP_Game_EntityActionSetState(action, FP_GameEntityState_Run);
@ -934,8 +930,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
} else if (action_has_finished) { } else if (action_has_finished) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle); FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle);
} else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) { } else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) {
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
Dqn_f32 t01 = action->timer_s / action->end_at_s; Dqn_f32 t01 = action->timer_s / action->end_at_s;
if (t01 > 0.5f) if (t01 > 0.5f)
FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackB); FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackB);
@ -953,8 +948,7 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
} else if (action_has_finished) { } else if (action_has_finished) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle); FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle);
} else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) { } else if (!FP_Game_EntityActionHasFailed(action) && we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) {
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
Dqn_f32 t01 = action->timer_s / action->end_at_s; Dqn_f32 t01 = action->timer_s / action->end_at_s;
if (t01 > 0.5f) if (t01 > 0.5f)
FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackC); FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackC);
@ -980,11 +974,9 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer,
if (action->flags & FP_GameEntityActionFlag_StateTransition) { if (action->flags & FP_GameEntityActionFlag_StateTransition) {
FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, action_to_anim_mapping); FP_Game_EntityActionReset(action, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, action_to_anim_mapping);
} else if (we_are_clicked_entity) { } else if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J) || if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) {
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_X)) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackA); FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackA);
} else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift) || } else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift)) {
TELY_Platform_InputGamepadButtonCodeIsPressed(input, 0, TELY_PlatformInputGamepadButtonCode_A)) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_Dash); FP_Game_EntityActionSetState(action, FP_GameEntityState_Dash);
} }
} }
@ -1369,5 +1361,5 @@ void TELY_DLL_FrameUpdate(void *user_data)
} }
TELY_RFui_Flush(rfui, renderer, input, assets); TELY_RFui_Flush(rfui, renderer, input, assets);
//TELY_Audio_MixPlaybackSamples(audio, assets); TELY_Audio_MixPlaybackSamples(audio, assets);
} }

View File

@ -8,11 +8,10 @@ enum FP_GameEntityFlag
FP_GameEntityFlag_Clickable = 1 << 0, FP_GameEntityFlag_Clickable = 1 << 0,
FP_GameEntityFlag_MoveByKeyboard = 1 << 1, FP_GameEntityFlag_MoveByKeyboard = 1 << 1,
FP_GameEntityFlag_MoveByMouse = 1 << 2, FP_GameEntityFlag_MoveByMouse = 1 << 2,
FP_GameEntityFlag_MoveByGamepad = 1 << 3, FP_GameEntityFlag_DrawHitBox = 1 << 3,
FP_GameEntityFlag_DrawHitBox = 1 << 4, FP_GameEntityFlag_DeriveHitBoxFromChildrenBoundingBox = 1 << 4,
FP_GameEntityFlag_DeriveHitBoxFromChildrenBoundingBox = 1 << 5, FP_GameEntityFlag_NonTraversable = 1 << 5,
FP_GameEntityFlag_NonTraversable = 1 << 6, FP_GameEntityFlag_MobSpawner = 1 << 6,
FP_GameEntityFlag_MobSpawner = 1 << 7,
}; };
enum FP_GameShapeType enum FP_GameShapeType