feat: show score and increment when lines are cleared
This commit is contained in:
parent
14520e047c
commit
b6a33d017f
1 changed files with 4 additions and 2 deletions
6
main.go
6
main.go
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue