Animate game over display

This commit is contained in:
Trevor Slocum 2019-11-07 16:50:49 -08:00
parent 87b67c6127
commit 4c4f6a3aeb
8 changed files with 60 additions and 36 deletions

View file

@ -1,3 +1,6 @@
0.1.3:
- Animate game over display
0.1.2:
- Resolve early game over issue
- Resolve display issue when rendering at size 3

View file

@ -400,7 +400,7 @@ func renderPlayerDetails(m *mino.Matrix, bs int) {
func renderMatrixes(mx []*mino.Matrix) {
renderBuffer.Reset()
if mx == nil || len(mx) == 0 {
if len(mx) == 0 {
return
}

6
go.mod
View file

@ -9,8 +9,8 @@ require (
github.com/gdamore/tcell v1.3.0
github.com/gliderlabs/ssh v0.2.2
github.com/mattn/go-isatty v0.0.10
github.com/mattn/go-runewidth v0.0.5 // indirect
github.com/mattn/go-runewidth v0.0.6 // indirect
github.com/tslocum/tview v0.0.0-20191018041445-09b275a4b660
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/sys v0.0.0-20191025090151-53bf42e6b339 // indirect
golang.org/x/crypto v0.0.0-20191107222254-f4817d981bb6
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd // indirect
)

12
go.sum
View file

@ -18,15 +18,15 @@ github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW1
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.5 h1:jrGtp51JOKTWgvLFzfG6OtZOJcK2sEnzc/U+zw7TtbA=
github.com/mattn/go-runewidth v0.0.5/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/tslocum/tview v0.0.0-20191018041445-09b275a4b660 h1:f/g7DFokEN2PRyGN4vIadgCDTTOoBoxiIxf4q1Re9PI=
github.com/tslocum/tview v0.0.0-20191018041445-09b275a4b660/go.mod h1:vUK8oe0CfwPjo5JouPDJq6g9+KsPiASsJP4yndpkzTg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191107222254-f4817d981bb6 h1:VsmCukA2gDdC3Mu6evOIT0QjLSQWiJIwzv1Bdj4jdzU=
golang.org/x/crypto v0.0.0-20191107222254-f4817d981bb6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
@ -35,8 +35,8 @@ golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191025090151-53bf42e6b339 h1:zSqWKgm/o7HAnlAzBQ+aetp9fpuyytsXnKA8eiLHYQM=
golang.org/x/sys v0.0.0-20191025090151-53bf42e6b339/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd h1:3x5uuvBgE6oaXJjCOvpCC1IpgJogqQ+PqGGU3ZxAgII=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

View file

@ -361,7 +361,7 @@ func (s *Conn) JoinGame(name string, gameID int, newGame *ListedGame, logger cha
g.Start(p.Seed)
if p.Started {
g.Players[g.LocalPlayer].Matrix.GameOver = true
g.Players[g.LocalPlayer].Matrix.SetGameOver()
}
go g.HandleReadCommands(s.In)

View file

@ -156,7 +156,7 @@ func (g *Game) AddPlayerL(p *Player) {
p.Matrix.PlayerName = p.Name
if g.Started {
p.Matrix.GameOver = true
p.Matrix.SetGameOver()
}
if g.LocalPlayer == PlayerHost {
@ -580,7 +580,7 @@ func (g *Game) HandleReadCommands(in chan GameCommandInterface) {
g.StartL(p.Seed)
if p.Started {
g.Players[g.LocalPlayer].Matrix.GameOver = true
g.Players[g.LocalPlayer].Matrix.SetGameOver()
}
}
case CommandUpdateMatrix:

View file

@ -60,6 +60,7 @@ func (s *SSHServer) Host(newPlayers chan<- *game.IncomingPlayer) {
}
cmdCtx, cancelCmd := context.WithCancel(sshSession.Context())
defer cancelCmd()
cmd := exec.CommandContext(cmdCtx, s.NetrisBinary, "--nick", game.Nickname(sshSession.User()), "--server", s.NetrisAddress)
cmd.Env = append(cmd.Env, fmt.Sprintf("TERM=%s", ptyReq.Term))
@ -84,7 +85,6 @@ func (s *SSHServer) Host(newPlayers chan<- *game.IncomingPlayer) {
}()
io.Copy(sshSession, f)
cancelCmd()
cmd.Wait()
},
PtyCallback: func(ctx ssh.Context, pty ssh.Pty) bool {

View file

@ -62,6 +62,10 @@ type Matrix struct {
}
func I(x int, y int, w int) int {
if x < 0 || x >= w || y < 0 {
log.Fatalf("failed to calculate matrix index %d %d %d", x, y, w)
}
return (y * w) + x
}
@ -452,7 +456,7 @@ func (m *Matrix) DrawPiecesL() {
}
}
// Draw piece
// Draw active piece
err := m.add(p, p.Solid, Point{p.X, p.Y}, true)
if err != nil {
log.Fatalf("failed to draw active piece: %+v", err)
@ -466,9 +470,8 @@ func (m *Matrix) Block(x int, y int) Block {
index := I(x, y, m.W)
// Return overlay block first
b := m.O[index]
if b != BlockNone {
// Return overlay block when present
if b := m.O[index]; b != BlockNone {
return b
}
@ -488,26 +491,44 @@ func (m *Matrix) SetGameOver() {
m.ComboStart = time.Time{}
m.ComboEnd = time.Time{}
for i := range m.M {
if m.M[i] != BlockNone && m.M[i] != BlockGarbage {
switch m.M[i] {
case BlockSolidBlue:
m.M[i] = BlockGhostBlue
case BlockSolidCyan:
m.M[i] = BlockGhostCyan
case BlockSolidGreen:
m.M[i] = BlockGhostGreen
case BlockSolidMagenta:
m.M[i] = BlockGhostMagenta
case BlockSolidOrange:
m.M[i] = BlockGhostOrange
case BlockSolidRed:
m.M[i] = BlockGhostRed
case BlockSolidYellow:
m.M[i] = BlockGhostYellow
go func() {
for y := 0; y < m.H+m.B-1; y++ {
m.Lock()
if !m.GameOver {
m.Unlock()
return
}
for x := 0; x < m.W; x++ {
i := I(x, y, m.W)
switch m.M[i] {
case BlockSolidBlue:
m.M[i] = BlockGhostBlue
case BlockSolidCyan:
m.M[i] = BlockGhostCyan
case BlockSolidGreen:
m.M[i] = BlockGhostGreen
case BlockSolidMagenta:
m.M[i] = BlockGhostMagenta
case BlockSolidOrange:
m.M[i] = BlockGhostOrange
case BlockSolidRed:
m.M[i] = BlockGhostRed
case BlockSolidYellow:
m.M[i] = BlockGhostYellow
}
}
m.Draw()
m.Unlock()
time.Sleep(7 * time.Millisecond)
}
}
}()
}
func (m *Matrix) SetBlock(x int, y int, block Block, overlay bool) bool {