From 129b44e56f546a4a80f4a70aeadcc89c77f9eee4 Mon Sep 17 00:00:00 2001 From: Joop Kiefte Date: Sat, 12 Sep 2020 09:32:20 +0200 Subject: Add floor detection to free pieces and correct collision detection field, should fix #1 --- tris/core.go | 4 ++-- tris/move.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tris/core.go b/tris/core.go index 0b5afff..d0164e2 100644 --- a/tris/core.go +++ b/tris/core.go @@ -44,9 +44,9 @@ type Placement struct { Lock time.Time } -func (p Placement) Collide(f Field) bool { //TODO: Fix first piece collision bug +func (p Placement) Collide(f Field) bool { pf, ok := p.Field() - for x := 0; x < 9; x++ { + for x := 0; x < 10; x++ { for y := 0; y < 20; y++ { if f[y][x] && pf[y][x] { return true diff --git a/tris/move.go b/tris/move.go index 29140b8..26dd568 100644 --- a/tris/move.go +++ b/tris/move.go @@ -12,7 +12,7 @@ func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, t np.X = x np.Y = y if !np.Collide(f) { // free air - return np, false, false + return np, np.Floor(f), false } np = p // last resort reset p if np.Floor(f) && np.Y < 0 { -- cgit v1.2.3-70-g09d2