From c695245fe792c9af02f3843d9d666d2dc46ce721 Mon Sep 17 00:00:00 2001 From: Joop Kiefte Date: Tue, 8 Dec 2020 09:54:44 +0100 Subject: Add blinking shadow --- main.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 4c1645b..ee472ae 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,22 @@ func npos(l, c int, f tris.Field) { } } +func lpos(l, c int, f tris.Field) { + pos(l, c) + var line []int + for _, r := range f { + if len(line) == 0 { + line = r + } + for i := range line { + if r[i] > 0 { + line[i] = 5 + } + } + } + ppos(l, c, render(line, "\u2591\u2591", " ")) +} + func render(r []int, block, empty string) string { var s string for _, c := range r { @@ -72,6 +88,7 @@ restart: rand.Seed(time.Now().UnixNano()) // to start with truly random pieces f := tris.NewField(20, 10) // the playing field (10x20) + emptyf := tris.NewField(20, 10) // empty playing field (10x20) var floor, topout, harddrop bool // state machine variables to check special situations // define outside of game loop to avoid accidental resets of position @@ -108,6 +125,7 @@ restart: } npos(3, 0, tris.HoldBox) fpos(0, 10, f.Add(p)) + lpos(20, 10, emptyf.Add(p)) var next tris.Field b, next = b.Next(5) npos(0, 34, next) @@ -188,7 +206,13 @@ restart: linescleared += l score += 40 * level * l * l } - fmt.Print("\007\033[2J") // Clear screen and bell + go func() { + for i := 0; i < l; i++ { + fmt.Print("\007") + time.Sleep(time.Second) + } + }() + fmt.Print("\033[2J") // Clear screen b, p = b.Pick() // ... and pick a new piece from the bag } // when not touching a piece or floor below yet, reset lock delay -- cgit v1.2.3-70-g09d2