ui.go
1940 bytes
1package game
2
3import (
4 "fmt"
5
6 "gitea.theedgeofrage.com/theedgeofrage/yeetris/elements"
7 "github.com/gen2brain/raylib-go/raylib"
8)
9
10type UI struct {
11 ScreenWidth int32
12 ScreenHeight int32
13 BoardWidth int32
14 BoardHeight int32
15 BoardOffset rl.Vector2
16 UIOffsetWidth int32
17 NextPiecePosition rl.Vector2
18 HeldPiecePosition rl.Vector2
19
20 Score int
21}
22
23func InitUI(scale rl.Vector2) *UI {
24 boardWidth := 10 * int32(scale.X)
25 boardHeight := 20 * int32(scale.Y)
26 screenWidth := boardWidth + 40 + 300
27 screenHeight := boardHeight + 40
28 rl.InitWindow(screenWidth, screenHeight, "Yeetris")
29
30 return &UI{
31 ScreenWidth: screenWidth,
32 ScreenHeight: screenHeight,
33 BoardWidth: boardWidth,
34 BoardHeight: boardHeight,
35 BoardOffset: rl.NewVector2(20, 20),
36 UIOffsetWidth: boardWidth + 40 + 20,
37 NextPiecePosition: rl.NewVector2(float32(boardWidth+40+20+110), 250),
38 HeldPiecePosition: rl.NewVector2(float32(boardWidth+40+20+110), 510),
39 }
40}
41
42func drawRectangleBorder(x, y, width, height, border int32, color rl.Color) {
43 rl.DrawRectangle(x-border, y-border, width+2*border, height+2*border, color)
44 rl.DrawRectangle(x, y, width, height, elements.Black)
45}
46
47func (u *UI) Draw(g *Game) {
48 drawRectangleBorder(int32(u.BoardOffset.X), int32(u.BoardOffset.Y), u.BoardWidth, u.BoardHeight, 20, elements.Gray)
49 rl.DrawText("Yeetris", u.UIOffsetWidth, 20, 40, rl.White)
50 rl.DrawText(fmt.Sprintf("Score: %d", u.Score), u.UIOffsetWidth, 70, 20, rl.White)
51 rl.DrawText("Next Piece:", u.UIOffsetWidth, 110, 20, rl.White)
52 drawRectangleBorder(u.UIOffsetWidth+10, 150, 200, 200, 10, elements.Gray)
53 rl.DrawText("Hold:", u.UIOffsetWidth, 370, 20, rl.White)
54 drawRectangleBorder(u.UIOffsetWidth+10, 410, 200, 200, 10, elements.Gray)
55
56 if g.Pause {
57 rl.DrawText(
58 "GAME PAUSED",
59 u.ScreenWidth/2-rl.MeasureText("GAME PAUSED", 40)/2,
60 u.ScreenHeight/2-40,
61 40,
62 elements.LightGray,
63 )
64 }
65}