From a8178cbf52697595aa48ee40e527e459ccff3d7e Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 30 Aug 2026 13:44:20 +0700 Subject: [PATCH] Fix edn export and import, fix autotile and delete-tile functions, add rl collision api --- src/game.clj | 8 +++++++- src/rl.clj | 3 +++ src/sprite_atlas.clj | 4 +--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/game.clj b/src/game.clj index e656be1..de8580b 100644 --- a/src/game.clj +++ b/src/game.clj @@ -5,6 +5,7 @@ (:require [engine :as e] [watch :as w] + [clojure.edn :as edn] [rl :as rl])) (def ^:const screen-width 1280) @@ -45,6 +46,11 @@ :layers (vec (repeatedly num-layers #(object-array (* rows cols)))) :current-layer 0 :current-tilemap 0 + :atlases + ;; (edn/read-string (slurp "./assets/Mushrooms, Flowers, Stones.edn")) + (let [path "./assets/Mushrooms, Flowers, Stones.edn" + atlas (edn/read-string (slurp path))] + [[:level-props (e/load-texture-once :level-props (:texture-path atlas)) (:selected-cells atlas)]]) ;; TODO: When we cannot find the image, no errors are being reported. Likely because raylib is failing silently ;; TODO: How do we get Raylib to reload images on the fly :tilemaps @@ -167,6 +173,7 @@ (do-neighbors! layer at-row at-col (fn [l r c] (when (tile-at game l r c) + (set-random-tile! game l r c))))) (defn delete-tile! [game layer at-row at-col] (set-tile! game layer at-row at-col nil) @@ -174,7 +181,6 @@ (fn [l r c] (when (tile-at game l r c) (set-random-tile! game l r c))))) - (set-random-tile! game l r c))))) (defn handle-game-input [config game] (update-as-> [g game] diff --git a/src/rl.clj b/src/rl.clj index f6839e1..0c792d9 100644 --- a/src/rl.clj +++ b/src/rl.clj @@ -228,6 +228,9 @@ (defn draw-rectangle-lines-ex!* [rec line-thick color] (draw-rectangle-lines-ex-raw!* rec (float line-thick) color)) +(defcfn collision-recs? "CheckCollisionRecs" [::rectangle ::rectangle] ::bool) +(defcfn collision-point-rec? "CheckCollisionPointRec" [::vector-2 ::rectangle] ::bool) + (def update-texture!* (ffi/make-downcall "UpdateTexture" [::texture ::mem/pointer] ::mem/void)) diff --git a/src/sprite_atlas.clj b/src/sprite_atlas.clj index afefe8c..7355b43 100644 --- a/src/sprite_atlas.clj +++ b/src/sprite_atlas.clj @@ -66,8 +66,7 @@ (when-let [f (.getFile d)] (let [base-path (System/getProperty "user.dir") full-path (str (.getDirectory d) f)] - (spit full-path (pr-str {:texture-path (str (.relativize (.toPath (io/file base-path)) - (.toPath (io/file full-path)))) + (spit full-path (pr-str {:texture-path sprite-atlas-path :selected-cells (:selected-cells g)})))) game) #_(this should be to write the sprite sheet to some path)) @@ -143,7 +142,6 @@ :dragging (assoc g :drag-delta (let [{mx :x my :y} (rl/get-mouse-position) {:keys [x y]} (:drag-start-pos g)] [(- mx x) (- my y)])))))) -(into #{[1 2]} [[1 2] [2 3]] ) (defn draw-sprite-atlas [_ {:keys [atlas atlas-pos drag-delta zoom drag-mode drag-start-pos current-mouse-pos selected-cells]}] (rl/clear-background!* rl/black)