aboutsummaryrefslogtreecommitdiff
path: root/src/player.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.odin')
-rw-r--r--src/player.odin31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/player.odin b/src/player.odin
index 9c824b4..7483bab 100644
--- a/src/player.odin
+++ b/src/player.odin
@@ -21,7 +21,8 @@ PLAYER_DASH_TIME :: 0.15
PLAYER_DASH_COOLDOWN :: 0.3
PLAYER_GUN_HEIGHT :: 0
-PLAYER_GUN_DIST :: 5 // how far out to hold the gun
+PLAYER_GUN_DIST :: 7 // how far out to hold the gun
+PLAYER_GUN_KICKBACK :: 4 // how far to move the gun back when you shoot
PLAYER_SCARF_DIST :: 5
@@ -34,7 +35,10 @@ Player_State :: enum {
player: struct {
body: phys.Body_Handle,
sprite: Sprite,
- gun_sprite: Sprite,
+ gun: struct {
+ sprite: Sprite,
+ kickback: f32,
+ },
scarf: Tail(7),
jump_buffer: f32,
coyote_time: f32,
@@ -63,11 +67,11 @@ init_player :: proc() {
math.floor(f32(player.sprite.height / 2)),
}
- init_sprite(&player.gun_sprite, .PISTOL)
+ init_sprite(&player.gun.sprite, .PISTOL)
- player.gun_sprite.offset = Vec2 {
+ player.gun.sprite.offset = Vec2 {
-PLAYER_GUN_DIST,
- math.round(f32(player.gun_sprite.height / 2)),
+ math.round(f32(player.gun.sprite.height / 2)),
}
player.scarf = {
@@ -149,6 +153,8 @@ _default_state :: proc(dt: f32) {
bullet_pos.y -= PLAYER_GUN_HEIGHT
bullet_pos += mouse_dir * PLAYER_GUN_DIST
+ player.gun.kickback = PLAYER_GUN_KICKBACK
+
make_bullet(
pos = bullet_pos,
vel = mouse_dir * 800,
@@ -212,7 +218,7 @@ _dash_state :: proc(dt: f32) {
player.dash_timer -= dt
- if player.dash_timer <= 0 || phys.get_collisions(player.body) != {} {
+ if player.dash_timer <= 0 || phys.get_collisions(player.body) != nil {
_exit_dash()
}
}
@@ -289,15 +295,18 @@ update_player :: proc(dt: f32) {
player.sprite.pos = pos
update_sprite(&player.sprite, dt)
- player.gun_sprite.pos = pos - Vec2{0, PLAYER_GUN_HEIGHT}
- mouse_dir := get_mouse_pos() - player.gun_sprite.pos
- player.gun_sprite.rotation = math.atan2(
+ mouse_dir := linalg.normalize0(get_mouse_pos() - player.gun.sprite.pos)
+ player.gun.sprite.rotation = math.atan2(
mouse_dir.y,
mouse_dir.x,
) * math.DEG_PER_RAD
- player.gun_sprite.scale.y = -1 if mouse_dir.x < 0 else 1
+ player.gun.sprite.pos = pos - Vec2{0, PLAYER_GUN_HEIGHT}
+ player.gun.sprite.pos += -mouse_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.dash_cooldown -= dt
player.jump_buffer -= dt
@@ -321,7 +330,7 @@ draw_player :: proc() {
draw_tail(player.scarf)
draw_sprite(player.sprite)
if player.state != .DASH {
- draw_sprite(player.gun_sprite)
+ draw_sprite(player.gun.sprite)
}
}