|
| 1 | +package hoverrace |
| 2 | + |
| 3 | +import "github.com/code-game-project/go-server/cg" |
| 4 | + |
| 5 | +// The `start` event is sent when the race begins. |
| 6 | +// The game begins once at least 2 players have joined and all players have sent the `ready` event. |
| 7 | +const StartEvent cg.EventName = "start" |
| 8 | + |
| 9 | +type StartEventData struct { |
| 10 | + // The positions of all checkpoints. |
| 11 | + Checkpoints []Position `json:"checkpoints"` |
| 12 | +} |
| 13 | + |
| 14 | +// Send the `ready` event to the server when you think the game should begin. |
| 15 | +const ReadyEvent cg.EventName = "ready" |
| 16 | + |
| 17 | +type ReadyEventData struct { |
| 18 | +} |
| 19 | + |
| 20 | +// The `ready_players` event contains a list of all players which are ready. |
| 21 | +const ReadyPlayersEvent cg.EventName = "ready_players" |
| 22 | + |
| 23 | +type ReadyPlayersEventData struct { |
| 24 | + // A list of all ready players. |
| 25 | + Players []string `json:"players"` |
| 26 | +} |
| 27 | + |
| 28 | +// The `throttle` event allows you to change your throttle level and direction. |
| 29 | +// **NOTE:** This values are targets. The hovercraft needs some time to reach the desired values. |
| 30 | +const ThrottleEvent cg.EventName = "throttle" |
| 31 | + |
| 32 | +type ThrottleEventData struct { |
| 33 | + // Throttle level between 0-1. |
| 34 | + Level float64 `json:"level"` |
| 35 | + // The angle in degrees the hovercraft should be facing (up = 0°). |
| 36 | + Angle float64 `json:"angle"` |
| 37 | +} |
| 38 | + |
| 39 | +// The `hovercraft` event tells all clients where all the hovercrafts are and how they are moving. |
| 40 | +const HovercraftsEvent cg.EventName = "hovercrafts" |
| 41 | + |
| 42 | +type HovercraftsEventData struct { |
| 43 | + // All hovercrafts mapped to their respective player IDs. |
| 44 | + Hovercrafts map[string]Hovercraft `json:"hovercrafts"` |
| 45 | + // The time in UNIX seconds when this event occured. |
| 46 | + Time int64 `json:"time"` |
| 47 | +} |
| 48 | + |
| 49 | +// The `next_checkpoint` tells you the position of the next checkpoint. |
| 50 | +const NextCheckpointEvent cg.EventName = "next_checkpoint" |
| 51 | + |
| 52 | +type NextCheckpointEventData struct { |
| 53 | + // The position of the next checkpoint. |
| 54 | + Pos Position `json:"pos"` |
| 55 | +} |
| 56 | + |
| 57 | +// The `finished` event is sent when a player crosses the finish line. |
| 58 | +const FinishedEvent cg.EventName = "finished" |
| 59 | + |
| 60 | +type FinishedEventData struct { |
| 61 | + // The ID of the player who reached the finish line. |
| 62 | + Player string `json:"player"` |
| 63 | + // The place which the player has reached. |
| 64 | + Place int `json:"place"` |
| 65 | +} |
| 66 | + |
| 67 | +type Hovercraft struct { |
| 68 | + // The position of the hovercraft. |
| 69 | + Pos Position `json:"pos"` |
| 70 | + // The current speed of the hovercraft. |
| 71 | + Speed float64 `json:"speed"` |
| 72 | + // The angle in degrees the hovercraft is facing (up = 0°). |
| 73 | + Angle float64 `json:"angle"` |
| 74 | +} |
| 75 | + |
| 76 | +type Position struct { |
| 77 | + X float64 `json:"x"` |
| 78 | + Y float64 `json:"y"` |
| 79 | +} |
0 commit comments