From ab69d501b9e0e82358873e431cc934ad74821361 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 14 Sep 2025 22:00:26 +0200 Subject: [PATCH] feat: implement shape drop --- main.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 5b27ee2..1e36656 100644 --- a/main.go +++ b/main.go @@ -13,26 +13,11 @@ import ( 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() + shape_pos := core.Vec2i8{X: 4, Y: 0} + dropTimer := core.NewIntervalTimer(0.3) + grid := game.Grid{} // Set random blocks to test render.Init(render.Config{ @@ -62,6 +47,10 @@ func main() { } for !rl.WindowShouldClose() { + if dropTimer.UpdateReset(rl.GetFrameTime()) { + shape_pos.Y += 1 + } + render.Begin(r.Theme.GridBackground) r.DrawGrid(rl.NewVector2(25, 25), grid) draw.DrawShape(rl.NewVector2(25, 25), shape_pos, shape)