just discovered **
This commit is contained in:
parent
3af347b24a
commit
56b5cc6b2c
1 changed files with 57 additions and 67 deletions
110
src/game.odin
110
src/game.odin
|
|
@ -93,6 +93,7 @@ Phase :: enum {
|
|||
Playing,
|
||||
}
|
||||
Vec2 :: [2]f32
|
||||
Rect :: ray.Rectangle
|
||||
Card :: struct {
|
||||
suit: Suit,
|
||||
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.DrawRectangleGradientEx(
|
||||
rrect_from_pos_sz({0, 0}, BOARD_SIZE),
|
||||
{**Vec2{0, 0}, **BOARD_SIZE},
|
||||
{30, 50, 40, 255},
|
||||
{25, 40, 43, 255},
|
||||
{25, 40, 43, 255},
|
||||
{30, 50, 40, 255},
|
||||
)
|
||||
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,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
{40, 35, 50, 255},
|
||||
|
|
@ -467,10 +468,11 @@ game_update :: proc() {
|
|||
target_position :=
|
||||
obj.entity.state != .Dragged ? entity.target_position : game.dragged_card_position
|
||||
starting_position := entity.position
|
||||
entity.position, entity.velocity = critical_spring_vec2(
|
||||
entity.position, entity.velocity = critical_spring_array(
|
||||
entity.position,
|
||||
entity.velocity,
|
||||
target_position,
|
||||
Vec2{},
|
||||
dt = delta,
|
||||
)
|
||||
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}
|
||||
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) ||
|
||||
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}
|
||||
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 game.should_redraw {
|
||||
|
|
@ -591,8 +593,8 @@ game_draw :: proc() {
|
|||
icon_size :: Vec2{40, 40}
|
||||
ray.DrawTexturePro(
|
||||
game.suit_textures[suit],
|
||||
source = rrect_from_pos_sz({0, 0}, SUIT_TEX_SIZE),
|
||||
dest = rrect_from_pos_sz(suit_position - icon_size * 0.5, icon_size),
|
||||
source = {**Vec2{0, 0}, **SUIT_TEX_SIZE},
|
||||
dest = {**(suit_position - icon_size * 0.5), **icon_size},
|
||||
origin = {0, 0},
|
||||
rotation = 0,
|
||||
tint = {255, 255, 255, 100},
|
||||
|
|
@ -623,10 +625,10 @@ game_draw :: proc() {
|
|||
|
||||
// NOTE(lilith): Scrim over the minor foundations
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(
|
||||
card_position({.Suit, 0}) - CARD_SIZE / 2 - GAP / 2,
|
||||
{CARD_SIZE.x * 4 + GAP * 3, CARD_SIZE.y} + Vec2{GAP, GAP},
|
||||
),
|
||||
Rect {
|
||||
**(card_position({.Suit, 0}) - CARD_SIZE / 2 - GAP / 2),
|
||||
**(Vec2{CARD_SIZE.x * 4 + GAP * 3, CARD_SIZE.y} + Vec2{GAP, GAP}),
|
||||
},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
ray.Color{0, 0, 0, u8(game.suits_overlay_opacity)},
|
||||
|
|
@ -656,15 +658,13 @@ game_draw :: proc() {
|
|||
|
||||
{ // NOTE(lilith): Draw reset button
|
||||
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(
|
||||
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.y,
|
||||
},
|
||||
),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
border_color({.Wand, 1}),
|
||||
|
|
@ -710,7 +710,7 @@ game_draw :: proc() {
|
|||
|
||||
{ // NOTE(lilith): Draw undo
|
||||
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.a = rect_contains(rect, game.mouse_position) ? 255 : 220
|
||||
if game.undo_state == nil {outline_color.a = 70}
|
||||
|
|
@ -746,7 +746,7 @@ game_draw :: proc() {
|
|||
|
||||
slot_draw :: proc(position: Vec2) {
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
{**(position - CARD_SIZE * 0.5), **CARD_SIZE},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = ray.Color{0, 0, 0, 90},
|
||||
|
|
@ -763,13 +763,13 @@ highlight_draw :: proc(position: Vec2, rotated := false) {
|
|||
shiny_color.a = shiny_alpha
|
||||
{ray.BeginBlendMode(.ADDITIVE); defer ray.EndBlendMode()
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(corner_pos, size),
|
||||
{**corner_pos, **size},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = shiny_color,
|
||||
)
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(corner_pos, size),
|
||||
{**corner_pos, **size},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = t * 2 + 1,
|
||||
|
|
@ -777,7 +777,7 @@ highlight_draw :: proc(position: Vec2, rotated := false) {
|
|||
)
|
||||
}
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(corner_pos - 1, size + 2),
|
||||
{**(corner_pos - 1), **(size + 2)},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = t * 3 + 2,
|
||||
|
|
@ -800,14 +800,14 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
// NOTE(lilith): Shadow
|
||||
shadow_size := CARD_SIZE * 1.05
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(entity.position - shadow_size * 0.5, shadow_size),
|
||||
{**(entity.position - shadow_size * 0.5), **shadow_size},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = {0, 0, 0, 60},
|
||||
)
|
||||
shadow_size_2 := CARD_SIZE * 1.03
|
||||
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,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = {0, 0, 0, 60},
|
||||
|
|
@ -817,7 +817,7 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
glow_color := card_backdrop_color(card)
|
||||
glow_color.a = 120
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
{**(entity.position - CARD_SIZE * 0.5), **CARD_SIZE},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = 4,
|
||||
|
|
@ -829,7 +829,7 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
highlight_color := card_glow_color(card)
|
||||
highlight_color.a = u8(180 * highlight_t)
|
||||
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,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = 6,
|
||||
|
|
@ -839,7 +839,7 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
|
||||
// NOTE(lilith): Background
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
{**(entity.position - CARD_SIZE * 0.5), **CARD_SIZE},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = background_color(card),
|
||||
|
|
@ -847,7 +847,7 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
|
||||
// NOTE(lilith): Border
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
{**(entity.position - CARD_SIZE * 0.5), **CARD_SIZE},
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = 2,
|
||||
|
|
@ -879,11 +879,11 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
if card.suit != .Major {
|
||||
ray.DrawTexturePro(
|
||||
game.suit_textures[card.suit],
|
||||
source = rrect_from_pos_sz({0, 0}, SUIT_TEX_SIZE),
|
||||
dest = rrect_from_pos_sz(
|
||||
entity.position + offset + {text_size.x, text_size.y * 0.1},
|
||||
text_size.yy * 0.7,
|
||||
),
|
||||
source = {**(Vec2{0, 0}), **SUIT_TEX_SIZE},
|
||||
dest = Rect {
|
||||
**(entity.position + offset + {text_size.x, text_size.y * 0.1}),
|
||||
**(text_size.yy * 0.7),
|
||||
},
|
||||
origin = {0, 0},
|
||||
rotation = 0,
|
||||
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
|
||||
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) {
|
||||
|
|
@ -1622,12 +1622,12 @@ place_from_position :: proc(p: Vec2) -> (place: Place) {
|
|||
for column_index in 0 ..< COLUMN_COUNT {
|
||||
place := Place{.Column, i8(column_index)}
|
||||
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}
|
||||
}
|
||||
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
|
||||
rect := rrect_from_pos_sz(pos, CARD_SIZE + GAP)
|
||||
rect := Rect{**pos, **(CARD_SIZE + GAP)}
|
||||
if rect_contains(rect, p) {return place}
|
||||
}
|
||||
|
||||
|
|
@ -1762,10 +1762,6 @@ should_run :: proc() -> bool {
|
|||
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) {
|
||||
return raw_data(slice), i32(len(slice))
|
||||
}
|
||||
|
|
@ -1794,37 +1790,31 @@ critical_spring_scalar :: proc(
|
|||
return
|
||||
}
|
||||
|
||||
critical_spring_vec2 :: proc(
|
||||
position: Vec2,
|
||||
velocity: Vec2,
|
||||
goal_position: Vec2,
|
||||
goal_velocity: Vec2 = Vec2{},
|
||||
critical_spring_array :: proc(
|
||||
position: $T/[$N]f32,
|
||||
velocity: T,
|
||||
goal_position: T,
|
||||
goal_velocity: T,
|
||||
damping: f32 = CARD_DAMPING,
|
||||
dt: f32 = 1,
|
||||
) -> (
|
||||
new_position: Vec2,
|
||||
new_velocity: Vec2,
|
||||
new_position: T,
|
||||
new_velocity: T,
|
||||
) {
|
||||
new_position.x, new_velocity.x = critical_spring_scalar(
|
||||
position.x,
|
||||
velocity.x,
|
||||
goal_position.x,
|
||||
goal_velocity.x,
|
||||
damping,
|
||||
dt,
|
||||
)
|
||||
new_position.y, new_velocity.y = critical_spring_scalar(
|
||||
position.y,
|
||||
velocity.y,
|
||||
goal_position.y,
|
||||
goal_velocity.y,
|
||||
for i in 0 ..< N {
|
||||
new_position[i], new_velocity[i] = critical_spring_scalar(
|
||||
position[i],
|
||||
velocity[i],
|
||||
goal_position[i],
|
||||
goal_velocity[i],
|
||||
damping,
|
||||
dt,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
rect_contains :: proc(rect: ray.Rectangle, p: Vec2) -> bool {
|
||||
rect_contains :: proc(rect: Rect, p: Vec2) -> bool {
|
||||
return(
|
||||
rect.x <= p.x &&
|
||||
p.x <= rect.x + rect.width &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue