aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-09-12 08:25:24 +0200
committerJoop Kiefte <ikojba@gmail.com>2020-09-12 08:25:24 +0200
commitac3196415d5d87a745d339f1548573b0b5745c41 (patch)
treeb296d16875d98b965b7520797294358156ee3b08 /main.go
parentbc89ff176ddf7cf9627df15e8624d94a040a1d0b (diff)
Creating move routine to implement kicks in
Diffstat (limited to 'main.go')
-rw-r--r--main.go51
1 files changed, 33 insertions, 18 deletions
diff --git a/main.go b/main.go
index a705b00..19a170e 100644
--- a/main.go
+++ b/main.go
@@ -22,43 +22,39 @@ func GetKey() []byte {
func main() {
var f tris.Field
+ var floor, topout bool
+ var x, y int
+ var rot tris.Rotation
fmt.Print("\033[2J") // Clear screen
b := tris.NewBag()
b, p := b.Pick()
t := time.Tick(time.Second / 60)
- ds := time.NewTicker(time.Second)
for {
-// fmt.Print("\033[2J") // Clear screen
+ x, y, rot = p.X, p.Y, p.Rot
fmt.Print("\033[0;0H") // Position to 0,0
fmt.Println(f.Add(p).String())
- select {
- case <-ds.C:
- np, ok := p.Drop(f)
- if ok {
- p = np
- p.Lock = time.Now()
- }
- if time.Now().Sub(p.Lock) > tris.LockDelay {
- f = f.Add(p)
- b, p = b.Pick()
- }
- case <-t:
- }
key := GetKey()
switch key[0] {
case 27: // Escape, read the arrow key pressed
switch key[2] {
case 65: // Up
- p.Rot = (p.Rot + 1)%4
+ rot = (p.Rot + 1)%4
case 66: // Down
+ y = p.Y + 1
case 67: // Right
- p.X++
+ x = p.X + 1
case 68: // Left
- p.X--
+ x = p.X - 1
default:
fmt.Println("...escape, escape!")
return
}
+ case 'x':
+ rot = (p.Rot + 1)%4
+ case 'z':
+ rot = (p.Rot + 3)%4
+ case ' ':
+ y = 20
case 'q':
fmt.Println("...that was exciting!")
return
@@ -66,5 +62,24 @@ func main() {
fmt.Println("...never let an engineer pick the name of your software?")
return
}
+ select {
+ case <-t:
+ y = p.Y + 1
+ default:
+ }
+ p, floor, topout = p.Move(f, rot, x, y)
+ if floor && p.Lock.Add(tris.LockDelay).Before(time.Now()) {
+ fmt.Print("\033[2J") // Clear screen
+ f = f.Add(p)
+ b, p = b.Pick()
+ }
+ if !floor {
+ p.Lock = time.Now()
+ }
+
+ if topout {
+ fmt.Println("GAME OVER")
+ return
+ }
}
}