Track src modules; stop ignoring .odin files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SansanandClaude Opus 5.5 committed 2026-10-01 20:40:13 +02:00
1 parent 33d55357cf
commit 964d9987be
9 files changed
+597 -17

No files matched your search

+218
View File
@@ -0,0 +1,218 @@
package memory
import raylib "vendor:raylib"
import themes "../themes"
import card "../card"
import assets "../assets"
MemoryState :: enum {
WAITING,
FIRST,
SECOND,
OVER,
}
memory_cards: [24]card.Card
memory_state: MemoryState
memory_first: i32
memory_second: i32
memory_matches: i32
memory_moves: i32
memory_time: f32
memory_flip: f32
init_memory_game :: proc() {
hiragana_chars: [12]cstring = {"あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し"}
romanji_chars: [12]cstring = {"A", "I", "U", "E", "O", "KA", "KI", "KU", "KE", "KO", "SA", "SHI"}
for i := 0; i < 12; i += 1 {
memory_cards[i*2] = card.Card{
x = 0, y = 0,
character = romanji_chars[i],
is_face_up = false,
is_matched = false,
pair_id = i32(i),
flip_progress = 0.0,
is_flipping = false,
flip_direction = false,
}
memory_cards[i*2+1] = card.Card{
x = 0, y = 0,
character = romanji_chars[i],
is_face_up = false,
is_matched = false,
pair_id = i32(i),
flip_progress = 0.0,
is_flipping = false,
flip_direction = false,
}
}
for i := 0; i < 100; i += 1 {
a := i % 24
b := (i * 7) % 24
temp := memory_cards[a]
memory_cards[a] = memory_cards[b]
memory_cards[b] = temp
}
total_w := themes.GRID_COLS * (themes.CARD_WIDTH + themes.CARD_SPACING) - themes.CARD_SPACING
total_h := themes.GRID_ROWS * (themes.CARD_HEIGHT + themes.CARD_SPACING) - themes.CARD_SPACING
start_x := (themes.SCREEN_WIDTH - total_w) / 2
start_y := (themes.SCREEN_HEIGHT - total_h) / 2
for i := 0; i < 24; i += 1 {
row := i32(i) / themes.GRID_COLS
col := i32(i) % themes.GRID_COLS
memory_cards[i].x = start_x + col * (themes.CARD_WIDTH + themes.CARD_SPACING)
memory_cards[i].y = start_y + row * (themes.CARD_HEIGHT + themes.CARD_SPACING)
}
memory_state = MemoryState.WAITING
memory_first = -1
memory_second = -1
memory_matches = 0
memory_moves = 0
memory_time = 0.0
memory_flip = 0.0
}
update_memory_game :: proc(delta_time: f32, mouse_x, mouse_y: i32) {
memory_time += delta_time
if memory_state == MemoryState.SECOND {
memory_flip += delta_time
if memory_flip >= themes.FLIP_DELAY {
if memory_first >= 0 && memory_second >= 0 {
if memory_cards[memory_first].pair_id == memory_cards[memory_second].pair_id {
memory_cards[memory_first].is_matched = true
memory_cards[memory_second].is_matched = true
memory_matches += 1
} else {
memory_cards[memory_first].is_flipping = true
memory_cards[memory_first].flip_direction = false
memory_cards[memory_first].flip_progress = 0.0
memory_cards[memory_second].is_flipping = true
memory_cards[memory_second].flip_direction = false
memory_cards[memory_second].flip_progress = 0.0
}
}
memory_state = MemoryState.WAITING
memory_flip = 0.0
memory_first = -1
memory_second = -1
}
}
// Update flip animations
for i := 0; i < 24; i += 1 {
if memory_cards[i].is_flipping {
memory_cards[i].flip_progress += delta_time * 3.0 // Flip speed
if memory_cards[i].flip_progress >= 1.0 {
memory_cards[i].flip_progress = 1.0
memory_cards[i].is_flipping = false
memory_cards[i].is_face_up = memory_cards[i].flip_direction
}
}
}
if memory_state == MemoryState.WAITING || memory_state == MemoryState.FIRST {
for i := 0; i < 24; i += 1 {
if !memory_cards[i].is_matched && !memory_cards[i].is_flipping {
if card.is_card_clicked(&memory_cards[i], mouse_x, mouse_y) &&
raylib.IsMouseButtonPressed(raylib.MouseButton.LEFT) {
memory_cards[i].is_flipping = true
memory_cards[i].flip_direction = true
memory_cards[i].flip_progress = 0.0
memory_moves += 1
if memory_first == -1 {
memory_first = i32(i)
memory_state = MemoryState.FIRST
} else if i32(i) != memory_first {
memory_second = i32(i)
memory_state = MemoryState.SECOND
}
break
}
}
}
}
if memory_matches >= 12 {
memory_state = MemoryState.OVER
}
}
draw_memory_game :: proc(mouse_x, mouse_y: i32) -> i32 {
raylib.ClearBackground(themes.JAPAN_BACKGROUND)
font := assets.get_font()
title: cstring = "Memory Game - Japanese"
title_w := raylib.MeasureText(title, themes.TITLE_FONT_SIZE)
title_x := (themes.SCREEN_WIDTH - title_w) / 2
raylib.DrawTextEx(font, title, raylib.Vector2{f32(title_x + 4), 54}, f32(themes.TITLE_FONT_SIZE), 0, themes.BLACK)
raylib.DrawTextEx(font, title, raylib.Vector2{f32(title_x), 50}, f32(themes.TITLE_FONT_SIZE), 0, themes.JAPAN_PRIMARY)
info_text := raylib.TextFormat("Moves: %d | Time: %.1fs", memory_moves, memory_time)
info_w := raylib.MeasureText(info_text, themes.SUBTITLE_FONT_SIZE)
info_x := (themes.SCREEN_WIDTH - info_w) / 2
raylib.DrawTextEx(font, info_text, raylib.Vector2{f32(info_x), 150}, f32(themes.SUBTITLE_FONT_SIZE), 0, themes.DARK_GRAY)
for i := 0; i < 24; i += 1 {
card.draw_card(&memory_cards[i], mouse_x, mouse_y, themes.JAPAN_PRIMARY)
}
back_w := themes.BUTTON_WIDTH
back_h := themes.BUTTON_HEIGHT
back_x := (themes.SCREEN_WIDTH - back_w) / 2
back_y := themes.SCREEN_HEIGHT - 100
back_hovered := mouse_x >= back_x && mouse_x <= back_x + back_w &&
mouse_y >= back_y && mouse_y <= back_y + back_h
back_color := themes.JAPAN_PRIMARY
if back_hovered {
back_color = themes.JAPAN_ACCENT
}
raylib.DrawRectangle(back_x, back_y, back_w, back_h, back_color)
raylib.DrawRectangleLines(back_x, back_y, back_w, back_h, themes.BLACK)
back_text: cstring = "Back"
back_text_w := raylib.MeasureText(back_text, themes.BUTTON_FONT_SIZE)
back_text_x := back_x + (back_w - back_text_w) / 2
back_text_y := back_y + (back_h - themes.BUTTON_FONT_SIZE) / 2
raylib.DrawTextEx(font, back_text, raylib.Vector2{f32(back_text_x), f32(back_text_y)}, f32(themes.BUTTON_FONT_SIZE), 0, themes.WHITE)
if back_hovered && raylib.IsMouseButtonPressed(raylib.MouseButton.LEFT) {
return themes.JAPANESE_SCREEN
}
if memory_state == MemoryState.OVER {
raylib.DrawRectangle(0, 0, themes.SCREEN_WIDTH, themes.SCREEN_HEIGHT, raylib.Color{0, 0, 0, 128})
win_text: cstring = "Congratulations! You Win!"
win_w := raylib.MeasureText(win_text, 48)
win_x := (themes.SCREEN_WIDTH - win_w) / 2
raylib.DrawTextEx(font, win_text, raylib.Vector2{f32(win_x), f32(themes.SCREEN_HEIGHT / 2 - 60)}, 48, 0, themes.WHITE)
stats_text := raylib.TextFormat("Moves: %d | Time: %.1fs", memory_moves, memory_time)
stats_w := raylib.MeasureText(stats_text, 32)
stats_x := (themes.SCREEN_WIDTH - stats_w) / 2
raylib.DrawTextEx(font, stats_text, raylib.Vector2{f32(stats_x), f32(themes.SCREEN_HEIGHT / 2)}, 32, 0, themes.WHITE)
again_text: cstring = "Play Again"
again_w := raylib.MeasureText(again_text, themes.BUTTON_FONT_SIZE)
again_x := (themes.SCREEN_WIDTH - again_w) / 2
again_y := themes.SCREEN_HEIGHT / 2 + 60
again_hovered := mouse_x >= again_x && mouse_x <= again_x + again_w &&
mouse_y >= again_y && mouse_y <= again_y + themes.BUTTON_FONT_SIZE
again_color := themes.JAPAN_PRIMARY
if again_hovered {
again_color = themes.JAPAN_ACCENT
}
raylib.DrawTextEx(font, again_text, raylib.Vector2{f32(again_x), f32(again_y)}, f32(themes.BUTTON_FONT_SIZE), 0, again_color)
if again_hovered && raylib.IsMouseButtonPressed(raylib.MouseButton.LEFT) {
init_memory_game()
}
}
return themes.JAPANESE_MEMORY
}