-
Notifications
You must be signed in to change notification settings - Fork 0
/
polygon.go
128 lines (108 loc) · 1.75 KB
/
polygon.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"github.com/square-melon/thegame/server/go/thegame/pb"
)
type Shape int
const (
Square Shape = 4
Triangle Shape = 3
Pentagon Shape = 5
)
type Polygon struct {
Entity
id int
shape Shape
}
func (p *Polygon) ID() int {
return p.id
}
func (p *Polygon) String() string {
return fmt.Sprintf("%s#%d", p.ShapeString(), p.id)
}
func (p *Polygon) ShapeString() string {
switch p.shape {
case Square:
return "Square"
case Triangle:
return "Triangle"
case Pentagon:
return "Pentagon"
default:
return "Polygon?"
}
}
func (p *Polygon) ToProto() *pb.Polygon {
return &pb.Polygon{
Entity: EntityToProto(p),
Edges: int32(p.Edges()),
}
}
func (p *Polygon) MaxHealth() int {
switch p.shape {
case Square:
return 100
case Triangle:
return 300
case Pentagon:
return 1000
default:
panic("Unknown shape")
}
}
func (p *Polygon) Edges() int {
return int(p.shape)
}
func (p *Polygon) Friction() float64 {
return 0.04
}
func (p *Polygon) IsBounded() bool {
return true
}
func (p *Polygon) MaxSpeed() float64 {
return 5
}
func (p *Polygon) Radius() float64 {
switch p.shape {
case Square:
return 20
case Triangle:
return 20
case Pentagon:
return 25
default:
panic("Unknown shape")
}
}
func (p *Polygon) Team() int {
return 0
}
func (p *Polygon) BodyDamage() int {
switch p.shape {
case Square:
return 10
case Triangle:
return 20
case Pentagon:
return 40
default:
panic("Unknown shape")
}
}
func (p *Polygon) CanAcquireExperience() bool {
return false
}
func (p *Polygon) AcquireExperience(int) {
}
func (p *Polygon) RewardingExperience() int {
switch p.shape {
case Square:
return 10
case Triangle:
return 60
case Pentagon:
return 360
default:
panic("Unknown shape")
}
}