-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.odin
73 lines (57 loc) · 1.72 KB
/
main.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import "core:fmt"
import "core:strings"
import rl "vendor:raylib"
SCREEN_WIDTH :: 500 // 200 offset for UI
SCREEN_HEIGHT :: 620 // 20 offset for UI
lastUpdateTime: f64
BlockMoveInterval :: 0.2
eventTriggered :: proc(interval: f64 = BlockMoveInterval) -> bool {
if rl.GetTime() - lastUpdateTime >= interval {
lastUpdateTime = rl.GetTime()
return true
}
return false
}
main :: proc() {
rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Block Game - Odin")
rl.SetTargetFPS(120)
font := rl.LoadFontEx("fonts/monogram.ttf", 64, nil, 0)
game := Game_New()
lastUpdateTime: f32 = 0
for !rl.WindowShouldClose() {
rl.UpdateMusicStream(game.music)
Game_HandleInput(&game)
if eventTriggered(0.2) {
Game_MoveBlockDown(&game)
}
sb := strings.builder_make() // will default to 16 cap, 0 len
defer strings.builder_destroy(&sb)
score := fmt.sbprintf(&sb, "%d", game.score)
scoreText := strings.to_string(sb)
scoreTextCString := strings.clone_to_cstring(scoreText)
scoreTextSize := rl.MeasureTextEx(font, scoreTextCString, 38, 2)
rl.BeginDrawing()
{
rl.ClearBackground(Colors[.DarkBlue])
rl.DrawTextEx(font, "Score", rl.Vector2{365, 15}, 38, 2, rl.WHITE)
rl.DrawRectangleRounded(rl.Rectangle{320, 55, 170, 60}, 0.3, 0, Colors[.LightBlue])
rl.DrawTextEx(
font,
scoreTextCString,
rl.Vector2{320 + (170 - scoreTextSize.x) / 2, 65},
38,
2,
rl.WHITE,
)
rl.DrawTextEx(font, "Next", rl.Vector2{370, 175}, 38, 2, rl.WHITE)
rl.DrawRectangleRounded(rl.Rectangle{320, 215, 170, 180}, 0.3, 0, Colors[.LightBlue])
if game.gameOver {
rl.DrawTextEx(font, "GAME OVER", rl.Vector2{320, 450}, 38, 2, rl.WHITE)
}
Game_Draw(&game)
rl.DrawFPS(10, 10)
}
rl.EndDrawing()
}
}