aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZach Latta <zach@zachlatta.com>2016-03-06 05:35:12 -0500
committerZach Latta <zach@zachlatta.com>2016-03-06 05:35:12 -0500
commit753d276b82a12b84fe7b3c0a6ea14fd8381978c4 (patch)
tree7993635f0710a218de3fafb97ba8113fa5534737
parent6e2716fcc3272832355fb4c995ae4b4b6cd74f05 (diff)
downloadsshtron-753d276b82a12b84fe7b3c0a6ea14fd8381978c4.tar.gz
Keep your color when you respawn
-rw-r--r--game.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/game.go b/game.go
index d296c9f..da63f9c 100644
--- a/game.go
+++ b/game.go
@@ -138,13 +138,16 @@ type Player struct {
score float64
}
-func NewPlayer(worldWidth, worldHeight int) *Player {
+// NewPlayer creates a new player. If color is below 1, a random color is chosen
+func NewPlayer(worldWidth, worldHeight int, color color.Attribute) *Player {
rand.Seed(time.Now().UnixNano())
startX := rand.Float64() * float64(worldWidth)
startY := rand.Float64() * float64(worldHeight)
- color := playerColors[rand.Intn(len(playerColors))]
+ if color < 0 {
+ color = playerColors[rand.Intn(len(playerColors))]
+ }
return &Player{
CreatedAt: time.Now(),
@@ -588,17 +591,17 @@ type Session struct {
func NewSession(c ssh.Channel, worldWidth, worldHeight int) *Session {
s := Session{c: c}
- s.newGame(worldWidth, worldHeight)
+ s.newGame(worldWidth, worldHeight, -1)
return &s
}
-func (s *Session) newGame(worldWidth, worldHeight int) {
- s.Player = NewPlayer(worldWidth, worldHeight)
+func (s *Session) newGame(worldWidth, worldHeight int, color color.Attribute) {
+ s.Player = NewPlayer(worldWidth, worldHeight, color)
}
func (s *Session) StartOver(worldWidth, worldHeight int) {
- s.newGame(worldWidth, worldHeight)
+ s.newGame(worldWidth, worldHeight, s.Player.Color)
}
func (s *Session) Read(p []byte) (int, error) {
Un proyecto texto-plano.xyz