diff options
Diffstat (limited to 'src/player.odin')
| -rw-r--r-- | src/player.odin | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/player.odin b/src/player.odin index 061726f..8569d8c 100644 --- a/src/player.odin +++ b/src/player.odin @@ -30,6 +30,7 @@ player: struct { state: Player_State, outside_room: bool, has_double_jumped: bool, + prev_aim_dir: Vec2, fall_height: f32, body: phys.Body_Handle, @@ -72,12 +73,37 @@ init_player :: proc() { player.max_health = 10 player.health = 10 + player.prev_aim_dir = {1, 0} } deinit_player :: proc() { phys.remove_body(player.body) } +aim_dir :: proc() -> Vec2 { + dir: Vec2 + + if fw.is_keybind_down(actions.aim_left) { + dir.x -= 1 + } + if fw.is_keybind_down(actions.aim_right) { + dir.x += 1 + } + if fw.is_keybind_down(actions.aim_up) { + dir.y -= 1 + } + if fw.is_keybind_down(actions.aim_down) { + dir.y += 1 + } + + if dir == {0, 0} { + return player.prev_aim_dir + } + + player.prev_aim_dir = dir + return dir +} + @(private = "file") _get_input_dir :: proc() -> f32 { if !point_inside_room(phys.get_position(player.body)) { @@ -165,26 +191,26 @@ _default_state :: proc(dt: f32) { player.fall_height = min(pos.y, player.fall_height) } - rel_mouse_pos := fw.get_mouse_pos() - pos + aim_dir := aim_dir() if fw.is_keybind_just_down(actions.shoot) { - mouse_dir := linalg.normalize0(rel_mouse_pos + {0, PLAYER_GUN_HEIGHT}) - bullet_pos := pos bullet_pos.y -= PLAYER_GUN_HEIGHT - bullet_pos += mouse_dir * PLAYER_GUN_DIST + bullet_pos += aim_dir * PLAYER_GUN_DIST player.gun.kickback = PLAYER_GUN_KICKBACK make_bullet( pos = bullet_pos, - vel = mouse_dir * 800, + vel = aim_dir * 800, lifetime = 0.25, mask = {.Hard, .Enemy}, ) } - player.sprite.scale.x = math.sign(rel_mouse_pos.x) + if aim_dir.x != 0 { + player.sprite.scale.x = math.sign(aim_dir.x) + } if player.jump_buffer > 0 { if player.coyote_time > 0 { @@ -406,14 +432,14 @@ update_player :: proc(dt: f32) { player.sprite.pos = pos update_sprite(&player.sprite, dt) - mouse_dir := linalg.normalize0(fw.get_mouse_pos() - player.gun.sprite.pos) - player.gun.sprite.rotation = math.atan2(mouse_dir.y, mouse_dir.x) + aim_dir := aim_dir() + player.gun.sprite.rotation = math.atan2(aim_dir.y, aim_dir.x) player.gun.sprite.pos = pos - Vec2{0, PLAYER_GUN_HEIGHT} - player.gun.sprite.pos += -mouse_dir * player.gun.kickback + player.gun.sprite.pos += -aim_dir * player.gun.kickback player.gun.kickback = dt_lerp(player.gun.kickback, 0, 5) - player.gun.sprite.scale.y = -1 if mouse_dir.x < 0 else 1 + player.gun.sprite.scale.y = -1 if aim_dir.x < 0 else 1 player.dash_cooldown -= dt player.jump_buffer -= dt |
