@@ -7,13 +7,6 @@ import (
77 "github.com/code-game-project/go-server/cg"
88)
99
10- const (
11- throttleSpeed = 1
12- turnSpeed = 220
13- maxAcceleration = 5
14- maxVelocity = 20
15- )
16-
1710type Player struct {
1811 id string
1912 username string
@@ -59,30 +52,30 @@ func (p *Player) update(delta time.Duration) {
5952func (p * Player ) move (delta time.Duration ) {
6053 if ! p .finished && p .game .running {
6154 if p .targetThrottle > p .throttle {
62- p .throttle += throttleSpeed * delta .Seconds ()
55+ p .throttle += p . game . config . ThrottleSpeed * delta .Seconds ()
6356 if p .throttle > p .targetThrottle {
6457 p .throttle = p .targetThrottle
6558 }
6659 } else if p .targetThrottle < p .throttle {
67- p .throttle -= throttleSpeed * delta .Seconds ()
60+ p .throttle -= p . game . config . ThrottleSpeed * delta .Seconds ()
6861 if p .throttle < p .targetThrottle {
6962 p .throttle = p .targetThrottle
7063 }
7164 }
7265
7366 if p .targetAngle > p .angle {
74- p .angle += turnSpeed * delta .Seconds ()
67+ p .angle += p . game . config . TurnSpeed * delta .Seconds ()
7568 if p .angle > p .targetAngle {
7669 p .angle = p .targetAngle
7770 }
7871 } else if p .targetAngle < p .angle {
79- p .angle -= turnSpeed * delta .Seconds ()
72+ p .angle -= p . game . config . TurnSpeed * delta .Seconds ()
8073 if p .angle < p .targetAngle {
8174 p .angle = p .targetAngle
8275 }
8376 }
8477
85- p .acc = VecFromAngle (p .angle ).Mul (maxAcceleration * p .throttle )
78+ p .acc = VecFromAngle (p .angle ).Mul (p . game . config . MaxAcceleration * p .throttle )
8679 } else {
8780 p .throttle = 0
8881
@@ -92,7 +85,7 @@ func (p *Player) move(delta time.Duration) {
9285 p .acc = Vec {
9386 X : - p .vel .X / velMag ,
9487 Y : - p .vel .Y / velMag ,
95- }.Mul (math .Min (maxAcceleration , math .Abs (velMag )))
88+ }.Mul (math .Min (p . game . config . MaxAcceleration , math .Abs (velMag )))
9689 }
9790
9891 if p .vel .MagnitudeSquared () < 0.01 {
@@ -136,7 +129,7 @@ outer:
136129 p .game .finishedPlayers = append (p .game .finishedPlayers , FinishedPlayer {
137130 Id : p .id ,
138131 Place : len (p .game .finishedPlayers ) + 1 ,
139- Duration : time .Now (). Sub (p .game .startTime ).Milliseconds (),
132+ Duration : time .Since (p .game .startTime ).Milliseconds (),
140133 })
141134 p .game .cg .Send (FinishedPlayersEvent , FinishedPlayersEventData {
142135 Players : p .game .finishedPlayers ,
0 commit comments