implement ability to lose and win in fishing minigame
This commit is contained in:
16
audio.sex
16
audio.sex
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
(define MENU-CLICK-FILE "res/music/01 - Menu.ogg")
|
(define MENU-CLICK-FILE "res/music/01 - Menu.ogg")
|
||||||
(define FISHING-SPOT-FILE "res/music/02 - Fishing Spot.ogg")
|
(define FISHING-SPOT-FILE "res/music/02 - Fishing Spot.ogg")
|
||||||
|
(define FISHING-START-FILE "res/music/03 - Catch!.ogg")
|
||||||
|
(define GOTCHA-FILE "res/music/04 - Gotcha!.ogg")
|
||||||
(define MENU-MUSIC-FILE "res/music/Catch-Phase 01 - Fishing.ogg")
|
(define MENU-MUSIC-FILE "res/music/Catch-Phase 01 - Fishing.ogg")
|
||||||
(define GAME-MUSIC-FILE "res/music/Catch-Phase 03 - Aqua World.ogg")
|
(define GAME-MUSIC-FILE "res/music/Catch-Phase 03 - Aqua World.ogg")
|
||||||
(define FISHING-MUSIC-FILE "res/music/Catch-Phase 05 - FIH.ogg")
|
(define FISHING-MUSIC-FILE "res/music/Catch-Phase 05 - FIH.ogg")
|
||||||
|
|
||||||
(var menu-click Sound)
|
(var menu-click Sound)
|
||||||
(var fishing-spot-sound Sound)
|
(var fishing-spot-sound Sound)
|
||||||
|
(var fishing-start-sound Sound)
|
||||||
|
(var gotcha-sound Sound)
|
||||||
|
|
||||||
(var menu-music Music)
|
(var menu-music Music)
|
||||||
(var game-music Music)
|
(var game-music Music)
|
||||||
@@ -32,6 +36,8 @@
|
|||||||
(pub fn audio-init () void
|
(pub fn audio-init () void
|
||||||
(= menu-click (load-sound MENU-CLICK-FILE))
|
(= menu-click (load-sound MENU-CLICK-FILE))
|
||||||
(= fishing-spot-sound (load-sound FISHING-SPOT-FILE))
|
(= fishing-spot-sound (load-sound FISHING-SPOT-FILE))
|
||||||
|
(= fishing-start-sound (load-sound FISHING-START-FILE))
|
||||||
|
(= gotcha-sound (load-sound GOTCHA-FILE))
|
||||||
(= menu-music (load-music MENU-MUSIC-FILE))
|
(= menu-music (load-music MENU-MUSIC-FILE))
|
||||||
(= game-music (load-music GAME-MUSIC-FILE))
|
(= game-music (load-music GAME-MUSIC-FILE))
|
||||||
(= fishing-music (load-music FISHING-MUSIC-FILE)))
|
(= fishing-music (load-music FISHING-MUSIC-FILE)))
|
||||||
@@ -43,6 +49,8 @@
|
|||||||
|
|
||||||
(UnloadSound menu-click)
|
(UnloadSound menu-click)
|
||||||
(UnloadSound fishing-spot-sound)
|
(UnloadSound fishing-spot-sound)
|
||||||
|
(UnloadSound fishing-start-sound)
|
||||||
|
(UnloadSound gotcha-sound)
|
||||||
(UnloadMusicStream menu-music)
|
(UnloadMusicStream menu-music)
|
||||||
(UnloadMusicStream game-music)
|
(UnloadMusicStream game-music)
|
||||||
(UnloadMusicStream fishing-music))
|
(UnloadMusicStream fishing-music))
|
||||||
@@ -95,3 +103,11 @@
|
|||||||
(pub fn audio-play-fishing-spot () void
|
(pub fn audio-play-fishing-spot () void
|
||||||
(if (IsSoundValid fishing-spot-sound)
|
(if (IsSoundValid fishing-spot-sound)
|
||||||
(PlaySound fishing-spot-sound)))
|
(PlaySound fishing-spot-sound)))
|
||||||
|
|
||||||
|
(pub fn audio-play-fishing-start () void
|
||||||
|
(if (IsSoundValid fishing-start-sound)
|
||||||
|
(PlaySound fishing-start-sound)))
|
||||||
|
|
||||||
|
(pub fn audio-play-gotcha () void
|
||||||
|
(if (IsSoundValid gotcha-sound)
|
||||||
|
(PlaySound gotcha-sound)))
|
||||||
|
|||||||
145
game.sex
145
game.sex
@@ -19,11 +19,13 @@
|
|||||||
(define FISHING-POPUP-PADDING 32.0f)
|
(define FISHING-POPUP-PADDING 32.0f)
|
||||||
(define BOBBER-WIDTH 28.0f)
|
(define BOBBER-WIDTH 28.0f)
|
||||||
(define BOBBER-HEIGHT 36.0f)
|
(define BOBBER-HEIGHT 36.0f)
|
||||||
|
(define FISH-GAP 20.0f)
|
||||||
|
(define FISH-SPEED 0.75f)
|
||||||
|
|
||||||
;; Physics is expressed in abstract units; this maps them to popup pixels
|
;; Physics is expressed in abstract units; this maps them to popup pixels
|
||||||
(define BOBBER-SCALE 32.0f)
|
(define BOBBER-SCALE 32.0f)
|
||||||
|
|
||||||
(var bobber-impulse float 5.0f)
|
(var bobber-impulse float 1.0f)
|
||||||
(var bobber-g float 6.8f)
|
(var bobber-g float 6.8f)
|
||||||
(var bobber-mass float 1.0f)
|
(var bobber-mass float 1.0f)
|
||||||
|
|
||||||
@@ -53,7 +55,17 @@
|
|||||||
|
|
||||||
;; Bobber height above the bottom of the popup and its vertical velocity
|
;; Bobber height above the bottom of the popup and its vertical velocity
|
||||||
(bobber-y float)
|
(bobber-y float)
|
||||||
(bobber-vy float)))
|
(bobber-vy float)
|
||||||
|
|
||||||
|
(catch-progress float)
|
||||||
|
(fish-y float)
|
||||||
|
(fish-vy float)
|
||||||
|
(fish-next-y float)
|
||||||
|
(fish-move-cooldown float)
|
||||||
|
|
||||||
|
;; Caught fish counter
|
||||||
|
(caught-fish int)
|
||||||
|
(fish-texture Texture2D)))
|
||||||
|
|
||||||
(ops camera
|
(ops camera
|
||||||
(fn init ((self (* camera))) void
|
(fn init ((self (* camera))) void
|
||||||
@@ -108,9 +120,24 @@
|
|||||||
FISHING-POPUP-WIDTH
|
FISHING-POPUP-WIDTH
|
||||||
FISHING-POPUP-HEIGHT)))
|
FISHING-POPUP-HEIGHT)))
|
||||||
|
|
||||||
|
(fn fishing-bobber-range () float
|
||||||
|
(return (- FISHING-POPUP-HEIGHT
|
||||||
|
(* 4.0f FISHING-POPUP-PADDING)
|
||||||
|
BOBBER-HEIGHT)))
|
||||||
|
|
||||||
|
(fn random-float ((lo float) (hi float)) float
|
||||||
|
(return (+ lo
|
||||||
|
(* (- hi lo)
|
||||||
|
(/ (cast (GetRandomValue 0 10000) float) 10000.0f)))))
|
||||||
|
|
||||||
|
(fn pick-fish-target ((state (* game-state))) void
|
||||||
|
(= (. state fish-next-y) (random-float 0.0f 1.0f))
|
||||||
|
(= (. state fish-move-cooldown) (random-float 0.5f 2.0f)))
|
||||||
|
|
||||||
(pub fn mk-game ((app-state (* app-state))) page
|
(pub fn mk-game ((app-state (* app-state))) page
|
||||||
(var state _ (mem-alloc game-state))
|
(var state _ (mem-alloc game-state))
|
||||||
(= (. state app-state) app-state)
|
(= (. state app-state) app-state)
|
||||||
|
(= (. state fish-texture) (LoadTexture "res/img/small-fish.png"))
|
||||||
(audio-play-game-music)
|
(audio-play-game-music)
|
||||||
|
|
||||||
(var map (* tmx-map) (load-tmx MAP-FILE))
|
(var map (* tmx-map) (load-tmx MAP-FILE))
|
||||||
@@ -154,11 +181,21 @@
|
|||||||
(= (. state bobber-y) 0.0f)
|
(= (. state bobber-y) 0.0f)
|
||||||
(= (. state bobber-vy) 0.0f)
|
(= (. state bobber-vy) 0.0f)
|
||||||
|
|
||||||
|
(= (. state catch-progress) 0.5f)
|
||||||
|
(= (. state fish-y) 0.5f)
|
||||||
|
(= (. state fish-vy) 0.0f)
|
||||||
|
(= (. state fish-next-y) 0.5f)
|
||||||
|
(= (. state fish-move-cooldown) 0.0f)
|
||||||
|
|
||||||
|
(= (. state caught-fish) 0)
|
||||||
|
|
||||||
(.init (& (. state cam)))
|
(.init (& (. state cam)))
|
||||||
(return (page/game state)))
|
(return (page/game state)))
|
||||||
|
|
||||||
(pub fn rm-game ((state (* game-state))) void
|
(pub fn rm-game ((state (* game-state))) void
|
||||||
(unload-tmx (. state map))
|
(unload-tmx (. state map))
|
||||||
|
(if (IsTextureValid (. state fish-texture))
|
||||||
|
(UnloadTexture (. state fish-texture)))
|
||||||
(free state)
|
(free state)
|
||||||
(return))
|
(return))
|
||||||
|
|
||||||
@@ -180,6 +217,22 @@
|
|||||||
(var bobber-bottom float
|
(var bobber-bottom float
|
||||||
(- (+ (. popup y) (. popup height))
|
(- (+ (. popup y) (. popup height))
|
||||||
FISHING-POPUP-PADDING))
|
FISHING-POPUP-PADDING))
|
||||||
|
|
||||||
|
(var progress-bar-length int (- (. popup width) (* 2 FISHING-POPUP-PADDING)))
|
||||||
|
(var progress-bar-bg _
|
||||||
|
#(Rectangle :
|
||||||
|
(+ (. popup x) -1 FISHING-POPUP-PADDING)
|
||||||
|
(+ (. popup y) -1 -10 (* 3 FISHING-POPUP-PADDING))
|
||||||
|
(+ progress-bar-length 2)
|
||||||
|
8))
|
||||||
|
(DrawRectangleLinesEx progress-bar-bg 1.0f DARKBROWN)
|
||||||
|
(var progress-bar _
|
||||||
|
#(Rectangle :
|
||||||
|
(+ (. popup x) FISHING-POPUP-PADDING)
|
||||||
|
(+ (. popup y) -10 (* 3 FISHING-POPUP-PADDING))
|
||||||
|
(* progress-bar-length (. state catch-progress))
|
||||||
|
6))
|
||||||
|
(DrawRectangleRec progress-bar BLUE)
|
||||||
(var bobber-bg _
|
(var bobber-bg _
|
||||||
#(Rectangle :
|
#(Rectangle :
|
||||||
(+ (. popup x)
|
(+ (. popup x)
|
||||||
@@ -198,7 +251,29 @@
|
|||||||
BOBBER-WIDTH
|
BOBBER-WIDTH
|
||||||
BOBBER-HEIGHT))
|
BOBBER-HEIGHT))
|
||||||
(DrawRectangleRec bobber-rect GOLD)
|
(DrawRectangleRec bobber-rect GOLD)
|
||||||
(DrawRectangleLinesEx bobber-rect 2.0f DARKBROWN))
|
(DrawRectangleLinesEx bobber-rect 2.0f DARKBROWN)
|
||||||
|
|
||||||
|
;; Fish sprite sits beside the bobber and moves over the same range
|
||||||
|
(if (IsTextureValid (. state fish-texture))
|
||||||
|
(do
|
||||||
|
(var fish-range float (fishing-bobber-range))
|
||||||
|
(var fish-width float (cast (. state fish-texture width) float))
|
||||||
|
(var fish-height float (cast (. state fish-texture height) float))
|
||||||
|
(var fish-rect _
|
||||||
|
#(Rectangle :
|
||||||
|
(+ (. popup x)
|
||||||
|
(/ (- (. popup width) BOBBER-WIDTH) 2.0f)
|
||||||
|
BOBBER-WIDTH
|
||||||
|
FISH-GAP)
|
||||||
|
(- bobber-bottom
|
||||||
|
(* (. state fish-y) fish-range)
|
||||||
|
fish-height)
|
||||||
|
fish-width
|
||||||
|
fish-height))
|
||||||
|
(DrawTexture (. state fish-texture)
|
||||||
|
(cast (. fish-rect x) int)
|
||||||
|
(cast (. fish-rect y) int)
|
||||||
|
WHITE))))
|
||||||
|
|
||||||
(pub fn render-game ((state (* game-state))) void
|
(pub fn render-game ((state (* game-state))) void
|
||||||
(BeginDrawing)
|
(BeginDrawing)
|
||||||
@@ -215,7 +290,7 @@
|
|||||||
(draw-tmx-layer (. state map) "objects" (& (. state cam ray-cam)))
|
(draw-tmx-layer (. state map) "objects" (& (. state cam ray-cam)))
|
||||||
(EndMode2D)
|
(EndMode2D)
|
||||||
|
|
||||||
(DrawText "WASD/arrows: move X near fishing spot: fish ESC: back to menu"
|
(DrawText (TextFormat "WASD/arrows: move X near fishing spot: fish ESC: back to menu Fish caught: %d" (. state caught-fish))
|
||||||
10 10 20 RAYWHITE)
|
10 10 20 RAYWHITE)
|
||||||
|
|
||||||
;; Show the interaction key above the player when near a fishing spot
|
;; Show the interaction key above the player when near a fishing spot
|
||||||
@@ -283,7 +358,7 @@
|
|||||||
(clamp dt 0.0f 0.05f)
|
(clamp dt 0.0f 0.05f)
|
||||||
|
|
||||||
;; X gives the bobber an upward impulse
|
;; X gives the bobber an upward impulse
|
||||||
(if (IsKeyPressed KEY-X)
|
(if (IsKeyDown KEY-X)
|
||||||
(+= (. state bobber-vy)
|
(+= (. state bobber-vy)
|
||||||
(/ (* bobber-impulse BOBBER-SCALE) bobber-mass)))
|
(/ (* bobber-impulse BOBBER-SCALE) bobber-mass)))
|
||||||
|
|
||||||
@@ -293,12 +368,8 @@
|
|||||||
(+= (. state bobber-y) (* (. state bobber-vy) dt))
|
(+= (. state bobber-y) (* (. state bobber-vy) dt))
|
||||||
|
|
||||||
;; Keep the bobber inside the confines
|
;; Keep the bobber inside the confines
|
||||||
(var popup Rectangle (fishing-popup-rect))
|
|
||||||
(var min-y float 0.0f)
|
(var min-y float 0.0f)
|
||||||
(var max-y float
|
(var max-y float (fishing-bobber-range))
|
||||||
(- (. popup height)
|
|
||||||
(* 4.0f FISHING-POPUP-PADDING)
|
|
||||||
BOBBER-HEIGHT))
|
|
||||||
(if (< (. state bobber-y) min-y)
|
(if (< (. state bobber-y) min-y)
|
||||||
(do
|
(do
|
||||||
(= (. state bobber-y) min-y)
|
(= (. state bobber-y) min-y)
|
||||||
@@ -309,12 +380,56 @@
|
|||||||
(if (> (. state bobber-vy) 0.0f)
|
(if (> (. state bobber-vy) 0.0f)
|
||||||
(= (. state bobber-vy) 0.0f))))
|
(= (. state bobber-vy) 0.0f))))
|
||||||
|
|
||||||
;; ESC closes the popup instead of leaving the game page
|
;; Fish waits for its cooldown, then moves to the next target height
|
||||||
(if (IsKeyReleased KEY-ESCAPE)
|
(if (> (. state fish-move-cooldown) 0.0f)
|
||||||
|
(-= (. state fish-move-cooldown) dt))
|
||||||
|
(if (<= (. state fish-move-cooldown) 0.0f)
|
||||||
|
(do
|
||||||
|
(var dy float (- (. state fish-next-y) (. state fish-y)))
|
||||||
|
(if (&& (< dy 0.01f) (> dy -0.01f))
|
||||||
|
(do
|
||||||
|
(= (. state fish-y) (. state fish-next-y))
|
||||||
|
(= (. state fish-vy) 0.0f)
|
||||||
|
(pick-fish-target state))
|
||||||
|
(do
|
||||||
|
(= (. state fish-vy)
|
||||||
|
(if (> dy 0.0f) FISH-SPEED (- FISH-SPEED)))
|
||||||
|
(+= (. state fish-y) (* (. state fish-vy) dt))
|
||||||
|
(if (> dy 0.0f)
|
||||||
|
(if (>= (. state fish-y) (. state fish-next-y))
|
||||||
|
(do
|
||||||
|
(= (. state fish-y) (. state fish-next-y))
|
||||||
|
(= (. state fish-vy) 0.0f)))
|
||||||
|
(if (<= (. state fish-y) (. state fish-next-y))
|
||||||
|
(do
|
||||||
|
(= (. state fish-y) (. state fish-next-y))
|
||||||
|
(= (. state fish-vy) 0.0f))))))))
|
||||||
|
|
||||||
|
;; Fill the catch meter while the bobber and fish are at the same
|
||||||
|
;; height, otherwise let it drain.
|
||||||
|
(var bobber-y-normalized float
|
||||||
|
(if (> max-y 0.0f) (/ (. state bobber-y) max-y) 0.0f))
|
||||||
|
(var fish-height-diff float
|
||||||
|
(- bobber-y-normalized (. state fish-y)))
|
||||||
|
(if (&& (<= fish-height-diff 0.10f)
|
||||||
|
(>= fish-height-diff -0.10f))
|
||||||
|
(+= (. state catch-progress) (* dt 0.2))
|
||||||
|
(-= (. state catch-progress) (* dt 0.05)))
|
||||||
|
|
||||||
|
;; ESC closes the popup instead of leaving the game page,
|
||||||
|
;; also popup closes when catch-progress becomes negative
|
||||||
|
(if (|| (IsKeyReleased KEY-ESCAPE)
|
||||||
|
(> (. state catch-progress) 1.0f)
|
||||||
|
(< (. state catch-progress) 0.0f))
|
||||||
(do
|
(do
|
||||||
(= (. state fishing-minigame-active) false)
|
(= (. state fishing-minigame-active) false)
|
||||||
(= (. state bobber-y) 0.0f)
|
(= (. state bobber-y) 0.0f)
|
||||||
(= (. state bobber-vy) 0.0f)
|
(= (. state bobber-vy) 0.0f)
|
||||||
|
(= (. state fish-vy) 0.0f)
|
||||||
|
(if (> (. state catch-progress) 1.0f)
|
||||||
|
(do
|
||||||
|
(audio-play-gotcha)
|
||||||
|
(++ (. state caught-fish))))
|
||||||
(audio-play-game-music))))
|
(audio-play-game-music))))
|
||||||
|
|
||||||
(pub fn update-game ((state (* game-state))) void
|
(pub fn update-game ((state (* game-state))) void
|
||||||
@@ -365,5 +480,11 @@
|
|||||||
(= (. state fishing-minigame-active) true)
|
(= (. state fishing-minigame-active) true)
|
||||||
(= (. state bobber-y) 0.0f)
|
(= (. state bobber-y) 0.0f)
|
||||||
(= (. state bobber-vy) 0.0f)
|
(= (. state bobber-vy) 0.0f)
|
||||||
|
(= (. state catch-progress) 0.5f)
|
||||||
|
;; Fish always starts in the middle of the bobber range
|
||||||
|
(= (. state fish-y) 0.5f)
|
||||||
|
(= (. state fish-vy) 0.0f)
|
||||||
|
(pick-fish-target state)
|
||||||
|
(audio-play-fishing-start)
|
||||||
(audio-play-fishing-music)
|
(audio-play-fishing-music)
|
||||||
(TraceLog LOG-INFO "Starting fishing minigame!"))))))
|
(TraceLog LOG-INFO "Starting fishing minigame!"))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user