add new fishing popup
This commit is contained in:
118
game.sex
118
game.sex
@@ -17,9 +17,7 @@
|
|||||||
(define FISHING-POPUP-WIDTH 480.0f)
|
(define FISHING-POPUP-WIDTH 480.0f)
|
||||||
(define FISHING-POPUP-HEIGHT 560.0f)
|
(define FISHING-POPUP-HEIGHT 560.0f)
|
||||||
(define FISHING-POPUP-PADDING 32.0f)
|
(define FISHING-POPUP-PADDING 32.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)
|
(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
|
||||||
@@ -65,7 +63,9 @@
|
|||||||
|
|
||||||
;; Caught fish counter
|
;; Caught fish counter
|
||||||
(caught-fish int)
|
(caught-fish int)
|
||||||
(fish-texture Texture2D)))
|
(popup-back Texture2D)
|
||||||
|
(popup-magnet Texture2D)
|
||||||
|
(popup-target Texture2D)))
|
||||||
|
|
||||||
(ops camera
|
(ops camera
|
||||||
(fn init ((self (* camera))) void
|
(fn init ((self (* camera))) void
|
||||||
@@ -137,7 +137,9 @@
|
|||||||
(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"))
|
(= (. 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)
|
(audio-play-game-music)
|
||||||
|
|
||||||
(var map (* tmx-map) (load-tmx MAP-FILE))
|
(var map (* tmx-map) (load-tmx MAP-FILE))
|
||||||
@@ -194,8 +196,12 @@
|
|||||||
|
|
||||||
(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))
|
(if (IsTextureValid (. state popup-back))
|
||||||
(UnloadTexture (. state fish-texture)))
|
(UnloadTexture (. state popup-back)))
|
||||||
|
(if (IsTextureValid (. state popup-magnet))
|
||||||
|
(UnloadTexture (. state popup-magnet)))
|
||||||
|
(if (IsTextureValid (. state popup-target))
|
||||||
|
(UnloadTexture (. state popup-target)))
|
||||||
(free state)
|
(free state)
|
||||||
(return))
|
(return))
|
||||||
|
|
||||||
@@ -204,7 +210,57 @@
|
|||||||
|
|
||||||
;; Dim the game behind the popup
|
;; Dim the game behind the popup
|
||||||
(DrawRectangle 0 0 WIN-WIDTH WIN-HEIGHT (Fade BLACK 0.5f))
|
(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 :
|
(GuiLabel #(Rectangle :
|
||||||
(+ (. popup x) FISHING-POPUP-PADDING)
|
(+ (. popup x) FISHING-POPUP-PADDING)
|
||||||
@@ -213,11 +269,6 @@
|
|||||||
40.0f)
|
40.0f)
|
||||||
"X: pull! ESC: leave...")
|
"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-length int (- (. popup width) (* 2 FISHING-POPUP-PADDING)))
|
||||||
(var progress-bar-bg _
|
(var progress-bar-bg _
|
||||||
#(Rectangle :
|
#(Rectangle :
|
||||||
@@ -232,48 +283,7 @@
|
|||||||
(+ (. popup y) -10 (* 3 FISHING-POPUP-PADDING))
|
(+ (. popup y) -10 (* 3 FISHING-POPUP-PADDING))
|
||||||
(* progress-bar-length (. state catch-progress))
|
(* progress-bar-length (. state catch-progress))
|
||||||
6))
|
6))
|
||||||
(DrawRectangleRec progress-bar BLUE)
|
(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))))
|
|
||||||
|
|
||||||
(pub fn render-game ((state (* game-state))) void
|
(pub fn render-game ((state (* game-state))) void
|
||||||
(BeginDrawing)
|
(BeginDrawing)
|
||||||
|
|||||||
BIN
res/img/fishing-popup-back.png
Normal file
BIN
res/img/fishing-popup-back.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
BIN
res/img/fishing-popup-magnet.png
Normal file
BIN
res/img/fishing-popup-magnet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
res/img/fishing-popup-target.png
Normal file
BIN
res/img/fishing-popup-target.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 307 B |
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<map version="1.10" tiledversion="1.12.2" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="0" nextlayerid="17" nextobjectid="6">
|
<map version="1.10" tiledversion="1.12.2" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="0" nextlayerid="17" nextobjectid="8">
|
||||||
<tileset firstgid="1" source="basictiles.tsx"/>
|
<tileset firstgid="1" source="basictiles.tsx"/>
|
||||||
<tileset firstgid="121" name="Sprite-0004" tilewidth="16" tileheight="16" tilecount="16" columns="8">
|
<tileset firstgid="121" name="Sprite-0004" tilewidth="16" tileheight="16" tilecount="16" columns="8">
|
||||||
<image source="Sprite-0004.png" width="128" height="32"/>
|
<image source="Sprite-0004.png" width="128" height="32"/>
|
||||||
@@ -829,6 +829,7 @@
|
|||||||
<object id="3" x="249.333" y="342" width="48" height="28"/>
|
<object id="3" x="249.333" y="342" width="48" height="28"/>
|
||||||
<object id="4" x="479.333" y="649.333" width="49.3333" height="40"/>
|
<object id="4" x="479.333" y="649.333" width="49.3333" height="40"/>
|
||||||
<object id="5" x="636.667" y="419.333" width="44" height="37.3333"/>
|
<object id="5" x="636.667" y="419.333" width="44" height="37.3333"/>
|
||||||
|
<object id="7" x="490.667" y="385.333" width="52" height="38.6667"/>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
<objectgroup color="#ffffff" id="15" name="objects">
|
<objectgroup color="#ffffff" id="15" name="objects">
|
||||||
<object id="1" name="player" gid="149" x="497.75" y="350" width="32" height="32"/>
|
<object id="1" name="player" gid="149" x="497.75" y="350" width="32" height="32"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user