feat: add CheckShapeCollision()
This commit is contained in:
parent
ab69d501b9
commit
27c10af424
1 changed files with 21 additions and 0 deletions
21
game/collision.go
Normal file
21
game/collision.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package game
|
||||
|
||||
import "tetris/engine/core"
|
||||
|
||||
func CheckShapeCollision(pos core.Vec2i8, shape *Shape, grid *Grid) bool {
|
||||
for _, block := range shape.Coordinates() {
|
||||
block = pos.Add(block)
|
||||
|
||||
// Can't collide if block is above the grid.
|
||||
if block.Y < 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if the block collides with the bottom of the grid.
|
||||
if block.Y >= int8(grid.Height()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue