add fishing zones and fishing tooltip
This commit is contained in:
92
game.sex
92
game.sex
@@ -31,7 +31,11 @@
|
||||
(cam camera)
|
||||
|
||||
(player (* TmxObject))
|
||||
(player-first-tile-gid int)))
|
||||
(player-first-tile-gid int)
|
||||
|
||||
(fishing-spots (* TmxObjectGroup))
|
||||
(near-fishing-spot bool)
|
||||
(fishing-minigame-active bool)))
|
||||
|
||||
(ops camera
|
||||
(fn init ((self (* camera))) void
|
||||
@@ -93,7 +97,7 @@
|
||||
;; Assume width = height (true for our map)
|
||||
(= TILE-SIZE (. map tile-width))
|
||||
|
||||
(var object-count int (tmx-object-count map "Objects"))
|
||||
(var object-count int (tmx-object-count map "objects"))
|
||||
(TraceLog LOG-INFO "Objects has %d object(s)" object-count)
|
||||
|
||||
(if (== object-count 0)
|
||||
@@ -104,23 +108,20 @@
|
||||
(/ (cast (tmx-pixel-height map) float) 2.0))
|
||||
(return (page/game state))))
|
||||
|
||||
(var player-x float (tmx-object-x map "Objects" 0))
|
||||
(var player-y float (tmx-object-y map "Objects" 0))
|
||||
(var player-width float (tmx-object-width map "Objects" 0))
|
||||
(var player-height float (tmx-object-height map "Objects" 0))
|
||||
(var player-x float (tmx-object-x map "objects" 0))
|
||||
(var player-y float (tmx-object-y map "objects" 0))
|
||||
(var player-width float (tmx-object-width map "objects" 0))
|
||||
(var player-height float (tmx-object-height map "objects" 0))
|
||||
|
||||
(var player (* TmxObject)
|
||||
(tmx-find-object-by-name (. state map handle) "Objects" "Player"))
|
||||
(tmx-find-object-by-name (. state map handle) "objects" "player"))
|
||||
(= (. state player) player)
|
||||
(= (. state player-first-tile-gid) (. player gid))
|
||||
(= (. state player x) (clamp-to-grid (. state player x)))
|
||||
(= (. state player y) (clamp-to-grid (. state player y)))
|
||||
|
||||
(TraceLog LOG-INFO
|
||||
"Objects[0]: \"%s\" type \"%s\" at %.1f, %.1f (%.1f x %.1f)"
|
||||
(tmx-object-name map "Objects" 0)
|
||||
(tmx-object-type map "Objects" 0)
|
||||
player-x player-y player-width player-height)
|
||||
(= (. state fishing-spots) (tmx-object-group (. map handle) "fishing_spots"))
|
||||
(= (. state fishing-minigame-active) false)
|
||||
|
||||
(.init (& (. state cam)))
|
||||
(return (page/game state)))
|
||||
@@ -141,12 +142,38 @@
|
||||
|
||||
(BeginMode2D (. state cam ray-cam))
|
||||
(animate-tmx (. state map))
|
||||
(draw-tmx-layer (. state map) "Background" (& (. state cam ray-cam)))
|
||||
(draw-tmx-layer (. state map) "Objects" (& (. state cam ray-cam)))
|
||||
(draw-tmx-layer (. state map) "bg" (& (. state cam ray-cam)))
|
||||
(draw-tmx-layer (. state map) "objects" (& (. state cam ray-cam)))
|
||||
(EndMode2D)
|
||||
|
||||
(DrawText "WASD/arrows: move wheel: zoom ESC: back to menu"
|
||||
10 10 20 RAYWHITE)
|
||||
|
||||
;; Show the interaction key above the player when near a fishing spot
|
||||
(if (. state near-fishing-spot)
|
||||
(do
|
||||
(var player-pos Vector2 (player-center state))
|
||||
(var screen-pos Vector2
|
||||
(GetWorldToScreen2D #(Vector2 :
|
||||
(+ (. player-pos x)
|
||||
(* TILE-SIZE 0.5f))
|
||||
(- (. player-pos y)
|
||||
(* TILE-SIZE 1.5f)))
|
||||
(. state cam ray-cam)))
|
||||
(var label-size float (cast (GuiGetStyle DEFAULT TEXT-SIZE) float))
|
||||
(var old-align int (GuiGetStyle LABEL TEXT-ALIGNMENT))
|
||||
(var old-color int (GuiGetStyle LABEL TEXT-COLOR-NORMAL))
|
||||
(GuiSetStyle LABEL TEXT-ALIGNMENT TEXT-ALIGN-CENTER)
|
||||
(GuiSetStyle LABEL TEXT-COLOR-NORMAL (cast 0xffffffff i32))
|
||||
(GuiLabel #(Rectangle :
|
||||
(- (. screen-pos x) (/ label-size 2.0f))
|
||||
(- (. screen-pos y) (/ label-size 2.0f))
|
||||
label-size
|
||||
label-size)
|
||||
"X")
|
||||
(GuiSetStyle LABEL TEXT-ALIGNMENT old-align)
|
||||
(GuiSetStyle LABEL TEXT-COLOR-NORMAL old-color)))
|
||||
|
||||
(EndDrawing))
|
||||
|
||||
(fn move-player ((state (* game-state)) (dx i32) (dy i32)) void
|
||||
@@ -170,7 +197,7 @@
|
||||
(= (. state player gid) (+ 3 (. state player-first-tile-gid))))
|
||||
|
||||
;; Rotate in any case, but move only if can
|
||||
(if (! (tmx-is-tile-walkable (. state map) "Background"
|
||||
(if (! (tmx-is-tile-walkable (. state map) "bg"
|
||||
(+ (* dx TILE-SIZE) (. state player x))
|
||||
(+ (* dy TILE-SIZE) (. state player y))))
|
||||
(return))
|
||||
@@ -193,16 +220,31 @@
|
||||
(if (|| (IsKeyPressed KEY-DOWN) (IsKeyPressed KEY-S))
|
||||
(move-player state 0 1))
|
||||
|
||||
(var wheel float (GetMouseWheelMove))
|
||||
(if (!= wheel 0.0)
|
||||
(do
|
||||
(+= (. state cam ray-cam zoom) (* wheel 0.5))
|
||||
(if (< (. state cam ray-cam zoom) 0.5)
|
||||
(= (. state cam ray-cam zoom) 0.5))
|
||||
(if (> (. state cam ray-cam zoom) 8.0)
|
||||
(= (. state cam ray-cam zoom) 8.0))))
|
||||
;; TODO: we probably don't need zoom at all
|
||||
;; (var wheel float (GetMouseWheelMove))
|
||||
;; (if (!= wheel 0.0)
|
||||
;; (do
|
||||
;; (+= (. state cam ray-cam zoom) (* wheel 0.5))
|
||||
;; (if (< (. state cam ray-cam zoom) 0.5)
|
||||
;; (= (. state cam ray-cam zoom) 0.5))
|
||||
;; (if (> (. state cam ray-cam zoom) 8.0)
|
||||
;; (= (. state cam ray-cam zoom) 8.0))))
|
||||
|
||||
(if (IsKeyReleased KEY-ESCAPE)
|
||||
(.change-page (. state app-state) (sum-type page menu)))
|
||||
|
||||
(.update (& (. state cam)) state)
|
||||
|
||||
(if (IsKeyReleased KEY-ESCAPE)
|
||||
(.change-page (. state app-state) (sum-type page menu))))
|
||||
;; If we're near the fishing spot, show the tip and arm the fishing game
|
||||
(= (. state near-fishing-spot) false)
|
||||
(if (!= NULL (tmx-object-at-point (. state fishing-spots) (player-center state)))
|
||||
(do
|
||||
(= (. state near-fishing-spot) true)
|
||||
(if (IsKeyReleased KEY-X)
|
||||
(do
|
||||
(= (. state fishing-minigame-active) true)
|
||||
(TraceLog LOG-INFO "Trying to activate minigame near fishing spot!")
|
||||
;; TODO: show fishing minigame popup: indicator that rises
|
||||
;; and falls and we need to click X to keep indicator in
|
||||
;; the fish zone that moves randomly
|
||||
)))))
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="32" tileheight="32" infinite="0" nextlayerid="4" nextobjectid="7">
|
||||
<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="32" tileheight="32" infinite="0" nextlayerid="5" nextobjectid="11">
|
||||
<tileset firstgid="1" source="WATAH 2.tsx"/>
|
||||
<tileset firstgid="257" source="ekko.tsx"/>
|
||||
<layer id="1" name="Background" width="30" height="20">
|
||||
<layer id="1" name="bg" width="30" height="20">
|
||||
<data encoding="csv">
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
@@ -16,18 +16,21 @@
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,156,34,34,34,34,35,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,0,0,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,0,0,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,0,0,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,140,2,2,2,3,0,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,33,155,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,0,33,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,35,0,0,0,
|
||||
0,0,17,18,18,18,18,18,146,34,34,147,18,18,18,18,18,18,18,18,18,18,19,0,0,0,0,0,0,0,
|
||||
0,0,17,18,18,18,18,18,19,0,0,145,18,18,18,18,18,18,18,18,18,18,140,2,2,2,3,0,0,0,
|
||||
0,0,17,18,18,18,18,18,19,0,0,145,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,17,18,18,18,18,18,19,0,0,145,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,17,18,18,18,18,18,19,0,0,145,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,33,155,18,18,18,18,19,0,0,145,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,0,0,0,
|
||||
0,0,0,33,34,34,34,34,35,0,0,33,34,34,34,34,34,34,34,34,34,34,34,34,34,34,35,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup color="#ffffff" id="3" name="Objects">
|
||||
<object id="5" name="Player" gid="257" x="321.16" y="161.145" width="32" height="32"/>
|
||||
<object id="6" name="Spot 1" x="701.785" y="348.293" width="73.6441" height="37.2552"/>
|
||||
<objectgroup color="#ffffff" id="3" name="objects">
|
||||
<object id="5" name="player" gid="257" x="321.16" y="161.145" width="32" height="32"/>
|
||||
</objectgroup>
|
||||
<objectgroup id="4" name="fishing_spots">
|
||||
<object id="8" name="pond" x="702.427" y="341.88" width="79.5756" height="50.1032"/>
|
||||
<object id="10" name="pond" x="259.406" y="388.119" width="121.782" height="87.1287"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
||||
25
tmx.sex
25
tmx.sex
@@ -32,7 +32,7 @@
|
||||
|
||||
(return NULL))
|
||||
|
||||
(fn find-object-group ((map (* TmxMap))
|
||||
(pub fn tmx-object-group ((map (* TmxMap))
|
||||
(name (* const char)))
|
||||
(* TmxObjectGroup)
|
||||
(if (== map NULL)
|
||||
@@ -52,7 +52,7 @@
|
||||
(index int))
|
||||
(* TmxObject)
|
||||
(var group (* TmxObjectGroup)
|
||||
(find-object-group map layer-name))
|
||||
(tmx-object-group map layer-name))
|
||||
(if (== group NULL)
|
||||
(return NULL))
|
||||
(if (< index 0)
|
||||
@@ -133,7 +133,7 @@
|
||||
(if (== map NULL)
|
||||
(return 0))
|
||||
(var group (* TmxObjectGroup)
|
||||
(find-object-group (. map handle) layer-name))
|
||||
(tmx-object-group (. map handle) layer-name))
|
||||
(if (== group NULL)
|
||||
(return 0))
|
||||
(return (cast (. group objectsLength) int)))
|
||||
@@ -210,7 +210,7 @@
|
||||
(return NULL))
|
||||
|
||||
(var group (* (struct TmxObjectGroup))
|
||||
(find-object-group map layer-name))
|
||||
(tmx-object-group map layer-name))
|
||||
(if (== group NULL)
|
||||
(return NULL))
|
||||
|
||||
@@ -270,3 +270,20 @@
|
||||
;;; (return (& [(. tileset tiles) local-gid])))))
|
||||
;; ???
|
||||
(return true))
|
||||
|
||||
(pub fn tmx-object-rect ((o (* TmxObject))) Rectangle
|
||||
(return #(Rectangle : (. o x) (. o y) (. o width) (. o height))))
|
||||
|
||||
(pub fn tmx-object-at-point ((group (* TmxObjectGroup))
|
||||
(point Vector2)) (* TmxObject)
|
||||
(if (== group NULL)
|
||||
(return NULL))
|
||||
(var objects (* TmxObject) (. group objects))
|
||||
(var i u32 0)
|
||||
(while (< i (. group objectsLength))
|
||||
(var obj (* TmxObject) (& [objects i]))
|
||||
(if (&& (== (. obj type) OBJECT-TYPE-RECTANGLE)
|
||||
(CheckCollisionPointRec point (tmx-object-rect obj)))
|
||||
(return obj))
|
||||
(++ i))
|
||||
(return NULL))
|
||||
|
||||
Reference in New Issue
Block a user