From 86738d3406671046ce50a2d1b07d858e14b2f968 Mon Sep 17 00:00:00 2001 From: iamcheeseman <[hidden email]> Date: Thu, 15 Jan 2026 16:17:16 -0500 Subject: Ensure upwards and downwards transitions work --- src/player.odin | 68 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 18 deletions(-) (limited to 'src/player.odin') diff --git a/src/player.odin b/src/player.odin index 497407c..2029195 100644 --- a/src/player.odin +++ b/src/player.odin @@ -20,7 +20,7 @@ PLAYER_DASH_SPEED :: 500 PLAYER_DASH_TIME :: 0.15 PLAYER_DASH_COOLDOWN :: 0.3 -PLAYER_GUN_HEIGHT :: 7 +PLAYER_GUN_HEIGHT :: 0 PLAYER_GUN_DIST :: 5 // how far out to hold the gun Player_State :: enum { @@ -44,7 +44,7 @@ player: struct { init_player :: proc() { body := phys.make_body( - phys.Rect{{-4, -16}, {8, 16}}, + phys.Rect{{-4, -8}, {8, 16}}, layers = {.PLAYER}, mask = {.DEFAULT} ) @@ -54,7 +54,7 @@ init_player :: proc() { player.sprite.offset = Vec2 { math.floor(f32(player.sprite.width / 2)), - f32(player.sprite.height), + math.floor(f32(player.sprite.height / 2)), } init_sprite(&player.gun_sprite, .PISTOL) @@ -71,6 +71,10 @@ deinit_player :: proc() { @(private = "file") _get_input_dir :: proc() -> f32 { + if !point_inside_room(phys.get_position(player.body)) { + return 0 + } + input: f32 if is_keybind_down(actions.move_left) { @@ -187,7 +191,6 @@ _dash_state :: proc(dt: f32) { phys.update_body(player.body) player.dash_timer -= dt - // body := phys.get_body(player.body_handle) if player.dash_timer <= 0 || phys.get_collisions(player.body) != {} { _exit_dash() @@ -205,26 +208,53 @@ _exit_dash :: proc() { } @(private = "file") -_change_rooms :: proc() { - width := f32(current_room.width) - height := f32(current_room.height) +_get_camera_target_pos :: proc() -> Vec2 { + pos := phys.get_position(player.body) - SCREEN_SIZE * 0.5 + room_size := Vec2{ + f32(current_room.width), + f32(current_room.height), + } + + camera_bounds_min := Vec2{0, 0} + camera_bounds_max := room_size - SCREEN_SIZE + + pos.x = math.clamp(pos.x, camera_bounds_min.x, camera_bounds_max.x) + pos.y = math.clamp(pos.y, camera_bounds_min.y, camera_bounds_max.y) + + return pos +} +@(private = "file") +_change_rooms :: proc() { pos := phys.get_position(player.body) - if pos.x < 0 || - pos.x > width || - pos.y < 0 || - pos.y > height { - prev_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} - changed := open_room_at({i32(pos.x), i32(pos.y)}) + if point_inside_room(pos) { + return + } + + prev_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} + changed := open_room_at({i32(pos.x), i32(pos.y)}) - if changed { - new_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} + if changed { + new_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} - diff := prev_room_pos - new_room_pos - new_pos := pos + diff - {0, 0} - phys.set_position(player.body, new_pos) + diff := prev_room_pos - new_room_pos + new_pos := pos + diff + phys.set_position(player.body, new_pos) + + if diff.y > 0 { + vel := phys.get_velocity(player.body) + vel.y = -PLAYER_JUMP_FORCE + phys.set_velocity(player.body, vel.y) + } else if diff.y > 0 { + vel := phys.get_velocity(player.body) + vel.y = 0 + phys.set_velocity(player.body, vel.y) } + + new_cam_pos := _get_camera_target_pos() + state.camera.target += diff + state.camera_target += diff } } @@ -253,6 +283,8 @@ update_player :: proc(dt: f32) { player.jump_buffer -= dt player.coyote_time -= dt + state.camera_target = _get_camera_target_pos() + _change_rooms() } -- cgit v1.3-2-g0d8e