掉落器(未完成)
This commit is contained in:
parent
2ddf2217bd
commit
3750008947
|
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ func PositionArrayToXY(position [2]int) (x, y int) {
|
||||||
return position[0], position[1]
|
return position[0], position[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PositionClone 克隆一个坐标数组
|
||||||
func PositionClone(position [2]int) [2]int {
|
func PositionClone(position [2]int) [2]int {
|
||||||
return [2]int{position[0], position[1]}
|
return [2]int{position[0], position[1]}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue