From 057997b3578f3ff62457c31e9fdcb301380088ca Mon Sep 17 00:00:00 2001 From: iamcheeseman <[hidden email]> Date: Thu, 15 Jan 2026 20:53:56 -0500 Subject: scarf --- res/img/player.ase | Bin 5482 -> 5601 bytes src/assets.odin | 2 +- src/draw.odin | 4 ++++ src/player.odin | 20 ++++++++++++++++++++ src/tail.odin | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/tail.odin diff --git a/res/img/player.ase b/res/img/player.ase index 5aaf62e..3f6519e 100644 Binary files a/res/img/player.ase and b/res/img/player.ase differ diff --git a/src/assets.odin b/src/assets.odin index 3a3f64c..37e9ee9 100644 --- a/src/assets.odin +++ b/src/assets.odin @@ -49,7 +49,7 @@ images: [Image_Id]Image_Resource = { animations: [Animation_Id]Animation_Resource = { .NONE = {frame_count=1, frame_durations={100}, tags={}}, - .PLAYER = {frame_count = 23, frame_durations = {100, 100, 100, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100, 100, 100, 100, 100}, tags = {"jump_up"={from = 14, to = 15}, "run"={from = 6, to = 13}, "jump_trans"={from = 16, to = 16}, "jump_down"={from = 17, to = 18}, "idle"={from = 0, to = 5}, "sleep"={from = 19, to = 22}}}, + .PLAYER = {frame_count = 23, frame_durations = {100, 100, 100, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 75, 100, 100, 100, 100, 100, 100, 100, 100, 100}, tags = {"idle"={from = 0, to = 5}, "jump_trans"={from = 16, to = 16}, "run"={from = 6, to = 13}, "jump_down"={from = 17, to = 18}, "jump_up"={from = 14, to = 15}, "sleep"={from = 19, to = 22}}}, } rooms: [Room_Id]Room_Resource = { diff --git a/src/draw.odin b/src/draw.odin index 6507e03..2724ce3 100644 --- a/src/draw.odin +++ b/src/draw.odin @@ -65,6 +65,10 @@ draw_end_frame :: proc() { rl.EndDrawing() } +draw_circle :: proc(pos: Vec2, rad: f32) { + rl.DrawCircle(i32(pos.x), i32(pos.y), rad, _color_to_rl(renderer.tint)) +} + draw_rect :: proc(rect: Rect) { assert(rect.size.x > 0 && rect.size.y > 0) diff --git a/src/player.odin b/src/player.odin index debfd44..990a7d1 100644 --- a/src/player.odin +++ b/src/player.odin @@ -23,6 +23,8 @@ PLAYER_DASH_COOLDOWN :: 0.3 PLAYER_GUN_HEIGHT :: 0 PLAYER_GUN_DIST :: 5 // how far out to hold the gun +PLAYER_SCARF_DIST :: 5 + Player_State :: enum { DEFAULT, DASH, @@ -33,6 +35,7 @@ player: struct { body: phys.Body_Handle, sprite: Sprite, gun_sprite: Sprite, + scarf: Tail(7), jump_buffer: f32, coyote_time: f32, dash_cooldown: f32, @@ -66,6 +69,13 @@ init_player :: proc() { -PLAYER_GUN_DIST, math.round(f32(player.gun_sprite.height / 2)), } + + player.scarf = { + point_max_dist = 2, + point_rad = 2, + color_start = [4]f32{0.18, 0.13, 0.18, 1} * 0.5, + color_end = {0.18, 0.13, 0.18, 1}, + } } deinit_player :: proc() { @@ -294,10 +304,20 @@ update_player :: proc(dt: f32) { state.camera_target = _get_camera_target_pos() + scarf_dist: f32 = PLAYER_SCARF_DIST + if _get_input_dir() != 0 { + scarf_dist -= 1 + } + scarf_pos := linalg.round( + pos + Vec2{-scarf_dist * player.sprite.scale.x, 0}, + ) + set_tail_position(&player.scarf, scarf_pos, dt) + _change_rooms() } draw_player :: proc() { + draw_tail(player.scarf) draw_sprite(player.sprite) if player.state != .DASH { draw_sprite(player.gun_sprite) diff --git a/src/tail.odin b/src/tail.odin new file mode 100644 index 0000000..2184444 --- /dev/null +++ b/src/tail.odin @@ -0,0 +1,40 @@ +package demonchime + +import "core:math" +import "core:math/linalg" + +Tail :: struct($N: int) { + points: [N]Vec2, + point_max_dist: f32, + point_rad: f32, + color_start: Color, + color_end: Color, +} + +set_tail_position :: proc(tail: ^Tail($N), pos: Vec2, dt: f32) { + tail.points[0] = pos + for i in 1.. tail.point_max_dist*tail.point_max_dist { + dir := linalg.normalize0(cur^ - prev) + cur^ = prev + dir * (tail.point_max_dist - 1) + } + } +} + +draw_tail :: proc(tail: Tail($N)) { + for point, i in tail.points { + renderer.tint = linalg.lerp( + tail.color_start, + tail.color_end, + f32(i)/len(tail.points), + ) + draw_circle(point, tail.point_rad) + } + renderer.tint = {1, 1, 1, 1} +} -- cgit v1.3-2-g0d8e