diff --git a/include/header.h b/include/header.h index f95d360..087ee59 100644 --- a/include/header.h +++ b/include/header.h @@ -126,4 +126,5 @@ struct player_obj init_player_obj(); void player_input_check(struct player_obj *player); //Debug stuff, debug.c -void state_string(char *str, enum PLAYER_STATE state); \ No newline at end of file +void state_string(char *str, enum PLAYER_STATE state); +void display_input(char *dir); \ No newline at end of file diff --git a/main.c b/main.c index fb462e1..f6a4d63 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,11 @@ * ********************************************************************************************/ +/* Issues: + Playing with a USB keyboard: Cannot handle simultaneous key input. I think this is more + of a GLFW issue. +*/ + #include "header.h" extern struct kinematic_obj_node *kinematic_HEAD; int PLAYER_ACCEL = 1500; @@ -31,6 +36,7 @@ int main() const int screenHeight = 450; char current_state[20]; char current_spd[50]; + //char dir[7]; InitWindow(screenWidth, screenHeight, "raylib"); @@ -104,6 +110,8 @@ int main() DrawFPS(0,0); state_string(current_state, player.state); DrawText(current_state, 250, 0, 12, BLACK); + //display_input(dir); + //DrawText(dir, 0, 50, 12, BLACK); sprintf(current_spd, "Velocity: {%.2f,%.2f}", player.kinematic.velocity.x,player.kinematic.velocity.y); DrawText(current_spd, 350, 0, 12, BLACK); EndMode2D(); diff --git a/obj/player.c b/obj/player.c index a65ba6a..9a82cf1 100644 --- a/obj/player.c +++ b/obj/player.c @@ -27,7 +27,7 @@ static Vector2 dash_vec = (Vector2){0.0, 0.0}; const unsigned int run_start_frames = 10; const unsigned int jump_squat_frames = 4; -const unsigned int land_lag_frames = 6; +const unsigned int land_lag_frames = 2; const unsigned int dash_time_frames = 8; const unsigned int afterimage_frames = 10; @@ -126,9 +126,6 @@ void player_input_check(struct player_obj *player){ } } } - break; - case TURN_AROUND: - break; case JUMP_SQUAT: player->kinematic.set_dim_reduction[1] = 10; @@ -188,29 +185,24 @@ void player_input_check(struct player_obj *player){ else player->state = IDLE; } - break; - case DASH_START: - break; case DASHING: player->kinematic.velocity.x = dash_vec.x; player->kinematic.velocity.y = dash_vec.y; ++frame_counter; if (frame_counter > dash_time_frames){ - player->kinematic.velocity.x *= 0.7; - player->kinematic.velocity.y *= 0.7; - if (!place_meeting(&player->kinematic, (Vector2){0,1})){ + player->kinematic.velocity.x *= 0.8; + player->kinematic.velocity.y *= 0.8; + if (!on_ground){ player->state = JUMPING; } else{ - player->state = FALLING; + player->state = RUNNING; dash_count = 1; + jumps = 1; } } break; - case DASH_END: - - break; } // This accounts for player leaving the ground without jumping (dashing or falling) @@ -235,25 +227,19 @@ void player_input_check(struct player_obj *player){ // Air friction is less than ground friction if (on_ground == true) - accel.x -= player->kinematic.velocity.x * 7.0; + accel.x -= player->kinematic.velocity.x * 6.0; else - accel.x -= player->kinematic.velocity.x * 1.0; + accel.x -= player->kinematic.velocity.x * 3.0; // Handle wall jumping // TODO: define the wall jump values if (IsKeyPressed(JUMP)){ if (on_ground == false){ - if (place_meeting(&player->kinematic, (Vector2){-8,0})){ + bool left_check = place_meeting(&player->kinematic, (Vector2){-8,0}); + bool right_check = place_meeting(&player->kinematic, (Vector2){8,0}); + if (left_check || right_check){ player->kinematic.velocity.y = -350; - player->kinematic.velocity.x = 400; - player->state = JUMPING; - afterimage_fcounter = 5; - afterimage_c.r = 128; - afterimage_c.g = 128; - afterimage_c.b = 128; - }else if (place_meeting(&player->kinematic, (Vector2){8, 0})){ - player->kinematic.velocity.y = -350; - player->kinematic.velocity.x = -400; + player->kinematic.velocity.x = left_check? 400 : -400; player->state = JUMPING; afterimage_fcounter = 5; afterimage_c.r = 128; @@ -281,6 +267,8 @@ void player_input_check(struct player_obj *player){ // Default a direction if (dash_vec.x == 0 && dash_vec.y == 0){ dash_vec.x = sign(player->kinematic.velocity.x); + if (place_meeting(&player->kinematic, (Vector2){dash_vec.x,0})) + dash_vec.y = -1; } // Apply the scalar value, normalised to the unit direction @@ -296,6 +284,7 @@ void player_input_check(struct player_obj *player){ player->state = DASHING; } + // All velocity modification must be done before calling the move function move(&player->kinematic, accel); // Handle jumping diff --git a/utilities/debug.c b/utilities/debug.c index 0627b33..55735b2 100644 --- a/utilities/debug.c +++ b/utilities/debug.c @@ -15,4 +15,11 @@ void state_string(char *str, enum PLAYER_STATE state){ case RUN_END: sprintf(str, "%s", "RUN_END");break; case TURN_AROUND: sprintf(str, "%s", "TURN_AROUND");break; } +} + +void display_input(char *dir){ + sprintf(dir, " %c \n%c%c%c", IsKeyDown(UP)? '|':' ', + IsKeyDown(LEFT)? '-':' ', + IsKeyDown(DOWN)? '|':' ', + IsKeyDown(RIGHT)? '-':' '); } \ No newline at end of file