1
0
Fork 0

feat: show score and increment when lines are cleared

This commit is contained in:
Henrik Hautakoski 2025-09-15 08:47:18 +02:00
parent 14520e047c
commit b6a33d017f

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"image/color" "image/color"
"tetris/assets" "tetris/assets"
@ -16,6 +17,7 @@ import (
var ( var (
shape game.Shape shape game.Shape
shape_pos core.Vec2i8 shape_pos core.Vec2i8
score game.Score
dropTimer = core.NewIntervalTimer(0.3) dropTimer = core.NewIntervalTimer(0.3)
moveTimer = core.NewIntervalTimer(0.1) moveTimer = core.NewIntervalTimer(0.1)
grid = game.Grid{} grid = game.Grid{}
@ -82,7 +84,7 @@ func Update(delta float32) {
// Update position if it does not collide // Update position if it does not collide
if game.CheckShapeCollision(new_pos, &shape, &grid) { if game.CheckShapeCollision(new_pos, &shape, &grid) {
LockShape() LockShape()
grid.ClearFullRows() score.Lines(grid.ClearFullRows())
SpawnShape() SpawnShape()
} else { } else {
shape_pos = new_pos shape_pos = new_pos
@ -96,7 +98,7 @@ func Render() {
draw.DrawShape(rl.NewVector2(25, 25), shape_pos, shape) draw.DrawShape(rl.NewVector2(25, 25), shape_pos, shape)
r.DrawFrame(rl.RectangleInt32{X: 400, Y: 25, Width: 250, Height: 100}) r.DrawFrame(rl.RectangleInt32{X: 400, Y: 25, Width: 250, Height: 100})
r.DrawHeaderText(410, 30, "Score") r.DrawHeaderText(410, 30, "Score")
r.DrawText(410, 65, "999999") r.DrawText(410, 65, fmt.Sprintf("%.7d", score))
r.DrawFrame(rl.RectangleInt32{X: 400, Y: 150, Width: 250, Height: 200}) r.DrawFrame(rl.RectangleInt32{X: 400, Y: 150, Width: 250, Height: 200})
render.End() render.End()
} }