Add keyboard play: arrows/WASD/hjkl focus, Enter/Space flips

Focus ring appears on the first key press and hides when the mouse moves.
Enter also triggers Play Again on the win panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SansanandClaude Opus 5.5 committed 2026-10-01 21:34:00 +02:00
1 parent 8214fda8f6
commit 685182b25d
4 files changed
+74 -9

No files matched your search

+10 -6
View File
@@ -229,18 +229,17 @@ smoothstep :: proc(t: f32) -> f32 {
return t * t * (3 - 2 * t)
}
draw :: proc(card: ^Card, theme: themes.Theme, clickable: bool) {
draw :: proc(card: ^Card, theme: themes.Theme, clickable: bool, focused := false) {
eased := smoothstep(card.flip_t)
squash := abs(math.cos(eased * math.PI)) // 1 → 0 → 1 across the flip
showing_face := eased >= 0.5
// Cards lift as they turn, and a little on hover
lift := math.sin(eased * math.PI) * 6
hovered := clickable && is_hovered(card)
if hovered {
lift += HOVER_LIFT
ui.set_hovered()
}
mouse_over := clickable && is_hovered(card)
if mouse_over { ui.set_hovered() }
hovered := mouse_over || (clickable && focused)
if hovered { lift += HOVER_LIFT }
scale: f32 = 1
if card.pulse_t > 0 {
@@ -273,6 +272,11 @@ draw :: proc(card: ^Card, theme: themes.Theme, clickable: bool) {
dest := raylib.Rectangle{center.x, center.y, width * squash, height}
raylib.DrawTexturePro(texture, source, dest, {dest.width / 2, dest.height / 2}, 0, tint)
if focused {
ring := raylib.Rectangle{center.x - width * squash / 2 - 6, center.y - height / 2 - 6, width * squash + 12, height + 12}
raylib.DrawRectangleRoundedLinesEx(ring, ROUNDNESS, SEGMENTS, 3, raylib.Fade(theme.ink, 0.75))
}
if card.matched && card.flip_t == 1 {
outline := raylib.Rectangle{center.x - width / 2 - 3, center.y - height / 2 - 3, width + 6, height + 6}
raylib.DrawRectangleRoundedLinesEx(outline, ROUNDNESS, SEGMENTS, 3, theme.accent)