Skip to content

Commit

Permalink
fixes crash, can't assume p.ID starts anywhere in particular
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Feb 28, 2018
1 parent c6c67cd commit fbae88e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/scenegame.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-gl/mathgl/mgl32"
"github.com/jakecoffman/cp"
"log"
"sort"
"time"
"github.com/go-gl/glfw/v3.2/glfw"
"math"
Expand Down Expand Up @@ -211,17 +212,20 @@ func (g *GameScene) Gui() {
update := nk.NkBegin(g.ctx, "Score", bounds, nk.WindowTitle|nk.WindowMinimizable)
if update > 0 {
nk.NkLayoutRowDynamic(g.ctx, 0, 1)
names := make([]string, len(g.game.Tanks))
for _, p := range g.game.Tanks {
if p.Name != "" {
names[p.ID-1] = fmt.Sprint(p.Name, " - ", p.Score)
tanks := make([]*tanklets.Tank, 0, len(g.game.Tanks))
for _, t := range g.game.Tanks {
tanks = append(tanks, t)
}
sort.Slice(tanks, func(i, j int) bool {
return tanks[i].ID < tanks[j].ID
})
for _, t := range tanks {
if t.Name != "" {
nk.NkLabel(g.ctx, fmt.Sprint(t.Name, " - ", t.Score), nk.TextLeft)
} else {
names[p.ID-1] = fmt.Sprint("Player ", p.ID, " - ", p.Score)
nk.NkLabel(g.ctx, fmt.Sprint("Player ", t.ID, " - ", t.Score), nk.TextLeft)
}
}
for _, n := range names {
nk.NkLabel(g.ctx, n, nk.TextLeft)
}
}
nk.NkEnd(g.ctx)
}
Expand Down

0 comments on commit fbae88e

Please sign in to comment.