Get surrounding tiles, unload textures

This commit is contained in:
Joseph Ferano 2026-08-23 14:35:44 +07:00
parent 53307aa95c
commit f16ed0cfb4

View File

@ -2,13 +2,17 @@
(:gen-class) (:gen-class)
(:require (:require
[engine] [engine]
[watch :as w]
[rl :as rl])) [rl :as rl]))
(def ^:const screen-width 1280) ;; (def ^:const screen-width 1280)
(def ^:const screen-height 630) ;; (def ^:const screen-height 630)
(def ^:const screen-width 970)
(def ^:const screen-height 530)
(def ^:const cell-size 16) (def ^:const cell-size 16)
(def ^:const rows (/ screen-width cell-size)) (def ^:const rows (quot screen-width cell-size))
(def ^:const cols (quot screen-height cell-size)) (def ^:const cols (quot screen-height cell-size))
(def ^:const grid-len (* rows cols))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
;; (set! *unchecked-math* :warn-on-boxed) ;; (set! *unchecked-math* :warn-on-boxed)
@ -26,7 +30,8 @@
t))) t)))
(defn idx [row col] (+ (* row cols) col)) (defn idx [row col] (+ (* row cols) col))
(defn tile-at [game r c] (aget ^objects (:grid game) (idx r c))) (defn tile-at [game r c] (aget ^objects (:grid game) (idx r c)))
(defn tile-at-idx [game idx] (aget ^objects (:grid game) idx))
(defn set-tile! [game r c tile] (aset ^objects (:grid game) (idx r c) tile)) (defn set-tile! [game r c tile] (aset ^objects (:grid game) (idx r c) tile))
(defn init-game [config] (defn init-game [config]
@ -37,6 +42,61 @@
:grid (object-array (* rows cols)) :grid (object-array (* rows cols))
:texture (load-texture-once "source-assets/Sprout Lands - Sprites - premium pack/Sprout Lands - Sprites - premium pack/Tilesets/ground tiles/New tiles/Grass_Hill_Tiles_v2.png")}) :texture (load-texture-once "source-assets/Sprout Lands - Sprites - premium pack/Sprout Lands - Sprites - premium pack/Tilesets/ground tiles/New tiles/Grass_Hill_Tiles_v2.png")})
(def tilemap-bitmask
{[0 0] :NW
[0 1] :N
[0 2] :NW
[1 0] :W
[1 1] :C
[1 2] :E
[2 0] :SW
[2 1] :S
[2 2] :SE})
(def tilemap-bitmask
{[0 0 0
0 0 1
0 1 1] :NW
[0 0 0
1 0 1
1 1 1] :N
[0 0 0
1 0 0
1 1 0] :NE
[0 1 1
0 0 1
0 1 1] :W
[1 1 0
1 0 0
1 1 0] :E
[0 1 1
0 0 1
0 0 0] :SW
[1 1 1
1 0 1
0 0 0] :S
[1 1 0
1 0 0
0 0 0] :SE})
(defn surrounding-tiles [game at-row at-col]
(let [idx (idx at-row at-col)]
(persistent!
(reduce (fn [acc num]
(let [cell-idx (+ idx num)]
(println cell-idx)
(if (or (< cell-idx 0)
(>= cell-idx 9 #_grid-len)
(= num 0))
(conj! acc 0)
(conj! acc (if (tile-at-idx game cell-idx)
1
0)))))
(transient [])
(range -4 5)))))
(defn auto-tile [])
(defn handle-game-input [config game] (defn handle-game-input [config game]
(let [game (assoc game :event-queue [])] (let [game (assoc game :event-queue [])]
(when (rl/key-pressed? rl/key-r)) (when (rl/key-pressed? rl/key-r))
@ -78,7 +138,8 @@
{:color-idx (:color-idx game)}) {:color-idx (:color-idx game)})
(defn unload-game [game] (defn unload-game [game]
(rl/unload-texture! (:texture game))) (rl/unload-texture! (:texture game))
(reset! texture-cache {}))
(defn -main [& _args] (defn -main [& _args]
(engine/run-game! (engine/run-game!