just discovered **

This commit is contained in:
Lilith Schier 2026-10-16 20:15:29 +02:00
parent 3af347b24a
commit 56b5cc6b2c

View file

@ -93,6 +93,7 @@ Phase :: enum {
Playing, Playing,
} }
Vec2 :: [2]f32 Vec2 :: [2]f32
Rect :: ray.Rectangle
Card :: struct { Card :: struct {
suit: Suit, suit: Suit,
number: i8, number: i8,
@ -263,14 +264,14 @@ draw_background :: proc() {
ray.DrawRectangleV(Vec2{}, Vec2{BOARD_SIZE.x, 10 * BOARD_SIZE.y}, {25, 40, 43, 255}) ray.DrawRectangleV(Vec2{}, Vec2{BOARD_SIZE.x, 10 * BOARD_SIZE.y}, {25, 40, 43, 255})
ray.DrawRectangleGradientEx( ray.DrawRectangleGradientEx(
rrect_from_pos_sz({0, 0}, BOARD_SIZE), {**Vec2{0, 0}, **BOARD_SIZE},
{30, 50, 40, 255}, {30, 50, 40, 255},
{25, 40, 43, 255}, {25, 40, 43, 255},
{25, 40, 43, 255}, {25, 40, 43, 255},
{30, 50, 40, 255}, {30, 50, 40, 255},
) )
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz(Vec2{0, -GAP}, Vec2{BOARD_SIZE.x, CARD_SIZE.y + 3 * GAP}), {**Vec2{0, -GAP}, **Vec2{BOARD_SIZE.x, CARD_SIZE.y + 3 * GAP}},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
{40, 35, 50, 255}, {40, 35, 50, 255},
@ -467,10 +468,11 @@ game_update :: proc() {
target_position := target_position :=
obj.entity.state != .Dragged ? entity.target_position : game.dragged_card_position obj.entity.state != .Dragged ? entity.target_position : game.dragged_card_position
starting_position := entity.position starting_position := entity.position
entity.position, entity.velocity = critical_spring_vec2( entity.position, entity.velocity = critical_spring_array(
entity.position, entity.position,
entity.velocity, entity.velocity,
target_position, target_position,
Vec2{},
dt = delta, dt = delta,
) )
if linalg.distance(entity.position, entity.target_position) < 0.05 { if linalg.distance(entity.position, entity.target_position) < 0.05 {
@ -557,13 +559,13 @@ game_update :: proc() {
{ {
center_point := Vec2{BOARD_SIZE.x / 2, GAP + RESET_BUTTON_SIZE.y / 2} center_point := Vec2{BOARD_SIZE.x / 2, GAP + RESET_BUTTON_SIZE.y / 2}
reset_rect := rrect_from_pos_sz(center_point - RESET_BUTTON_SIZE / 2, RESET_BUTTON_SIZE) reset_rect := Rect{**(center_point - RESET_BUTTON_SIZE / 2), **RESET_BUTTON_SIZE}
if rect_contains(reset_rect, game.mouse_position) || if rect_contains(reset_rect, game.mouse_position) ||
game.reset_button.fill > 0 {game.should_redraw = true} game.reset_button.fill > 0 {game.should_redraw = true}
} }
{ {
center_point := Vec2{BOARD_SIZE.x / 2, GAP + CARD_SIZE.y - UNDO_BUTTON_SIZE.y / 2} center_point := Vec2{BOARD_SIZE.x / 2, GAP + CARD_SIZE.y - UNDO_BUTTON_SIZE.y / 2}
undo_rect := rrect_from_pos_sz(center_point - UNDO_BUTTON_SIZE / 2, UNDO_BUTTON_SIZE) undo_rect := Rect{**(center_point - UNDO_BUTTON_SIZE / 2), **UNDO_BUTTON_SIZE}
if rect_contains(undo_rect, game.mouse_position) {game.should_redraw = true} if rect_contains(undo_rect, game.mouse_position) {game.should_redraw = true}
} }
if game.should_redraw { if game.should_redraw {
@ -591,8 +593,8 @@ game_draw :: proc() {
icon_size :: Vec2{40, 40} icon_size :: Vec2{40, 40}
ray.DrawTexturePro( ray.DrawTexturePro(
game.suit_textures[suit], game.suit_textures[suit],
source = rrect_from_pos_sz({0, 0}, SUIT_TEX_SIZE), source = {**Vec2{0, 0}, **SUIT_TEX_SIZE},
dest = rrect_from_pos_sz(suit_position - icon_size * 0.5, icon_size), dest = {**(suit_position - icon_size * 0.5), **icon_size},
origin = {0, 0}, origin = {0, 0},
rotation = 0, rotation = 0,
tint = {255, 255, 255, 100}, tint = {255, 255, 255, 100},
@ -623,10 +625,10 @@ game_draw :: proc() {
// NOTE(lilith): Scrim over the minor foundations // NOTE(lilith): Scrim over the minor foundations
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz( Rect {
card_position({.Suit, 0}) - CARD_SIZE / 2 - GAP / 2, **(card_position({.Suit, 0}) - CARD_SIZE / 2 - GAP / 2),
{CARD_SIZE.x * 4 + GAP * 3, CARD_SIZE.y} + Vec2{GAP, GAP}, **(Vec2{CARD_SIZE.x * 4 + GAP * 3, CARD_SIZE.y} + Vec2{GAP, GAP}),
), },
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
ray.Color{0, 0, 0, u8(game.suits_overlay_opacity)}, ray.Color{0, 0, 0, u8(game.suits_overlay_opacity)},
@ -656,15 +658,13 @@ game_draw :: proc() {
{ // NOTE(lilith): Draw reset button { // NOTE(lilith): Draw reset button
center_point := Vec2{BOARD_SIZE.x / 2, GAP + RESET_BUTTON_SIZE.y / 2} center_point := Vec2{BOARD_SIZE.x / 2, GAP + RESET_BUTTON_SIZE.y / 2}
rect := rrect_from_pos_sz(center_point - RESET_BUTTON_SIZE / 2, RESET_BUTTON_SIZE) rect := Rect{**(center_point - RESET_BUTTON_SIZE / 2), **RESET_BUTTON_SIZE}
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz( {
center_point - RESET_BUTTON_SIZE / 2, **(center_point - RESET_BUTTON_SIZE / 2),
{ RESET_BUTTON_SIZE.x * math.smoothstep(f32(0), 1, game.reset_button.fill),
RESET_BUTTON_SIZE.x * math.smoothstep(f32(0), 1, game.reset_button.fill), RESET_BUTTON_SIZE.y,
RESET_BUTTON_SIZE.y, },
},
),
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
border_color({.Wand, 1}), border_color({.Wand, 1}),
@ -710,7 +710,7 @@ game_draw :: proc() {
{ // NOTE(lilith): Draw undo { // NOTE(lilith): Draw undo
center_point := Vec2{BOARD_SIZE.x / 2, GAP + CARD_SIZE.y - UNDO_BUTTON_SIZE.y / 2} center_point := Vec2{BOARD_SIZE.x / 2, GAP + CARD_SIZE.y - UNDO_BUTTON_SIZE.y / 2}
rect := rrect_from_pos_sz(center_point - UNDO_BUTTON_SIZE / 2, UNDO_BUTTON_SIZE) rect := Rect{**(center_point - UNDO_BUTTON_SIZE / 2), **UNDO_BUTTON_SIZE}
outline_color := border_color(CARDS[0]) outline_color := border_color(CARDS[0])
outline_color.a = rect_contains(rect, game.mouse_position) ? 255 : 220 outline_color.a = rect_contains(rect, game.mouse_position) ? 255 : 220
if game.undo_state == nil {outline_color.a = 70} if game.undo_state == nil {outline_color.a = 70}
@ -746,7 +746,7 @@ game_draw :: proc() {
slot_draw :: proc(position: Vec2) { slot_draw :: proc(position: Vec2) {
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz(position - CARD_SIZE * 0.5, CARD_SIZE), {**(position - CARD_SIZE * 0.5), **CARD_SIZE},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
color = ray.Color{0, 0, 0, 90}, color = ray.Color{0, 0, 0, 90},
@ -763,13 +763,13 @@ highlight_draw :: proc(position: Vec2, rotated := false) {
shiny_color.a = shiny_alpha shiny_color.a = shiny_alpha
{ray.BeginBlendMode(.ADDITIVE); defer ray.EndBlendMode() {ray.BeginBlendMode(.ADDITIVE); defer ray.EndBlendMode()
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz(corner_pos, size), {**corner_pos, **size},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
color = shiny_color, color = shiny_color,
) )
ray.DrawRectangleRoundedLinesEx( ray.DrawRectangleRoundedLinesEx(
rrect_from_pos_sz(corner_pos, size), {**corner_pos, **size},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
lineThick = t * 2 + 1, lineThick = t * 2 + 1,
@ -777,7 +777,7 @@ highlight_draw :: proc(position: Vec2, rotated := false) {
) )
} }
ray.DrawRectangleRoundedLinesEx( ray.DrawRectangleRoundedLinesEx(
rrect_from_pos_sz(corner_pos - 1, size + 2), {**(corner_pos - 1), **(size + 2)},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
lineThick = t * 3 + 2, lineThick = t * 3 + 2,
@ -800,14 +800,14 @@ card_draw :: proc(handle: Card_Handle) {
// NOTE(lilith): Shadow // NOTE(lilith): Shadow
shadow_size := CARD_SIZE * 1.05 shadow_size := CARD_SIZE * 1.05
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz(entity.position - shadow_size * 0.5, shadow_size), {**(entity.position - shadow_size * 0.5), **shadow_size},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
color = {0, 0, 0, 60}, color = {0, 0, 0, 60},
) )
shadow_size_2 := CARD_SIZE * 1.03 shadow_size_2 := CARD_SIZE * 1.03
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz(entity.position - shadow_size_2 * 0.5, shadow_size_2), {**(entity.position - shadow_size_2 * 0.5), **shadow_size_2},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
color = {0, 0, 0, 60}, color = {0, 0, 0, 60},
@ -817,7 +817,7 @@ card_draw :: proc(handle: Card_Handle) {
glow_color := card_backdrop_color(card) glow_color := card_backdrop_color(card)
glow_color.a = 120 glow_color.a = 120
ray.DrawRectangleRoundedLinesEx( ray.DrawRectangleRoundedLinesEx(
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE), {**(entity.position - CARD_SIZE * 0.5), **CARD_SIZE},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
lineThick = 4, lineThick = 4,
@ -829,7 +829,7 @@ card_draw :: proc(handle: Card_Handle) {
highlight_color := card_glow_color(card) highlight_color := card_glow_color(card)
highlight_color.a = u8(180 * highlight_t) highlight_color.a = u8(180 * highlight_t)
ray.DrawRectangleRoundedLinesEx( ray.DrawRectangleRoundedLinesEx(
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5 - 2, CARD_SIZE + 4), {**(entity.position - CARD_SIZE * 0.5 - 2), **(CARD_SIZE + 4)},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
lineThick = 6, lineThick = 6,
@ -839,7 +839,7 @@ card_draw :: proc(handle: Card_Handle) {
// NOTE(lilith): Background // NOTE(lilith): Background
ray.DrawRectangleRounded( ray.DrawRectangleRounded(
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE), {**(entity.position - CARD_SIZE * 0.5), **CARD_SIZE},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
color = background_color(card), color = background_color(card),
@ -847,7 +847,7 @@ card_draw :: proc(handle: Card_Handle) {
// NOTE(lilith): Border // NOTE(lilith): Border
ray.DrawRectangleRoundedLinesEx( ray.DrawRectangleRoundedLinesEx(
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE), {**(entity.position - CARD_SIZE * 0.5), **CARD_SIZE},
CARD_ROUNDNESS, CARD_ROUNDNESS,
ROUNDED_RECT_SEGMENTS, ROUNDED_RECT_SEGMENTS,
lineThick = 2, lineThick = 2,
@ -879,11 +879,11 @@ card_draw :: proc(handle: Card_Handle) {
if card.suit != .Major { if card.suit != .Major {
ray.DrawTexturePro( ray.DrawTexturePro(
game.suit_textures[card.suit], game.suit_textures[card.suit],
source = rrect_from_pos_sz({0, 0}, SUIT_TEX_SIZE), source = {**(Vec2{0, 0}), **SUIT_TEX_SIZE},
dest = rrect_from_pos_sz( dest = Rect {
entity.position + offset + {text_size.x, text_size.y * 0.1}, **(entity.position + offset + {text_size.x, text_size.y * 0.1}),
text_size.yy * 0.7, **(text_size.yy * 0.7),
), },
origin = {0, 0}, origin = {0, 0},
rotation = 0, rotation = 0,
tint = text_color(card), tint = text_color(card),
@ -911,10 +911,10 @@ card_draw :: proc(handle: Card_Handle) {
} }
} }
entity_click_rect :: proc(entity: Card_Entity) -> (rect: ray.Rectangle) { entity_click_rect :: proc(entity: Card_Entity) -> (rect: Rect) {
size := CARD_SIZE size := CARD_SIZE
if abs(entity.rotation) > math.PI / 4 {size.xy = size.yx} if abs(entity.rotation) > math.PI / 4 {size.xy = size.yx}
return rrect_from_pos_sz(entity.position - size * 0.5, size) return {**(entity.position - size * 0.5), **size}
} }
state_init_solved :: proc(state: ^State) { state_init_solved :: proc(state: ^State) {
@ -1622,12 +1622,12 @@ place_from_position :: proc(p: Vec2) -> (place: Place) {
for column_index in 0 ..< COLUMN_COUNT { for column_index in 0 ..< COLUMN_COUNT {
place := Place{.Column, i8(column_index)} place := Place{.Column, i8(column_index)}
pos := card_position(place) - CARD_SIZE * 0.5 - GAP * 0.5 pos := card_position(place) - CARD_SIZE * 0.5 - GAP * 0.5
rect := rrect_from_pos_sz(pos, {CARD_SIZE.x + GAP, 10000}) rect := Rect{**pos, **Vec2{CARD_SIZE.x + GAP, 10000}}
if rect_contains(rect, p) {return place} if rect_contains(rect, p) {return place}
} }
for place in ([]Place{{.Major, 0}, {.Major, 1}, {.Suit, 0}, {.Suit, 1}, {.Suit, 2}, {.Suit, 3}}) { for place in ([]Place{{.Major, 0}, {.Major, 1}, {.Suit, 0}, {.Suit, 1}, {.Suit, 2}, {.Suit, 3}}) {
pos := card_position(place) - CARD_SIZE * 0.5 - GAP * 0.5 pos := card_position(place) - CARD_SIZE * 0.5 - GAP * 0.5
rect := rrect_from_pos_sz(pos, CARD_SIZE + GAP) rect := Rect{**pos, **(CARD_SIZE + GAP)}
if rect_contains(rect, p) {return place} if rect_contains(rect, p) {return place}
} }
@ -1762,10 +1762,6 @@ should_run :: proc() -> bool {
return game.run return game.run
} }
rrect_from_pos_sz :: proc(pos: Vec2, sz: Vec2) -> ray.Rectangle {
return {pos.x, pos.y, sz.x, sz.y}
}
psz_from_slice :: proc(slice: []$T) -> (rawptr, i32) { psz_from_slice :: proc(slice: []$T) -> (rawptr, i32) {
return raw_data(slice), i32(len(slice)) return raw_data(slice), i32(len(slice))
} }
@ -1794,37 +1790,31 @@ critical_spring_scalar :: proc(
return return
} }
critical_spring_vec2 :: proc( critical_spring_array :: proc(
position: Vec2, position: $T/[$N]f32,
velocity: Vec2, velocity: T,
goal_position: Vec2, goal_position: T,
goal_velocity: Vec2 = Vec2{}, goal_velocity: T,
damping: f32 = CARD_DAMPING, damping: f32 = CARD_DAMPING,
dt: f32 = 1, dt: f32 = 1,
) -> ( ) -> (
new_position: Vec2, new_position: T,
new_velocity: Vec2, new_velocity: T,
) { ) {
new_position.x, new_velocity.x = critical_spring_scalar( for i in 0 ..< N {
position.x, new_position[i], new_velocity[i] = critical_spring_scalar(
velocity.x, position[i],
goal_position.x, velocity[i],
goal_velocity.x, goal_position[i],
damping, goal_velocity[i],
dt, damping,
) dt,
new_position.y, new_velocity.y = critical_spring_scalar( )
position.y, }
velocity.y,
goal_position.y,
goal_velocity.y,
damping,
dt,
)
return return
} }
rect_contains :: proc(rect: ray.Rectangle, p: Vec2) -> bool { rect_contains :: proc(rect: Rect, p: Vec2) -> bool {
return( return(
rect.x <= p.x && rect.x <= p.x &&
p.x <= rect.x + rect.width && p.x <= rect.x + rect.width &&