File tree Expand file tree Collapse file tree 1 file changed +20
-13
lines changed Expand file tree Collapse file tree 1 file changed +20
-13
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ func (g *Game) onPlayerJoined(cgPlayer *cg.Player) {
7373 }
7474
7575 g .hovercrafts [cgPlayer .Id ] = Hovercraft {}
76+
77+ g .positionHovercrafts ()
7678}
7779
7880func (g * Game ) onPlayerLeft (player * cg.Player ) {
@@ -82,6 +84,7 @@ func (g *Game) onPlayerLeft(player *cg.Player) {
8284 }
8385
8486 if ! g .running {
87+ g .positionHovercrafts ()
8588 for _ , p := range g .players {
8689 if ! p .ready {
8790 return
@@ -231,8 +234,6 @@ func (g *Game) start() {
231234 g .finishedPlayers = 0
232235 g .createCheckpoints ()
233236
234- x := 0.0
235- i := 0
236237 for _ , player := range g .players {
237238 player .ready = false
238239 player .vel = Vec {}
@@ -245,17 +246,6 @@ func (g *Game) start() {
245246 player .finished = false
246247 player .checkpoints = make ([]Vec , len (g .checkpoints ))
247248 copy (player .checkpoints , g .checkpoints )
248-
249- player .pos = Vec {
250- X : x ,
251- Y : 0 ,
252- }
253- if i % 2 != 0 {
254- player .pos .X = - x
255- }
256-
257- x += 1.5
258- i ++
259249 }
260250
261251 g .update (0 )
@@ -278,6 +268,23 @@ func (g *Game) start() {
278268 g .cg .Send ("server" , StartEvent , StartEventData {})
279269}
280270
271+ func (g * Game ) positionHovercrafts () {
272+ x := 0.0
273+ i := 0
274+ for _ , player := range g .players {
275+ player .pos = Vec {
276+ X : x ,
277+ Y : 0 ,
278+ }
279+ if i % 2 != 0 {
280+ player .pos .X = - x
281+ } else {
282+ x += 1.5
283+ }
284+ i ++
285+ }
286+ }
287+
281288func (g * Game ) finish () {
282289 g .running = false
283290}
You can’t perform that action at this time.
0 commit comments