feat: add shape movement
This commit is contained in:
parent
d6a9e80fbb
commit
ac14dfe8b3
1 changed files with 13 additions and 0 deletions
13
main.go
13
main.go
|
|
@ -17,6 +17,7 @@ var (
|
||||||
shape game.Shape
|
shape game.Shape
|
||||||
shape_pos core.Vec2i8
|
shape_pos core.Vec2i8
|
||||||
dropTimer = core.NewIntervalTimer(0.3)
|
dropTimer = core.NewIntervalTimer(0.3)
|
||||||
|
moveTimer = core.NewIntervalTimer(0.1)
|
||||||
grid = game.Grid{}
|
grid = game.Grid{}
|
||||||
nextShape game.ShapeType
|
nextShape game.ShapeType
|
||||||
|
|
||||||
|
|
@ -49,6 +50,18 @@ func LockShape() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(delta float32) {
|
func Update(delta float32) {
|
||||||
|
if moveTimer.UpdateReset(delta) && (rl.IsKeyDown(rl.KeyLeft) || rl.IsKeyDown(rl.KeyRight)) {
|
||||||
|
new_pos := shape_pos
|
||||||
|
if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
|
new_pos.X -= 1
|
||||||
|
} else {
|
||||||
|
new_pos.X += 1
|
||||||
|
}
|
||||||
|
if !game.CheckShapeCollision(new_pos, &shape, &grid) {
|
||||||
|
shape_pos.X = new_pos.X
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if dropTimer.UpdateReset(delta) {
|
if dropTimer.UpdateReset(delta) {
|
||||||
new_pos := shape_pos
|
new_pos := shape_pos
|
||||||
new_pos.Y += 1
|
new_pos.Y += 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue