diff options
Diffstat (limited to 'src/player.odin')
| -rw-r--r-- | src/player.odin | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/src/player.odin b/src/player.odin index e7fd214..71b015b 100644 --- a/src/player.odin +++ b/src/player.odin @@ -28,32 +28,26 @@ Player_State :: enum { player: struct { body_handle: phys.Body_Handle, sprite: Sprite, - jump_buffer: f32, coyote_time: f32, - dash_cooldown: f32, dash_timer: f32, - state: Player_State, - outside_room: bool, has_double_jumped: bool, } init_player :: proc() { - handle, body := phys.make_body( - phys.Rect{{-4, 17}, {8, 16}}, - ) + handle, body := phys.make_body(phys.Rect{{-4, 17}, {8, 16}}) player.body_handle = handle phys.set_body_position(handle, Vec2{50, 100}) init_sprite(&player.sprite, .PLAYER) - player.sprite.offset = Vec2{ + player.sprite.offset = Vec2 { math.floor(f32(player.sprite.width / 2)), - -f32(player.sprite.height) + -f32(player.sprite.height), } } @@ -63,7 +57,7 @@ delete_player :: proc() { destroy_sprite(player.sprite) } -@(private="file") +@(private = "file") get_input_dir :: proc() -> f32 { input: f32 @@ -77,7 +71,7 @@ get_input_dir :: proc() -> f32 { return input } -@(private="file") +@(private = "file") default_state :: proc(dt: f32) { input := get_input_dir() @@ -104,12 +98,12 @@ default_state :: proc(dt: f32) { player.has_double_jumped = false } else { switch body.vel.y { - case -math.INF_F32..<-50: - set_sprite_active_tag(&player.sprite, "jump_up") - case 50..<math.INF_F32: - set_sprite_active_tag(&player.sprite, "jump_down") - case: - set_sprite_active_tag(&player.sprite, "jump_trans") + case -math.INF_F32 ..< -50: + set_sprite_active_tag(&player.sprite, "jump_up") + case 50 ..< math.INF_F32: + set_sprite_active_tag(&player.sprite, "jump_down") + case: + set_sprite_active_tag(&player.sprite, "jump_trans") } } @@ -127,9 +121,9 @@ default_state :: proc(dt: f32) { } } - if .DOWN not_in body.collisions \ - && !is_keybind_down(actions.jump) \ - && body.vel.y < PLAYER_JUMP_RELEASE_CUT { + if .DOWN not_in body.collisions && + !is_keybind_down(actions.jump) && + body.vel.y < PLAYER_JUMP_RELEASE_CUT { body.vel.y = PLAYER_JUMP_RELEASE_CUT } @@ -143,7 +137,7 @@ default_state :: proc(dt: f32) { phys.update_body(player.body_handle) } -@(private="file") +@(private = "file") enter_dash :: proc() { body := phys.get_body(player.body_handle) // the sprite x scale is the direction the player is facing :) @@ -153,7 +147,7 @@ enter_dash :: proc() { player.state = .DASH } -@(private="file") +@(private = "file") dash_state :: proc(dt: f32) { phys.update_body(player.body_handle) @@ -165,7 +159,7 @@ dash_state :: proc(dt: f32) { } } -@(private="file") +@(private = "file") exit_dash :: proc() { player.state = .DEFAULT @@ -175,26 +169,22 @@ exit_dash :: proc() { body.vel /= 2 } -@(private="file") +@(private = "file") change_rooms :: proc() { body := phys.get_body(player.body_handle) width := f32(current_room.width) height := f32(current_room.height) - if body.pos.x < 0 || body.pos.x > width \ - || body.pos.y < 0 || body.pos.y > height { - prev_room_pos := Vec2{ - f32(current_room.x), - f32(current_room.y), - } + if body.pos.x < 0 || + body.pos.x > width || + body.pos.y < 0 || + body.pos.y > height { + prev_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} changed := open_room_at({i32(body.pos.x), i32(body.pos.y)}) if changed { - new_room_pos := Vec2{ - f32(current_room.x), - f32(current_room.y), - } + new_room_pos := Vec2{f32(current_room.x), f32(current_room.y)} diff := prev_room_pos - new_room_pos new_pos := body.pos + diff - {0, 0} |
