diff --git a/game.sex b/game.sex index 3b4e569..b86baec 100644 --- a/game.sex +++ b/game.sex @@ -17,9 +17,7 @@ (define FISHING-POPUP-WIDTH 480.0f) (define FISHING-POPUP-HEIGHT 560.0f) (define FISHING-POPUP-PADDING 32.0f) -(define BOBBER-WIDTH 28.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 @@ -65,7 +63,9 @@ ;; Caught fish counter (caught-fish int) - (fish-texture Texture2D))) + (popup-back Texture2D) + (popup-magnet Texture2D) + (popup-target Texture2D))) (ops camera (fn init ((self (* camera))) void @@ -137,7 +137,9 @@ (pub fn mk-game ((app-state (* app-state))) page (var state _ (mem-alloc game-state)) (= (. state app-state) app-state) - (= (. state fish-texture) (LoadTexture "res/img/small-fish.png")) + (= (. state popup-back) (LoadTexture "res/img/fishing-popup-back.png")) + (= (. state popup-magnet) (LoadTexture "res/img/fishing-popup-magnet.png")) + (= (. state popup-target) (LoadTexture "res/img/fishing-popup-target.png")) (audio-play-game-music) (var map (* tmx-map) (load-tmx MAP-FILE)) @@ -194,8 +196,12 @@ (pub fn rm-game ((state (* game-state))) void (unload-tmx (. state map)) - (if (IsTextureValid (. state fish-texture)) - (UnloadTexture (. state fish-texture))) + (if (IsTextureValid (. state popup-back)) + (UnloadTexture (. state popup-back))) + (if (IsTextureValid (. state popup-magnet)) + (UnloadTexture (. state popup-magnet))) + (if (IsTextureValid (. state popup-target)) + (UnloadTexture (. state popup-target))) (free state) (return)) @@ -204,7 +210,57 @@ ;; Dim the game behind the popup (DrawRectangle 0 0 WIN-WIDTH WIN-HEIGHT (Fade BLACK 0.5f)) - (GuiPanel popup "Fishing") + (if (IsTextureValid (. state popup-back)) + (DrawTexture (. state popup-back) + (cast (. popup x) int) + (cast (. popup y) int) + WHITE) + (GuiPanel popup "Fishing")) + + ;; Magnet hangs from the top of the popup and marks the bobber position. + (var bobber-bottom float + (- (+ (. popup y) (. popup height)) + FISHING-POPUP-PADDING)) + + (if (IsTextureValid (. state popup-magnet)) + (do + (var magnet-width float (cast (. state popup-magnet width) float)) + (var magnet-height float (cast (. state popup-magnet height) float)) + (var magnet-x float + (+ (. popup x) + (/ (- (. popup width) magnet-width) 2.0f))) + (var magnet-y float + (- bobber-bottom + magnet-height + (. state bobber-y))) + (BeginScissorMode (cast (. popup x) int) + (cast (. popup y) int) + (cast (. popup width) int) + (cast (. popup height) int)) + (DrawTexture (. state popup-magnet) + (cast magnet-x int) + (cast magnet-y int) + WHITE) + (EndScissorMode))) + + ;; Target arrows move vertically over the same range as the magnet. + (if (IsTextureValid (. state popup-target)) + (do + (var target-range float (fishing-bobber-range)) + (var target-width float (cast (. state popup-target width) float)) + (var target-height float (cast (. state popup-target height) float)) + (var target-x float + (+ (. popup x) + (/ (- (. popup width) target-width) 2.0f))) + (var target-center-y float + (- bobber-bottom + (* (. state fish-y) target-range))) + (var target-y float + (- target-center-y (/ target-height 2.0f))) + (DrawTexture (. state popup-target) + (cast target-x int) + (cast target-y int) + WHITE))) (GuiLabel #(Rectangle : (+ (. popup x) FISHING-POPUP-PADDING) @@ -213,11 +269,6 @@ 40.0f) "X: pull! ESC: leave...") - ;; The golden rectangle is the bobber, hanging at the bottom of the popup - (var bobber-bottom float - (- (+ (. popup y) (. popup height)) - FISHING-POPUP-PADDING)) - (var progress-bar-length int (- (. popup width) (* 2 FISHING-POPUP-PADDING))) (var progress-bar-bg _ #(Rectangle : @@ -232,48 +283,7 @@ (+ (. popup y) -10 (* 3 FISHING-POPUP-PADDING)) (* progress-bar-length (. state catch-progress)) 6)) - (DrawRectangleRec progress-bar BLUE) - (var bobber-bg _ - #(Rectangle : - (+ (. popup x) - -1.0f - (/ (- (. popup width) BOBBER-WIDTH) 2.0f)) - (+ (. popup y) -1.0f (* 3.0f FISHING-POPUP-PADDING)) - (+ 2.0f BOBBER-WIDTH) - (- (+ (. popup height) 2.0f) - (* 4.0f FISHING-POPUP-PADDING)))) - (DrawRectangleLinesEx bobber-bg 2.0f DARKBROWN) - (var bobber-rect _ - #(Rectangle : - (+ (. popup x) - (/ (- (. popup width) BOBBER-WIDTH) 2.0f)) - (- bobber-bottom BOBBER-HEIGHT (. state bobber-y)) - BOBBER-WIDTH - BOBBER-HEIGHT)) - (DrawRectangleRec bobber-rect GOLD) - (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)))) + (DrawRectangleRec progress-bar BLUE)) (pub fn render-game ((state (* game-state))) void (BeginDrawing) diff --git a/res/img/fishing-popup-back.png b/res/img/fishing-popup-back.png new file mode 100644 index 0000000..fef3429 Binary files /dev/null and b/res/img/fishing-popup-back.png differ diff --git a/res/img/fishing-popup-magnet.png b/res/img/fishing-popup-magnet.png new file mode 100644 index 0000000..e8edb53 Binary files /dev/null and b/res/img/fishing-popup-magnet.png differ diff --git a/res/img/fishing-popup-target.png b/res/img/fishing-popup-target.png new file mode 100644 index 0000000..bec09c2 Binary files /dev/null and b/res/img/fishing-popup-target.png differ diff --git a/res/tilemaps/start.tmx b/res/tilemaps/start.tmx index b091dbf..a473d11 100644 --- a/res/tilemaps/start.tmx +++ b/res/tilemaps/start.tmx @@ -1,5 +1,5 @@ - + @@ -829,6 +829,7 @@ +