-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathachievements.go
More file actions
237 lines (213 loc) · 5.1 KB
/
achievements.go
File metadata and controls
237 lines (213 loc) · 5.1 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package main
import (
"bytes"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"log"
)
var checkAchievement func(g *game)
var achievementBarSpr *ebiten.Image
var achievementBarChosenSpr *ebiten.Image
var starUnlockedSpr *ebiten.Image
var starLockedSpr *ebiten.Image
type achievement struct {
completed bool
fullName string
checkFunc func(g *game)
description string
}
var achievements = map[string]*achievement{
"allAchievements": {
false,
"All achievements",
achievementAllAchievements,
"Complete all achievements!",
},
"resettedSimulation": {
false,
"Reset it",
achievementResettedSimulation,
"Reset the simulation.",
},
"allDead": {
false,
"The board is empty!",
achievementAllDead,
"Get no animals on the board.",
},
"allOver300": {
false,
"Getting a bit crowdy",
achievementAllOver300,
"Get over 300 animals of each\ntype.",
},
"brokenChart": {
false,
"Hey! You broke the chart!",
achievementBrokenChart,
"Get over 900 carnivores\nor herbivores.",
},
"theyCanDrown": {
false,
"They can drown?!",
achievementTheyCanDrown,
"A herbivore or a carnivore\nhas drowned",
},
"massStarvation": {
false,
"Mass starvation",
achievementMassStarvation,
"All carnivores have speed\nequal to 0.",
},
"fromHeroToZeroHerbi": {
false,
"From hero to zero",
achievementFromHeroToZeroHerbi,
"Get a herbivore with all\ngenes equal to 0.",
},
"fromZeroToHeroCarni": {
false,
"From zero to hero",
achievementFromZeroToHeroCarni,
"Get a carnivore with all\ngenes equal to 7.",
},
"theFastestWillPrevail": {
false,
"The fastest will prevail",
achievementTheFastestWillPrevail,
"Herbivores have average\nspeed equal to 6.9 or more.",
},
"armsRace": {
false,
"Arms race",
achievementArmsRace,
"Carnivores have average\nspeed equal to 6.5 or more.",
},
}
var achievementNames = []string{
"allAchievements",
"resettedSimulation",
"allDead",
"allOver300",
"theyCanDrown",
"brokenChart",
"massStarvation",
"fromHeroToZeroHerbi",
"fromZeroToHeroCarni",
"theFastestWillPrevail",
"armsRace",
}
func init() {
var err error
achievementBarReader := bytes.NewReader(spr.achievementBarBytes)
achievementBarSpr, _, err = ebitenutil.NewImageFromReader(achievementBarReader)
if err != nil {
log.Fatal(err)
}
achievementBarChosenReader := bytes.NewReader(spr.achievementBarChosenBytes)
achievementBarChosenSpr, _, err = ebitenutil.NewImageFromReader(achievementBarChosenReader)
if err != nil {
log.Fatal(err)
}
starUnlockedReader := bytes.NewReader(spr.starUnlockedBytes)
starUnlockedSpr, _, err = ebitenutil.NewImageFromReader(starUnlockedReader)
if err != nil {
log.Fatal(err)
}
starLockedReader := bytes.NewReader(spr.starLockedBytes)
starLockedSpr, _, err = ebitenutil.NewImageFromReader(starLockedReader)
if err != nil {
log.Fatal(err)
}
}
func achievementAllAchievements(g *game) {
for i := range g.a {
if i == "allAchievements" {
continue
}
if !g.a[i].completed {
return
}
}
g.a["allAchievements"].completed = true
}
func achievementResettedSimulation(g *game) {
for _, event := range g.currentEvents {
if event == "simulation reset" {
g.a["resettedSimulation"].completed = true
return
}
}
}
func achievementAllDead(g *game) {
if len(g.herbivores) == 0 && len(g.carnivores) == 0 {
g.a["allDead"].completed = true
}
}
func achievementAllOver300(g *game) {
if len(g.herbivores) >= 300 && len(g.carnivores) >= 300 {
g.a["allOver300"].completed = true
}
}
func achievementBrokenChart(g *game) {
if len(g.herbivores) > 900 || len(g.carnivores) > 900 {
g.a["brokenChart"].completed = true
}
}
func achievementTheyCanDrown(g *game) {
for _, event := range g.currentEvents {
if event == "herbivore drowned" || event == "carnivore drowned" {
g.a["theyCanDrown"].completed = true
return
}
}
}
func achievementMassStarvation(g *game) {
if g.d.carnivoresSpeedsCounters[0] == 0 {
return
}
for i := 1; i < len(g.d.carnivoresSpeedsCounters); i++ {
if g.d.carnivoresSpeedsCounters[i] != 0 {
return
}
}
g.a["massStarvation"].completed = true
}
func achievementFromHeroToZeroHerbi(g *game) {
for _, h := range g.herbivores {
if h.dna[0] == 0 && h.dna[1] == 0 && h.dna[2] == 0 && h.dna[3] == 0 {
g.a["fromHeroToZeroHerbi"].completed = true
}
}
}
func achievementFromZeroToHeroCarni(g *game) {
for _, c := range g.carnivores {
if c.dna[0] == 7 && c.dna[1] == 7 && c.dna[2] == 7 && c.dna[3] == 7 {
g.a["fromZeroToHeroCarni"].completed = true
}
}
}
func achievementTheFastestWillPrevail(g *game) {
if g.d.herbivoresSpeedsCounters[7] == 0 {
return
}
sum := 0
for i := 0; i < len(g.d.herbivoresSpeedsCounters); i++ {
sum += g.d.herbivoresSpeedsCounters[i] * i
}
if float64(sum)/float64(len(g.herbivores)) >= 6.9 {
g.a["theFastestWillPrevail"].completed = true
}
}
func achievementArmsRace(g *game) {
if g.d.carnivoresSpeedsCounters[7] == 0 {
return
}
sum := 0
for i := 0; i < len(g.d.carnivoresSpeedsCounters); i++ {
sum += g.d.carnivoresSpeedsCounters[i] * i
}
if float64(sum)/float64(len(g.carnivores)) >= 6.5 {
g.a["armsRace"].completed = true
}
}