Skip to content

Commit e92ca8e

Browse files
committed
pretty much done, but will add more features eventually
1 parent 91314e8 commit e92ca8e

File tree

9 files changed

+2156
-1084
lines changed

9 files changed

+2156
-1084
lines changed

assets/v2/faces/blink.png

21.6 KB
Loading

assets/v2/faces/look_l.png

24.1 KB
Loading

assets/v2/faces/look_ll.png

23.7 KB
Loading

assets/v2/faces/look_m.png

22.2 KB
Loading

assets/v2/faces/look_r.png

22.6 KB
Loading

assets/v2/faces/look_rr.png

22.4 KB
Loading

assets/v2/main.png

304 KB
Loading

main.S

+2,065-1,079
Large diffs are not rendered by default.

main.bz

+91-5
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,19 @@ embed "assets/v2/d-.png" as img_dm
108108
embed "assets/v2/dcoff.png" as img_dcoff
109109
embed "assets/v2/dcon.png" as img_dcon
110110

111-
embed "assets/v2/faces/front.png" as img_face_front
112111
embed "assets/v2/faces/win.png" as img_face_win
113112
embed "assets/v2/faces/loss.png" as img_face_loss
114113

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+
115124
embed "assets/v2/display1.png" as img_display1
116125

117126
fn loadTexture(byte[] imageData) texture {
@@ -157,9 +166,9 @@ fn main() {
157166
let int gyOff = 150
158167
let int cellSize = 45
159168

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
163172

164173
let float gameTime = 0
165174

@@ -211,9 +220,17 @@ fn main() {
211220
let texture dcon = loadTexture(img_dcon)
212221

213222
let rect faceSize = rect!{0,0,600,550}
214-
let texture texFaceFront = loadTexture(img_face_front)
215223
let texture texFaceLoss = loadTexture(img_face_loss)
216224
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)
217234
# TEXTURES
218235

219236

@@ -239,6 +256,13 @@ fn main() {
239256
let float animTimerBlink = 0
240257
let bool animTimerBlinkState = false
241258

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+
242266

243267
while !WindowShouldClose() {
244268
mut acceptInput = !gameEnded
@@ -284,6 +308,66 @@ fn main() {
284308
}
285309

286310
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+
287371
if gameWon mut faceT = texFaceWin
288372
if gameLost mut faceT = texFaceLoss
289373

@@ -459,6 +543,8 @@ if acceptInput {
459543
# abs is taken in clib i suppose, i definitely need to do the module system
460544
fn mabs(int i) int { if i > 0 ret i else ret -i ret 0 }
461545

546+
cfn sqrt(double f) double
547+
462548
fn countFlags(cell[][] grid) int {
463549
let int flagCount = 0
464550
for i from 0 until grid.len {

0 commit comments

Comments
 (0)