1
0
Fork 0
tetris-go/main.go

75 lines
1.8 KiB
Go

package main
import (
"image/color"
"tetris/assets"
"tetris/engine/core"
"tetris/engine/graphics"
"tetris/engine/render"
"tetris/game"
"tetris/game/draw"
rl "github.com/gen2brain/raylib-go/raylib"
)
// Create a grid with a block patter to test
// if all the blocks renders correctly
func createGrid() *game.Grid {
grid := &game.Grid{}
c := 0
for y := range byte(grid.Height() - 4) {
for x := range byte(grid.Width()) {
grid.Set(x, y, game.Block((c%7)+1))
c++
}
}
return grid
}
func main() {
shape := game.NewShape(game.SHAPE_O)
shape_pos := core.Vec2i8{X: 1, Y: 13}
grid := createGrid()
// Set random blocks to test
render.Init(render.Config{
Title: "Tetris",
WindowWidth: 685,
WindowHeight: 600,
RenderWidth: 685,
RenderHeight: 600,
ScaleFlags: render.SCALE_INTEGER,
})
defer render.Exit()
// Load texture
texture := graphics.LoadTextureFromMemory(".png", assets.Sprite)
defer rl.UnloadTexture(texture)
render.SetTexture(texture)
render.SetFont(&assets.Font)
r := draw.Renderer{
Theme: &draw.Theme{
FrameBG: color.RGBA{R: 30, G: 30, B: 46, A: 255},
FrameBorder: color.RGBA{R: 242, G: 205, B: 205, A: 255},
TextHeader: color.RGBA{R: 242, G: 205, B: 205, A: 255},
Text: color.RGBA{R: 205, G: 214, B: 244, A: 255},
GridBackground: color.RGBA{R: 17, G: 17, B: 27, A: 255},
},
}
for !rl.WindowShouldClose() {
render.Begin(r.Theme.GridBackground)
r.DrawGrid(rl.NewVector2(25, 25), grid)
draw.DrawShape(rl.NewVector2(25, 25), shape_pos, shape)
r.DrawFrame(rl.RectangleInt32{X: 400, Y: 25, Width: 250, Height: 100})
r.DrawHeaderText(410, 30, "Score")
r.DrawText(410, 65, "999999")
r.DrawFrame(rl.RectangleInt32{X: 400, Y: 150, Width: 250, Height: 200})
render.End()
}
}