~sircmpwn/cells

cells/messages.go -rw-r--r-- 1.1 KiB View raw
99dbe4f3Drew DeVault Refactor chunk coords into separate func 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

const CHUNK_SIZE = 32

type Color [3]int

type Position struct {
	X float32 `json:"x"`
	Y float32 `json:"y"`
}

type Coordinates struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type Player struct {
	Id       int64    `json:"id"`
	Color    [3]int   `json:"color"`
	Position Position `json:"position"`
}

type Message struct {
	Type string `json:"type"`
}

type SpawnSelfMessage struct {
	Message
	Self Player `json:"self"`
}

type SpawnPeerMessage struct {
	Message
	Peer Player `json:"peer"`
}

type DespawnPeerMessage struct {
	Message
	PeerId int64 `json:"peer_id"`
}

type PingMessage struct {
	Message
	Coords Coordinates `json:"coords"`
	Color  Color       `json:"color"`
}

type PlayerMotionMessage struct {
	Message
	PlayerId int64    `json:"player_id"`
	Position Position `json:"position"`
}

type ChunkDataMessage struct {
	Message
	Coords Coordinates                    `json:"coords"`
	Cells  [CHUNK_SIZE * CHUNK_SIZE]Color `json:"cells"`
}

type SetCellMessage struct {
	Message
	Coords Coordinates `json:"coords"`
	Color  Color       `json:"color"`
}