~sircmpwn/cells

ref: 2816bf27a73cbf6bcfc22f1df83e626abfba0345 cells/messages.go -rw-r--r-- 964 bytes View raw
2816bf27Drew DeVault Implement local drawing operations 3 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
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 CellMapMessage struct {
	Message
	Coords Coordinates                    `json:"coords"`
	Cells  [CHUNK_SIZE * CHUNK_SIZE]Color `json:"cells"`
}

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"`
}