Fix ESC quitting, memory layout overlap, shuffle and move counting
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
964d9987be
commit
5557de62a3
3 files changed
+21
-23
No files matched your search
@@ -13,6 +13,7 @@ mouse_y: i32
|
||||
main :: proc() {
|
||||
raylib.InitWindow(themes.SCREEN_WIDTH, themes.SCREEN_HEIGHT, cstring("HanjaKanaMun"))
|
||||
defer raylib.CloseWindow()
|
||||
raylib.SetExitKey(raylib.KeyboardKey.KEY_NULL)
|
||||
|
||||
assets.load_fonts()
|
||||
defer assets.unload_fonts()
|
||||
|
||||
+16
-20
@@ -1,5 +1,6 @@
|
||||
package memory
|
||||
|
||||
import "core:math/rand"
|
||||
import raylib "vendor:raylib"
|
||||
import themes "../themes"
|
||||
import card "../card"
|
||||
@@ -48,18 +49,11 @@ init_memory_game :: proc() {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
rand.shuffle(memory_cards[:])
|
||||
|
||||
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
|
||||
start_y := themes.GRID_TOP
|
||||
|
||||
for i := 0; i < 24; i += 1 {
|
||||
row := i32(i) / themes.GRID_COLS
|
||||
@@ -118,18 +112,19 @@ update_memory_game :: proc(delta_time: f32, mouse_x, mouse_y: i32) {
|
||||
|
||||
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 !memory_cards[i].is_matched && !memory_cards[i].is_flipping &&
|
||||
!memory_cards[i].is_face_up && i32(i) != memory_first {
|
||||
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 {
|
||||
} else {
|
||||
memory_second = i32(i)
|
||||
memory_moves += 1
|
||||
memory_state = MemoryState.SECOND
|
||||
}
|
||||
break
|
||||
@@ -148,24 +143,25 @@ draw_memory_game :: proc(mouse_x, mouse_y: i32) -> i32 {
|
||||
|
||||
font := assets.get_font()
|
||||
title: cstring = "Memory Game - Japanese"
|
||||
title_w := raylib.MeasureText(title, themes.TITLE_FONT_SIZE)
|
||||
title_size: i32 = 48
|
||||
title_w := raylib.MeasureText(title, title_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)
|
||||
raylib.DrawTextEx(font, title, raylib.Vector2{f32(title_x + 3), 33}, f32(title_size), 0, themes.BLACK)
|
||||
raylib.DrawTextEx(font, title, raylib.Vector2{f32(title_x), 30}, f32(title_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)
|
||||
raylib.DrawTextEx(font, info_text, raylib.Vector2{f32(info_x), 92}, 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_w: i32 = 120
|
||||
back_h: i32 = 50
|
||||
back_x: i32 = 30
|
||||
back_y: i32 = 30
|
||||
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
|
||||
|
||||
@@ -26,9 +26,10 @@ TITLE_FONT_SIZE: i32 = 72
|
||||
SUBTITLE_FONT_SIZE: i32 = 24
|
||||
BUTTON_FONT_SIZE: i32 = 24
|
||||
|
||||
CARD_WIDTH: i32 = 100
|
||||
CARD_HEIGHT: i32 = 140
|
||||
CARD_SPACING: i32 = 15
|
||||
CARD_WIDTH: i32 = 90
|
||||
CARD_HEIGHT: i32 = 120
|
||||
CARD_SPACING: i32 = 12
|
||||
GRID_TOP: i32 = 140
|
||||
GRID_ROWS: i32 = 4
|
||||
GRID_COLS: i32 = 6
|
||||
FLIP_DELAY: f32 = 1.0
|
||||
|
||||
Reference in new issue
Block a user