1
0
Fork 0
tetris-go/game/collision.go

29 lines
563 B
Go

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
}
if block.X < 0 || block.X >= int8(grid.Width()) {
return true
}
// Check if the block collides with the bottom of the grid.
if block.Y >= int8(grid.Height()) {
return true
}
if grid.At(byte(block.X), byte(block.Y)) != BLOCK_EMPTY {
return true
}
}
return false
}