big small tweaks
This commit is contained in:
parent
3197ae9e6f
commit
67255a9efc
1 changed files with 320 additions and 116 deletions
436
src/game.odin
436
src/game.odin
|
|
@ -28,14 +28,14 @@ MINOR_SUIT_COUNT :: 4
|
|||
CARD_PROPORTIONS :: 4.75 / 2.75
|
||||
CARD_SIZE :: Vec2{125, 125 * CARD_PROPORTIONS}
|
||||
CARD_ROUNDNESS :: 0.05
|
||||
CARD_HEADER_TEXT_SIZE :: 26
|
||||
CARD_HEADER_TEXT_SIZE :: 28
|
||||
CARD_BOTTOM_TEXT_SIZE :: 20
|
||||
SUIT_TEX_SIZE :: Vec2{128, 128}
|
||||
COLUMN_COUNT :: 11
|
||||
COLUMN_HEIGHT :: 28
|
||||
ROUNDED_RECT_SEGMENTS :: 6
|
||||
GAP :: 16
|
||||
CARD_SEPARATION :: CARD_HEADER_TEXT_SIZE * 1.15
|
||||
CARD_SEPARATION :: CARD_HEADER_TEXT_SIZE
|
||||
CARD_DAMPING :: 60
|
||||
AUTO_MOVE_INTERVAL :: 0.1
|
||||
BOARD_SIZE :: Vec2 {
|
||||
|
|
@ -57,10 +57,11 @@ Game :: struct {
|
|||
static_arena_data: [128 * mem.Kilobyte]byte,
|
||||
// Allocations here will never be freed
|
||||
static_allocator: runtime.Allocator,
|
||||
entities: [TAROT_COUNT]Card_Entity,
|
||||
delta: f32,
|
||||
entities: [Card_Handle(TAROT_COUNT)]Card_Entity,
|
||||
state: State,
|
||||
displayed_state: State,
|
||||
card_top_font: ray.Font,
|
||||
font: ray.Font,
|
||||
card_bottom_font: ray.Font,
|
||||
suit_textures: [Suit]ray.Texture,
|
||||
dragged_card: Maybe(Card_Handle),
|
||||
|
|
@ -76,6 +77,13 @@ Game :: struct {
|
|||
random_game_count: int,
|
||||
camera: ray.Camera2D,
|
||||
sdf_shader: ray.Shader,
|
||||
hovered_any_card: Maybe(Card_Handle),
|
||||
reset_button: Hold_Button,
|
||||
undo_state: Maybe(State),
|
||||
}
|
||||
Hold_Button :: struct {
|
||||
fill: f32,
|
||||
activated: bool,
|
||||
}
|
||||
Phase :: enum {
|
||||
Searching,
|
||||
|
|
@ -95,14 +103,17 @@ Suit :: enum {
|
|||
}
|
||||
Card_Handle :: distinct i8
|
||||
Card_Entity :: struct {
|
||||
position: Vec2,
|
||||
target_position: Vec2,
|
||||
velocity: Vec2,
|
||||
rotation: f32,
|
||||
target_rotation: f32,
|
||||
angular_velocity: f32,
|
||||
is_draggable: bool,
|
||||
state: Card_State_Kind,
|
||||
position: Vec2,
|
||||
target_position: Vec2,
|
||||
velocity: Vec2,
|
||||
rotation: f32,
|
||||
target_rotation: f32,
|
||||
angular_velocity: f32,
|
||||
is_draggable: bool,
|
||||
is_neighbor_highlit: bool,
|
||||
is_hovered: bool,
|
||||
highlight_amount: f32,
|
||||
state: Card_State_Kind,
|
||||
}
|
||||
Card_State_Kind :: enum {
|
||||
Idle,
|
||||
|
|
@ -174,27 +185,27 @@ init :: proc() {
|
|||
ray.SetTextureFilter(game.suit_textures[suit], .TRILINEAR)
|
||||
}
|
||||
|
||||
game.card_top_font.baseSize = 32
|
||||
game.card_top_font.glyphCount = 95
|
||||
game.card_top_font.glyphs = ray.LoadFontData(
|
||||
game.font.baseSize = 32
|
||||
game.font.glyphCount = 95
|
||||
game.font.glyphs = ray.LoadFontData(
|
||||
psz_from_slice(game.assets["Coustard-Regular.ttf"].data),
|
||||
fontSize = 32,
|
||||
codepoints = nil,
|
||||
codepointCount = 0,
|
||||
type = .SDF,
|
||||
glyphCount = &game.card_top_font.glyphCount,
|
||||
glyphCount = &game.font.glyphCount,
|
||||
)
|
||||
atlas := ray.GenImageFontAtlas(
|
||||
game.card_top_font.glyphs,
|
||||
&game.card_top_font.recs,
|
||||
game.font.glyphs,
|
||||
&game.font.recs,
|
||||
codepointCount = 0,
|
||||
fontSize = 32,
|
||||
padding = 0,
|
||||
packMethod = 1,
|
||||
)
|
||||
defer ray.UnloadImage(atlas)
|
||||
game.card_top_font.texture = ray.LoadTextureFromImage(atlas)
|
||||
game.card_bottom_font = game.card_top_font
|
||||
game.font.texture = ray.LoadTextureFromImage(atlas)
|
||||
game.card_bottom_font = game.font
|
||||
game.sdf_shader = ray.LoadShaderFromMemory(
|
||||
nil,
|
||||
strings.clone_to_cstring(
|
||||
|
|
@ -202,7 +213,7 @@ init :: proc() {
|
|||
context.temp_allocator,
|
||||
),
|
||||
)
|
||||
ray.SetTextureFilter(game.card_top_font.texture, .BILINEAR)
|
||||
ray.SetTextureFilter(game.font.texture, .BILINEAR)
|
||||
game.ctx = context
|
||||
}
|
||||
|
||||
|
|
@ -225,6 +236,21 @@ update :: proc() {
|
|||
ray.BeginMode2D(game.camera); defer ray.EndMode2D()
|
||||
ray.ClearBackground({40, 65, 52, 255})
|
||||
|
||||
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),
|
||||
{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}),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
{40, 35, 50, 255},
|
||||
)
|
||||
|
||||
switch game.phase {
|
||||
case .Searching:
|
||||
game_update_searching()
|
||||
|
|
@ -257,35 +283,37 @@ game_update_searching :: proc() {
|
|||
free_all(context.temp_allocator)
|
||||
}
|
||||
|
||||
text := fmt.ctprintf(
|
||||
"Generating puzzle,\nPlease wait...\n\nAttempt: %d",
|
||||
game.random_game_count,
|
||||
)
|
||||
center_point := Vec2{BOARD_SIZE.x / 2, GAP + CARD_SIZE.y / 2}
|
||||
GENERATING_TEXT :: "Divining new spread..."
|
||||
count_text := fmt.ctprintf("%d", game.random_game_count)
|
||||
generating_text_size := ray.MeasureTextEx(game.font, GENERATING_TEXT, CARD_HEADER_TEXT_SIZE, 0)
|
||||
count_text_size := ray.MeasureTextEx(game.font, count_text, CARD_BOTTOM_TEXT_SIZE, 0)
|
||||
|
||||
{ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode()
|
||||
ray.DrawTextEx(
|
||||
game.card_top_font,
|
||||
text,
|
||||
Vec2{CARD_HEADER_TEXT_SIZE, CARD_HEADER_TEXT_SIZE},
|
||||
game.font,
|
||||
GENERATING_TEXT,
|
||||
center_point - {0, generating_text_size.y} - generating_text_size / 2,
|
||||
CARD_HEADER_TEXT_SIZE,
|
||||
0,
|
||||
text_color(CARDS[1]),
|
||||
)
|
||||
ray.DrawTextEx(
|
||||
game.font,
|
||||
count_text,
|
||||
center_point + {0, generating_text_size.y} - count_text_size / 2,
|
||||
CARD_BOTTOM_TEXT_SIZE,
|
||||
0,
|
||||
text_color(CARDS[1]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
game_update :: proc() {
|
||||
free_all(context.temp_allocator)
|
||||
delta := ray.GetFrameTime()
|
||||
game.delta = f32(ray.GetFrameTime())
|
||||
delta := game.delta
|
||||
|
||||
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),
|
||||
{30, 50, 40, 255},
|
||||
{25, 40, 43, 255},
|
||||
{25, 40, 43, 255},
|
||||
{30, 50, 40, 255},
|
||||
)
|
||||
ray.DrawRectangleV(Vec2{}, Vec2{BOARD_SIZE.x, CARD_SIZE.y + 2 * GAP}, {40, 35, 50, 255})
|
||||
|
||||
for &entity in game.entities {entity.is_draggable = false}
|
||||
for &column in game.state.columns {
|
||||
|
|
@ -303,11 +331,9 @@ game_update :: proc() {
|
|||
game.hovered_draggable = nil
|
||||
for &obj, index in game_cards_zipped() {
|
||||
handle := Card_Handle(index)
|
||||
if rect_contains(
|
||||
rrect_from_pos_sz(obj.entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
mouse_position,
|
||||
) &&
|
||||
game.entities[int(handle)].is_draggable {
|
||||
entity := game.entities[int(handle)]
|
||||
rect := entity_click_rect(entity)
|
||||
if rect_contains(rect, mouse_position) && entity.is_draggable {
|
||||
game.hovered_draggable = handle
|
||||
break
|
||||
}
|
||||
|
|
@ -339,18 +365,21 @@ game_update :: proc() {
|
|||
to = new_place,
|
||||
card = dragged_card,
|
||||
}
|
||||
effects, ok := state_perform_move_with_effects(
|
||||
before_state := game.state
|
||||
if effects, ok := state_perform_move_with_effects(
|
||||
&game.state,
|
||||
move,
|
||||
allocator = context.temp_allocator,
|
||||
)
|
||||
); ok {
|
||||
game.undo_state = before_state
|
||||
for auto_move in effects {
|
||||
queue.push(&game.auto_moves, auto_move)
|
||||
auto_obj := &game_cards_zipped()[int(auto_move.card)]
|
||||
auto_obj.entity.state = .Locked
|
||||
}
|
||||
}
|
||||
obj.entity.state = .Idle
|
||||
game.dragged_card = nil
|
||||
for auto_move in effects {
|
||||
queue.push(&game.auto_moves, auto_move)
|
||||
auto_obj := &game_cards_zipped()[int(auto_move.card)]
|
||||
auto_obj.entity.state = .Locked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -436,6 +465,42 @@ game_update :: proc() {
|
|||
)
|
||||
}
|
||||
|
||||
// NOTE(lilith): Neighbor card highlighting
|
||||
{
|
||||
game.hovered_any_card = nil
|
||||
for column, column_index in game.displayed_state.columns {
|
||||
for handle, height in column {
|
||||
entity := game.entities[handle]
|
||||
rect := entity_click_rect(entity)
|
||||
if rect_contains(rect, mouse_position) {
|
||||
game.hovered_any_card = handle
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(game.displayed_state.aside) > 0 {
|
||||
handle := game.displayed_state.aside[0]
|
||||
entity := game.entities[handle]
|
||||
rect := entity_click_rect(entity)
|
||||
if rect_contains(rect, mouse_position) {
|
||||
game.hovered_any_card = handle
|
||||
}
|
||||
}
|
||||
if handle, ok := game.dragged_card.?; ok {game.hovered_any_card = handle}
|
||||
if hover_handle, ok := game.hovered_any_card.?; ok {
|
||||
hover_card := card_from_handle(hover_handle)
|
||||
for &entity, handle in game.entities {
|
||||
card := card_from_handle(Card_Handle(handle))
|
||||
entity.is_neighbor_highlit = cards_are_stackable(card, hover_card)
|
||||
entity.is_hovered = Card_Handle(handle) == hover_handle
|
||||
}
|
||||
} else {
|
||||
for &entity in game.entities {
|
||||
entity.is_neighbor_highlit = false
|
||||
entity.is_hovered = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(lilith): Draw cards
|
||||
for column, column_index in game.displayed_state.columns {
|
||||
for handle, cc_index in column {
|
||||
|
|
@ -454,11 +519,13 @@ game_update :: proc() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if draggin_card_over_aside || len(game.displayed_state.aside) != 0 {
|
||||
game.suits_overlay_opacity = min(160, game.suits_overlay_opacity + 500 * delta)
|
||||
} else {
|
||||
game.suits_overlay_opacity = max(0, game.suits_overlay_opacity - 500 * delta)
|
||||
}
|
||||
// NOTE(lilith): Scrim over the minor foundations
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(
|
||||
card_position({.Suit, 0}) - CARD_SIZE / 2 - GAP / 2,
|
||||
|
|
@ -479,9 +546,9 @@ game_update :: proc() {
|
|||
nil {target_highlight_card_handle = game.hovered_draggable}
|
||||
if handle, ok := target_highlight_card_handle.?; ok {
|
||||
game.last_highlight_card = handle
|
||||
game.highlight_opacity = min(1, game.highlight_opacity + delta * 3)
|
||||
game.highlight_opacity = min(1, game.highlight_opacity + delta * 2)
|
||||
} else {
|
||||
game.highlight_opacity = max(0, game.highlight_opacity - delta * 3)
|
||||
game.highlight_opacity = max(0, game.highlight_opacity - delta * 2)
|
||||
}
|
||||
if handle, ok := game.last_highlight_card.?; ok {
|
||||
place := state_card_place(game.state, handle)
|
||||
|
|
@ -495,6 +562,95 @@ game_update :: proc() {
|
|||
if !state_is_move_valid(game.state, move) {continue}
|
||||
highlight_draw(card_position(to, len(column)))
|
||||
}
|
||||
if len(game.state.aside) == 0 {
|
||||
highlight_draw(card_position({.Aside, 0}), rotated = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ // NOTE(lilith): Draw reset button
|
||||
RESET_BUTTON_SIZE :: Vec2{CARD_SIZE.x, CARD_SIZE.x / 4}
|
||||
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)
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(
|
||||
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}),
|
||||
)
|
||||
outline_color := border_color(CARDS[0])
|
||||
outline_color.a = rect_contains(rect, mouse_position) ? 255 : 170
|
||||
ray.DrawRectangleRoundedLines(rect, CARD_ROUNDNESS, ROUNDED_RECT_SEGMENTS, outline_color)
|
||||
RESET_TEXT :: "Reset"
|
||||
RESET_FONT_SIZE :: 22
|
||||
reset_text_size := ray.MeasureTextEx(game.font, RESET_TEXT, RESET_FONT_SIZE, 0)
|
||||
{ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode()
|
||||
ray.DrawTextEx(
|
||||
game.font,
|
||||
RESET_TEXT,
|
||||
center_point - reset_text_size / 2,
|
||||
RESET_FONT_SIZE,
|
||||
0,
|
||||
outline_color,
|
||||
)
|
||||
}
|
||||
if ray.IsMouseButtonDown(.LEFT) &&
|
||||
rect_contains(rect, mouse_position) &&
|
||||
!game.reset_button.activated {
|
||||
rate := 1 - game.reset_button.fill
|
||||
game.reset_button.fill += game.delta * (rate * rate * 1.6 + 0.25)
|
||||
} else {
|
||||
game.reset_button.fill -= game.delta
|
||||
game.reset_button.activated = false
|
||||
}
|
||||
game.reset_button.fill = clamp(game.reset_button.fill, 0, 1)
|
||||
if game.reset_button.fill >= 1 {
|
||||
game.reset_button.activated = true
|
||||
game.reset_button.fill = 0
|
||||
game.phase = .Searching
|
||||
game.state = {}
|
||||
game.displayed_state = {}
|
||||
queue.clear(&game.auto_moves)
|
||||
game.random_game_count = 0
|
||||
game.last_highlight_card = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
{ // NOTE(lilith): Draw undo
|
||||
UNDO_BUTTON_SIZE :: Vec2{CARD_SIZE.x, CARD_SIZE.x / 3}
|
||||
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)
|
||||
outline_color := border_color(CARDS[0])
|
||||
outline_color.a = rect_contains(rect, mouse_position) ? 255 : 220
|
||||
if game.undo_state == nil {outline_color.a = 70}
|
||||
ray.DrawRectangleRoundedLines(rect, CARD_ROUNDNESS, ROUNDED_RECT_SEGMENTS, outline_color)
|
||||
UNDO_TEXT :: "Undo"
|
||||
UNDO_FONT_SIZE :: CARD_HEADER_TEXT_SIZE
|
||||
reset_text_size := ray.MeasureTextEx(game.font, UNDO_TEXT, UNDO_FONT_SIZE, 0)
|
||||
{ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode()
|
||||
ray.DrawTextEx(
|
||||
game.font,
|
||||
UNDO_TEXT,
|
||||
center_point - reset_text_size / 2,
|
||||
UNDO_FONT_SIZE,
|
||||
0,
|
||||
outline_color,
|
||||
)
|
||||
}
|
||||
if ray.IsMouseButtonPressed(.LEFT) &&
|
||||
rect_contains(rect, mouse_position) &&
|
||||
game.undo_state != nil {
|
||||
queue.clear(&game.auto_moves)
|
||||
game.state = game.undo_state.?
|
||||
game.displayed_state = game.undo_state.?
|
||||
game.undo_state = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -512,43 +668,74 @@ slot_draw :: proc(position: Vec2) {
|
|||
)
|
||||
}
|
||||
|
||||
highlight_draw :: proc(position: Vec2) {
|
||||
highlight_draw :: proc(position: Vec2, rotated := false) {
|
||||
t := f32(math.cos(ray.GetTime() * 1.6)) * 0.5 + 0.5
|
||||
shiny_color := ray.ColorFromHSV(f32(ray.GetTime() * 30), 0.2, 0.8)
|
||||
shiny_color.a = u8((t * 40 + 30) * game.highlight_opacity)
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = shiny_color,
|
||||
)
|
||||
size := CARD_SIZE
|
||||
if rotated {size.xy = size.yx}
|
||||
corner_pos := position - size / 2
|
||||
shiny_alpha := u8((t * 30 + 70) * game.highlight_opacity)
|
||||
shiny_color := ray.ColorFromHSV(f32(ray.GetTime() * 30), 0.35, 0.6)
|
||||
shiny_color.a = shiny_alpha
|
||||
{ray.BeginBlendMode(.ADDITIVE); defer ray.EndBlendMode()
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(corner_pos, size),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = shiny_color,
|
||||
)
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(corner_pos, size),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = t * 2 + 1,
|
||||
color = ray.Color{255, 255, 230, u8(140 * game.highlight_opacity)},
|
||||
)
|
||||
}
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(position - CARD_SIZE * 0.5 - 1, CARD_SIZE + 2),
|
||||
rrect_from_pos_sz(corner_pos - 1, size + 2),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = t * 2 + 1,
|
||||
lineThick = t * 3 + 2,
|
||||
color = ray.Color{0, 0, 0, u8(140 * game.highlight_opacity)},
|
||||
)
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = t * 2,
|
||||
color = ray.Color{255, 255, 230, u8(140 * game.highlight_opacity)},
|
||||
)
|
||||
}
|
||||
|
||||
card_draw :: proc(handle: Card_Handle) {
|
||||
obj := game_cards_zipped()[int(handle)]
|
||||
card := obj.card
|
||||
entity := obj.entity
|
||||
entity := &game.entities[handle]
|
||||
card := card_from_handle(handle)
|
||||
|
||||
if entity.is_neighbor_highlit || entity.is_hovered {
|
||||
entity.highlight_amount += game.delta * 6
|
||||
} else {
|
||||
entity.highlight_amount -= game.delta * 3
|
||||
}
|
||||
entity.highlight_amount = clamp(entity.highlight_amount, 0, 1)
|
||||
highlight_t := math.smoothstep(f32(0), 1, entity.highlight_amount)
|
||||
|
||||
rlgl.PushMatrix(); defer rlgl.PopMatrix()
|
||||
rlgl.Translatef(entity.position.x, entity.position.y, 0)
|
||||
rlgl.Rotatef(entity.rotation * math.DEG_PER_RAD, 0, 0, 1)
|
||||
rlgl.Scalef(1 + 0.02 * highlight_t, 1 + 0.02 * highlight_t, 1)
|
||||
rlgl.Translatef(-entity.position.x, -entity.position.y, 0)
|
||||
|
||||
glow_color := card_glow_color(card)
|
||||
// NOTE(lilith): Shadow
|
||||
shadow_size := CARD_SIZE * 1.05
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(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),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = {0, 0, 0, 60},
|
||||
)
|
||||
|
||||
// NOTE(lilith): Base glow
|
||||
glow_color := card_backdrop_color(card)
|
||||
glow_color.a = 120
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
|
|
@ -557,22 +744,41 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
lineThick = 4,
|
||||
color = glow_color,
|
||||
)
|
||||
|
||||
{ray.BeginBlendMode(.ADDITIVE); defer ray.EndBlendMode()
|
||||
// NOTE(lilith): Highlight
|
||||
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),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = 6,
|
||||
color = highlight_color,
|
||||
)
|
||||
}
|
||||
|
||||
// NOTE(lilith): Background
|
||||
ray.DrawRectangleRounded(
|
||||
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
color = background_color(card),
|
||||
)
|
||||
|
||||
// NOTE(lilith): Border
|
||||
ray.DrawRectangleRoundedLinesEx(
|
||||
rrect_from_pos_sz(entity.position - CARD_SIZE * 0.5, CARD_SIZE),
|
||||
CARD_ROUNDNESS,
|
||||
ROUNDED_RECT_SEGMENTS,
|
||||
lineThick = 2,
|
||||
color = outline_color(card),
|
||||
color = border_color(card),
|
||||
)
|
||||
|
||||
// NOTE(lilith): Top title
|
||||
text := strings.clone_to_cstring(short_title(card), context.temp_allocator)
|
||||
font_size := f32(CARD_HEADER_TEXT_SIZE)
|
||||
text_size := ray.MeasureTextEx(game.card_top_font, text, font_size, spacing = 0)
|
||||
text_size := ray.MeasureTextEx(game.font, text, font_size, spacing = 0)
|
||||
offset: Vec2
|
||||
#partial switch card.suit {
|
||||
case .Major:
|
||||
|
|
@ -583,7 +789,7 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
offset -= CARD_SIZE * 0.5
|
||||
{ray.BeginShaderMode(game.sdf_shader); defer ray.EndShaderMode()
|
||||
ray.DrawTextEx(
|
||||
game.card_top_font,
|
||||
game.font,
|
||||
text,
|
||||
position = entity.position + offset,
|
||||
fontSize = font_size,
|
||||
|
|
@ -626,6 +832,12 @@ card_draw :: proc(handle: Card_Handle) {
|
|||
}
|
||||
}
|
||||
|
||||
entity_click_rect :: proc(entity: Card_Entity) -> (rect: ray.Rectangle) {
|
||||
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)
|
||||
}
|
||||
|
||||
state_init_solved :: proc(state: ^State) {
|
||||
state^ = {}
|
||||
for &suit_pile, suit_index in state.minor {
|
||||
|
|
@ -1156,11 +1368,9 @@ state_is_move_valid :: proc(state: State, move: Move) -> (ok: bool) #no_bounds_c
|
|||
state := state
|
||||
if move.from == move.to {return false}
|
||||
moved_card := card_from_handle(move.card)
|
||||
when !ODIN_DISABLE_ASSERT {
|
||||
from_pile := state_get_pile(&state, move.from)
|
||||
assert(len(from_pile) > 0)
|
||||
assert(slice.last(from_pile) == move.card)
|
||||
}
|
||||
from_pile := state_get_pile(&state, move.from)
|
||||
if len(from_pile) == 0 {return false}
|
||||
if slice.last(from_pile) != move.card {return false}
|
||||
|
||||
#partial switch move.from.kind {
|
||||
case .Major, .Suit:
|
||||
|
|
@ -1350,15 +1560,14 @@ game_cards_zipped :: proc() -> #soa[]struct {
|
|||
text_color :: proc(card: Card) -> ray.Color {
|
||||
switch card.suit {
|
||||
case .Major:
|
||||
// return ray.Color{250, 220, 120, 255}
|
||||
// return ray.Color{250, 230, 190, 255}
|
||||
return ray.Color{230, 230, 220, 255}
|
||||
// return ray.Color{230, 230, 220, 255}
|
||||
return ray.Color{230, 215, 210, 255}
|
||||
case .Chalice:
|
||||
return ray.Color{20, 50, 70, 255}
|
||||
return ray.Color{20, 30, 80, 255}
|
||||
case .Coin:
|
||||
return ray.Color{12, 90, 10, 255}
|
||||
return ray.Color{10, 70, 15, 255}
|
||||
case .Sword:
|
||||
return ray.Color{100, 90, 0, 255}
|
||||
return ray.Color{80, 70, 0, 255}
|
||||
case .Wand:
|
||||
return ray.Color{80, 0, 0, 255}
|
||||
}
|
||||
|
|
@ -1368,45 +1577,40 @@ text_color :: proc(card: Card) -> ray.Color {
|
|||
background_color :: proc(card: Card) -> ray.Color {
|
||||
switch card.suit {
|
||||
case .Major:
|
||||
return ray.Color{0, 0, 0, 255}
|
||||
return ray.Color{20, 10, 15, 255}
|
||||
case .Chalice, .Coin, .Sword, .Wand:
|
||||
return ray.Color{250, 240, 235, 255}
|
||||
return ray.Color{230, 215, 210, 255}
|
||||
}
|
||||
unreachable()
|
||||
}
|
||||
|
||||
outline_color :: proc(card: Card) -> ray.Color {
|
||||
border_color :: proc(card: Card) -> ray.Color {
|
||||
return text_color(card)
|
||||
// switch card.suit {
|
||||
// case .Major:
|
||||
// return ray.Color{250, 230, 190, 255}
|
||||
// case .Chalice:
|
||||
// return ray.Color{20, 50, 70, 255}
|
||||
// case .Coin:
|
||||
// return ray.Color{12, 90, 10, 255}
|
||||
// case .Sword:
|
||||
// return ray.Color{90, 80, 50, 255}
|
||||
// case .Wand:
|
||||
// return ray.Color{80, 0, 0, 255}
|
||||
// }
|
||||
// unreachable()
|
||||
}
|
||||
|
||||
card_backdrop_color :: proc(card: Card) -> ray.Color {
|
||||
switch card.suit {
|
||||
case .Major:
|
||||
return ray.Color{40, 0, 40, 255}
|
||||
// return ray.ColorFromHSV(f32(ray.GetTime() * 0.2), 0.4, 0.8)
|
||||
case .Chalice:
|
||||
return ray.Color{20, 80, 180, 255}
|
||||
case .Coin:
|
||||
return ray.Color{15, 110, 40, 255}
|
||||
case .Sword:
|
||||
return ray.Color{170, 170, 40, 255}
|
||||
case .Wand:
|
||||
return ray.Color{170, 15, 5, 255}
|
||||
}
|
||||
unreachable()
|
||||
}
|
||||
|
||||
card_glow_color :: proc(card: Card) -> ray.Color {
|
||||
switch card.suit {
|
||||
#partial switch card.suit {
|
||||
case .Major:
|
||||
return ray.Color{0, 0, 0, 255}
|
||||
// return ray.ColorFromHSV(f32(ray.GetTime() * 0.2), 0.4, 0.8)
|
||||
case .Chalice:
|
||||
return ray.Color{0, 120, 180, 255}
|
||||
case .Coin:
|
||||
return ray.Color{20, 120, 30, 255}
|
||||
case .Sword:
|
||||
return ray.Color{200, 190, 0, 255}
|
||||
case .Wand:
|
||||
return ray.Color{170, 0, 0, 255}
|
||||
return ray.Color{120, 0, 120, 255}
|
||||
}
|
||||
unreachable()
|
||||
return card_backdrop_color(card)
|
||||
}
|
||||
|
||||
short_title :: proc(card: Card) -> string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue