diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-12-08 09:54:44 +0100 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-12-08 09:54:44 +0100 |
commit | c695245fe792c9af02f3843d9d666d2dc46ce721 (patch) | |
tree | 1e53b62a2da3a2e17f20f97beecfb724d1386833 | |
parent | fd247492a1aad9df833be75d3cecd5d5e5b5c38f (diff) |
Add blinking shadow
-rw-r--r-- | main.go | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -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 |