From 375000894783e3c17673fe0ea0c9df0ea5467fe2 Mon Sep 17 00:00:00 2001 From: kercylan <61743331+kercylan98@users.noreply.github.com> Date: Sun, 4 Jun 2023 20:41:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=89=E8=90=BD=E5=99=A8=EF=BC=88=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/g2d/dropper.go | 33 +++++++++++++++++++++++++++++++++ utils/g2d/g2d.go | 1 + 2 files changed, 34 insertions(+) create mode 100644 utils/g2d/dropper.go diff --git a/utils/g2d/dropper.go b/utils/g2d/dropper.go new file mode 100644 index 0000000..752b90c --- /dev/null +++ b/utils/g2d/dropper.go @@ -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) { + + } + } + } +} diff --git a/utils/g2d/g2d.go b/utils/g2d/g2d.go index 00a4bca..39f3734 100644 --- a/utils/g2d/g2d.go +++ b/utils/g2d/g2d.go @@ -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]} }