diff --git a/main.c b/main.c index 39d336a..fb462e1 100644 --- a/main.c +++ b/main.c @@ -49,16 +49,28 @@ int main() struct kinematic_obj tile = init_kinematic_obj(900, 100); struct kinematic_obj tile2 = init_kinematic_obj(100, 40); struct kinematic_obj tile3 = init_kinematic_obj(100, 40); + struct kinematic_obj tile4 = init_kinematic_obj(40, 200); + struct kinematic_obj tile5 = init_kinematic_obj(40, 200); + struct kinematic_obj tile6 = init_kinematic_obj(50, 300); + struct kinematic_obj tile7 = init_kinematic_obj(50, 300); set_position(&player.kinematic, 400, 100); set_position(&tile, -50, 380); set_position(&tile2, 100, 280); set_position(&tile3, 500, 280); + set_position(&tile4, 250, 140); + set_position(&tile5, 350, 100); + set_position(&tile6, 0, 50); + set_position(&tile7, 700, 80); struct squishy_square sqr = init_squishy_square(&player.kinematic, RED); player.image = &sqr; add_node(&tile); add_node(&tile2); add_node(&tile3); + add_node(&tile4); + add_node(&tile5); + add_node(&tile6); + add_node(&tile7); add_node(&player.kinematic); SetTargetFPS(60); // Set our game to run at 60 frames-per-second diff --git a/obj/player.c b/obj/player.c index 80147fe..fafd422 100644 --- a/obj/player.c +++ b/obj/player.c @@ -40,29 +40,32 @@ void player_input_check(struct player_obj *player){ case IDLE: if (IsKeyDown(LEFT) || IsKeyDown(RIGHT)){ player->state = RUN_START; - //allow_friction = false; player->kinematic.velocity.x = (IsKeyDown(KEY_RIGHT)-IsKeyDown(KEY_LEFT)) * RUN_INIT_SPD; } break; case RUN_START: - run_dir = sign(player->kinematic.velocity.x); - // Run Opposite Direction - if ((IsKeyPressed(LEFT) && run_dir == 1) || (IsKeyPressed(RIGHT) && run_dir == -1)){ + if (player->kinematic.velocity.x == 0){ frame_counter = 0; - player->kinematic.velocity.x = -run_dir * RUN_INIT_SPD; - }else{ - // Complete the run startup - if(frame_counterkinematic.velocity.x = run_dir * RUN_INIT_SPD; - } - }else{ + player->state = IDLE; + }else{run_dir = sign(player->kinematic.velocity.x); + // Run Opposite Direction + if ((IsKeyPressed(LEFT) && run_dir == 1) || (IsKeyPressed(RIGHT) && run_dir == -1)){ frame_counter = 0; - allow_friction = true; - player->state = RUNNING; + player->kinematic.velocity.x = -run_dir * RUN_INIT_SPD; + }else{ + // Complete the run startup + if(frame_counterkinematic.velocity.x = run_dir * RUN_INIT_SPD; + } + }else{ + frame_counter = 0; + player->state = RUNNING; + } } } + break; case RUNNING: run_dir = sign(player->kinematic.velocity.x); @@ -78,13 +81,14 @@ void player_input_check(struct player_obj *player){ set_squish_target_offset(player->image, 0, 0); set_squish_target_offset(player->image, 2, 0); if (player->kinematic.velocity.x == 0){ - if (run_dir == 1){ + if (place_meeting(&player->kinematic, (Vector2){1,0})){ player->kinematic.dim_reduction[0] = PLAYER_SIZE / 2; - set_squish_target_offset(player->image, 0, 15); - }else{ + //set_squish_target_offset(player->image, 2, 15); + }else if (place_meeting(&player->kinematic, (Vector2){1,0})){ player->kinematic.dim_reduction[2] = PLAYER_SIZE / 2; - set_squish_target_offset(player->image, 2, 15); + //set_squish_target_offset(player->image, 2, 15); } + player->state = IDLE; } break; case RUN_END: @@ -138,7 +142,6 @@ void player_input_check(struct player_obj *player){ else player->kinematic.velocity.y = -JUMP_SPD; player->state = JUMPING; - on_ground = false; short_hop = false; } break; @@ -150,32 +153,34 @@ void player_input_check(struct player_obj *player){ break; case FALLING: accel.x = AIR_ACCEL*(IsKeyDown(KEY_RIGHT)-IsKeyDown(KEY_LEFT)); - if (place_meeting(&player->kinematic, (Vector2){0,1})){ + if (on_ground){ + frame_counter = 0; player->state = LANDING; - player->kinematic.dim_reduction[3] = 0; - player->kinematic.set_dim_reduction[3] = 0; - player->kinematic.dim_reduction[1] = PLAYER_SIZE; - player->kinematic.set_dim_reduction[1] = 0; - set_squish_target_offset(player->image, 1, 0); - on_ground = true; state_buffer = IDLE; } break; case LANDING: dash_count = 1; + if (frame_counter == 0){ + player->kinematic.dim_reduction[3] = 0; + player->kinematic.set_dim_reduction[3] = 0; + player->kinematic.dim_reduction[1] = PLAYER_SIZE; + player->kinematic.set_dim_reduction[1] = 0; + set_squish_target_offset(player->image, 1, 0); + } if(frame_counterstate = state_buffer; - --jumps; - } - else if (IsKeyDown(LEFT) || IsKeyDown(RIGHT)) + //if (state_buffer == JUMP_SQUAT){ + // player->state = state_buffer; + // --jumps; + //} + if (IsKeyDown(LEFT) || IsKeyDown(RIGHT)) player->state = RUNNING; else player->state = IDLE; @@ -198,7 +203,6 @@ void player_input_check(struct player_obj *player){ player->state = FALLING; dash_count = 1; } - //allow_friction = true; } break; case DASH_END: @@ -206,12 +210,45 @@ void player_input_check(struct player_obj *player){ break; } - if (IsKeyPressed(JUMP) && jumps > 0){ - player->state = JUMP_SQUAT; - allow_friction = true; - short_hop = false; - --jumps; + // Add mercy jump here + if (on_ground == true && !place_meeting(&player->kinematic, (Vector2){0,1}) && player->state != JUMP_SQUAT){ + jumps = 0; + if (player->state != DASHING) + player->state = FALLING; + else + player->state = JUMPING; } + + on_ground = place_meeting(&player->kinematic, (Vector2){0,1}); + + //if (player->state != DASHING && !place_meeting(&player->kinematic, (Vector2){0,1}) ){ + if (!on_ground ){ + accel.y = GRAV; + if(player->state != DASHING && player->kinematic.velocity.y > 0) + player->state = FALLING; + } + //if (allow_friction == true) + if (on_ground == true) + accel.x -= player->kinematic.velocity.x * 7.0; + else + accel.x -= player->kinematic.velocity.x * 1.0; + + if (IsKeyPressed(JUMP)){ + if (on_ground == false){ + if (place_meeting(&player->kinematic, (Vector2){-8,0})){ + player->kinematic.velocity.y = -350; + player->kinematic.velocity.x = 400; + player->state = JUMPING; + afterimage_fcounter = 5; + }else if (place_meeting(&player->kinematic, (Vector2){8, 0})){ + player->kinematic.velocity.y = -350; + player->kinematic.velocity.x = -400; + player->state = JUMPING; + afterimage_fcounter = 5; + } + } + } + if (IsKeyPressed(DASH) && dash_count > 0){ // Determine the direction of dashing dash_vec.x = 0; @@ -242,33 +279,16 @@ void player_input_check(struct player_obj *player){ frame_counter=0;afterimage_fcounter=0; player->state = DASHING; } - - // Add mercy jump here - if (on_ground == true && !place_meeting(&player->kinematic, (Vector2){0,1}) && player->state != JUMP_SQUAT){ - jumps = 0; - on_ground = false; + move(&player->kinematic, accel); + /*if (IsKeyPressed(JUMP) && jumps > 0){ + player->state = JUMP_SQUAT; allow_friction = true; - if (player->state != DASHING) - player->state = FALLING; - else - player->state = JUMPING; - } - - if (allow_friction == true) - if (on_ground) - accel.x -= player->kinematic.velocity.x * 7.0; - else - accel.x -= player->kinematic.velocity.x * 1.0; - - //if (player->state != DASHING && !place_meeting(&player->kinematic, (Vector2){0,1}) ){ - if (!place_meeting(&player->kinematic, (Vector2){0,1}) ){ - accel.y = GRAV; - if(player->state != DASHING && player->kinematic.velocity.y > 0) - player->state = FALLING; - } + short_hop = false; + --jumps; + }*/ + - player->kinematic.set_dim_reduction[1] = 0; player->kinematic.set_dim_reduction[3] = 0; if (on_ground == false){ @@ -290,5 +310,4 @@ void player_input_check(struct player_obj *player){ // Set the hitbox reductions adjust_hitbox(&player->kinematic); - move(&player->kinematic, accel); } \ No newline at end of file