@@ -108,10 +108,19 @@ embed "assets/v2/d-.png" as img_dm
108
108
embed "assets/v2/dcoff.png" as img_dcoff
109
109
embed "assets/v2/dcon.png" as img_dcon
110
110
111
- embed "assets/v2/faces/front.png" as img_face_front
112
111
embed "assets/v2/faces/win.png" as img_face_win
113
112
embed "assets/v2/faces/loss.png" as img_face_loss
114
113
114
+ embed "assets/v2/faces/front.png" as img_face_front
115
+ embed "assets/v2/faces/blink.png" as img_face_blink
116
+
117
+ embed "assets/v2/faces/look_m.png" as img_face_look_m
118
+ embed "assets/v2/faces/look_l.png" as img_face_look_l
119
+ embed "assets/v2/faces/look_ll.png" as img_face_look_ll
120
+ embed "assets/v2/faces/look_r.png" as img_face_look_r
121
+ embed "assets/v2/faces/look_rr.png" as img_face_look_rr
122
+
123
+
115
124
embed "assets/v2/display1.png" as img_display1
116
125
117
126
fn loadTexture(byte[] imageData) texture {
@@ -157,9 +166,9 @@ fn main() {
157
166
let int gyOff = 150
158
167
let int cellSize = 45
159
168
160
- let int gridWidth = 13
161
- let int gridHeight = 13
162
- let int mineCount = 20
169
+ let int gridWidth = 11
170
+ let int gridHeight = 11
171
+ let int mineCount = 18
163
172
164
173
let float gameTime = 0
165
174
@@ -211,9 +220,17 @@ fn main() {
211
220
let texture dcon = loadTexture(img_dcon)
212
221
213
222
let rect faceSize = rect!{0,0,600,550}
214
- let texture texFaceFront = loadTexture(img_face_front)
215
223
let texture texFaceLoss = loadTexture(img_face_loss)
216
224
let texture texFaceWin = loadTexture(img_face_win)
225
+
226
+ let texture texFaceFront = loadTexture(img_face_front)
227
+ let texture texFaceBlink = loadTexture(img_face_blink)
228
+
229
+ let texture texFaceLookM = loadTexture(img_face_look_m)
230
+ let texture texFaceLookL = loadTexture(img_face_look_l)
231
+ let texture texFaceLookLL = loadTexture(img_face_look_ll)
232
+ let texture texFaceLookR = loadTexture(img_face_look_r)
233
+ let texture texFaceLookRR = loadTexture(img_face_look_rr)
217
234
# TEXTURES
218
235
219
236
@@ -239,6 +256,13 @@ fn main() {
239
256
let float animTimerBlink = 0
240
257
let bool animTimerBlinkState = false
241
258
259
+ let int animFaceState = 0
260
+ let float animChangeStateTimer = 0
261
+ let int BLINK = 0
262
+ let int FOLLOW = 1
263
+ let bool animBlinkState = false
264
+ let float animBlink = 0
265
+
242
266
243
267
while !WindowShouldClose() {
244
268
mut acceptInput = !gameEnded
@@ -284,6 +308,66 @@ fn main() {
284
308
}
285
309
286
310
let texture faceT = texFaceFront
311
+ mut animChangeStateTimer = animChangeStateTimer - dt
312
+
313
+ if animChangeStateTimer < 0 {
314
+ let int newState = rand() %% 2
315
+ mut animChangeStateTimer = (rand() %% 6 + 3)->float
316
+ mut animFaceState = newState
317
+ }
318
+
319
+
320
+ if animFaceState == BLINK {
321
+ mut animBlink = animBlink - dt
322
+
323
+ if animBlink < 0 {
324
+ mut animBlinkState = !animBlinkState
325
+ if animBlinkState {
326
+ mut animBlink = (rand() %% 3 + 1)->float
327
+ }
328
+ else {
329
+ mut animBlink = 0.2
330
+ }
331
+ }
332
+
333
+ if animBlinkState
334
+ mut faceT = texFaceFront
335
+ else
336
+ mut faceT = texFaceBlink
337
+ }
338
+ else if animFaceState == FOLLOW {
339
+ let float faceX = faceX + faceWidth/2
340
+ let float faceY = faceY + faceHeight/2
341
+
342
+ let float mouseX = GetMouseX()->float - faceX
343
+ let float mouseY = GetMouseY()->float - faceY
344
+
345
+ let float hypo = sqrt((mouseX*mouseX + mouseY*mouseY)->double)->float
346
+
347
+ let float ratio = mouseY / hypo
348
+
349
+
350
+ let float middleThreshold = 0.95
351
+ let float slightlyThreshold = 0.7
352
+
353
+
354
+ if ratio > middleThreshold or ratio < 0-middleThreshold
355
+ mut faceT = texFaceLookM
356
+ else if ratio > slightlyThreshold or ratio < 0-slightlyThreshold {
357
+ if mouseX < 0
358
+ mut faceT = texFaceLookL
359
+ else
360
+ mut faceT = texFaceLookR
361
+ }
362
+ else {
363
+ if mouseX < 0
364
+ mut faceT = texFaceLookLL
365
+ else
366
+ mut faceT = texFaceLookRR
367
+ }
368
+ }
369
+
370
+
287
371
if gameWon mut faceT = texFaceWin
288
372
if gameLost mut faceT = texFaceLoss
289
373
@@ -459,6 +543,8 @@ if acceptInput {
459
543
# abs is taken in clib i suppose, i definitely need to do the module system
460
544
fn mabs(int i) int { if i > 0 ret i else ret -i ret 0 }
461
545
546
+ cfn sqrt(double f) double
547
+
462
548
fn countFlags(cell[][] grid) int {
463
549
let int flagCount = 0
464
550
for i from 0 until grid.len {
0 commit comments