掉落器(未完成)

This commit is contained in:
kercylan 2023-06-04 20:41:52 +08:00
parent 2ddf2217bd
commit 3750008947
2 changed files with 34 additions and 0 deletions

33
utils/g2d/dropper.go Normal file
View File

@ -0,0 +1,33 @@
package g2d
func NewDropper[T any](matrix [][]T, setPosition func(x, y, newX, newY int), allowDrop, allowCross, isObstacle func(data T) bool) *Dropper[T] {
return &Dropper[T]{
matrix: matrix,
width: len(matrix) + 1,
height: len(matrix[0]),
setPosition: setPosition,
allowDrop: allowDrop,
allowCross: allowCross,
isObstacle: isObstacle,
}
}
// Dropper 掉落器
type Dropper[T any] struct {
matrix [][]T
width, height int
setPosition func(x, y, newX, newY int)
allowDrop, allowCross, isObstacle func(data T) bool
}
func (slf *Dropper[T]) Drop() {
for x := 0; x < slf.width; x++ {
for y := slf.height - 1; y >= 0; y-- {
data := slf.matrix[x][y]
if slf.allowDrop(data) {
}
}
}
}

View File

@ -10,6 +10,7 @@ func PositionArrayToXY(position [2]int) (x, y int) {
return position[0], position[1]
}
// PositionClone 克隆一个坐标数组
func PositionClone(position [2]int) [2]int {
return [2]int{position[0], position[1]}
}