feat: lock and spawn shapes
This commit is contained in:
parent
3c847094a0
commit
a6072e5b05
1 changed files with 22 additions and 3 deletions
25
main.go
25
main.go
|
|
@ -14,10 +14,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
shape = game.NewShape(game.SHAPE_O)
|
||||
shape_pos = core.Vec2i8{X: 4, Y: 0}
|
||||
shape game.Shape
|
||||
shape_pos core.Vec2i8
|
||||
dropTimer = core.NewIntervalTimer(0.3)
|
||||
grid = game.Grid{}
|
||||
nextShape game.ShapeType
|
||||
|
||||
r = draw.Renderer{
|
||||
Theme: &draw.Theme{
|
||||
|
|
@ -30,13 +31,29 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func SpawnShape() {
|
||||
shape = game.NewShape(nextShape)
|
||||
shape_pos = core.Vec2i8{X: 4, Y: 0}
|
||||
nextShape = (nextShape + 1) % 7
|
||||
}
|
||||
|
||||
func LockShape() {
|
||||
for _, block := range shape.Coordinates() {
|
||||
block = shape_pos.Add(block)
|
||||
grid.Set(byte(block.X), byte(block.Y), shape.GetBlock())
|
||||
}
|
||||
}
|
||||
|
||||
func Update(delta float32) {
|
||||
if dropTimer.UpdateReset(delta) {
|
||||
new_pos := shape_pos
|
||||
new_pos.Y += 1
|
||||
|
||||
// Update position if it does not collide
|
||||
if !game.CheckShapeCollision(new_pos, &shape, &grid) {
|
||||
if game.CheckShapeCollision(new_pos, &shape, &grid) {
|
||||
LockShape()
|
||||
SpawnShape()
|
||||
} else {
|
||||
shape_pos = new_pos
|
||||
}
|
||||
}
|
||||
|
|
@ -71,6 +88,8 @@ func main() {
|
|||
render.SetTexture(texture)
|
||||
render.SetFont(&assets.Font)
|
||||
|
||||
SpawnShape()
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
Update(rl.GetFrameTime())
|
||||
Render()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue