diff options
| -rw-r--r-- | art/alcohol.png | bin | 0 -> 397 bytes | |||
| -rw-r--r-- | art/logo.png | bin | 0 -> 2119 bytes | |||
| -rw-r--r-- | art/soap.png | bin | 0 -> 416 bytes | |||
| -rw-r--r-- | game.fnl | 27 | ||||
| -rw-r--r-- | map.fnl | 78 |
5 files changed, 93 insertions, 12 deletions
diff --git a/art/alcohol.png b/art/alcohol.png Binary files differnew file mode 100644 index 0000000..59f8ee5 --- /dev/null +++ b/art/alcohol.png diff --git a/art/logo.png b/art/logo.png Binary files differnew file mode 100644 index 0000000..564af68 --- /dev/null +++ b/art/logo.png diff --git a/art/soap.png b/art/soap.png Binary files differnew file mode 100644 index 0000000..ed214b1 --- /dev/null +++ b/art/soap.png @@ -168,7 +168,10 @@ (. player :frame) (. player :orientation) x - y))) + y)) + (love.graphics.print (string.format "%d/%d" (. world :surfaces-slimed) + (. world :surfaces-total)) + 0 0)) (fn update [dt set-mode] (local gravity 128) @@ -227,20 +230,28 @@ (let [tile (. collision :other)] ;; Touching top. (when (> 0 (. collision :normal :y)) - (tset tile :slimed :top true) - (tset player :grounded true)) + (tset player :grounded true) + (when (not (. tile :slimed :top)) + (tset world :surfaces-slimed (+ 1 (. world :surfaces-slimed))) + (tset tile :slimed :top true))) ;; Touching bottom. (when (< 0 (. collision :normal :y)) - (tset tile :slimed :bottom true)) - + (when (not (. tile :slimed :bottom)) + (tset world :surfaces-slimed (+ 1 (. world :surfaces-slimed))) + (tset tile :slimed :bottom true))) + ;; Touching left. (when (> 0 (. collision :normal :x)) - (tset tile :slimed :left true)) + (when (not (. tile :slimed :left)) + (tset world :surfaces-slimed (+ 1 (. world :surfaces-slimed))) + (tset tile :slimed :left true))) ;; Touching right. (when (< 0 (. collision :normal :x)) - (tset tile :slimed :right true))))))) + (when (not (. tile :slimed :right)) + (tset world :surfaces-slimed (+ 1 (. world :surfaces-slimed))) + (tset tile :slimed :right true)))))))) (fn keypressed [key set-mode] @@ -256,7 +267,7 @@ (fn keyreleased [key set-mode] (when (= key "right") (tset player :action :right false)) - + (when (= key "left") (tset player :action :left false)) @@ -15,7 +15,7 @@ ;;;; You should have received a copy of the GNU General Public License along ;;;; with slime-the-world. If not, see <http://www.gnu.org/licenses/>. -(local tiles +(local tile-sheet {:img (love.graphics.newImage "art/tiles.png") :width 32 :height 32 :padding-x 8 :padding-y 8 @@ -31,6 +31,71 @@ :padding-x 8 :padding-y 8 :offsets {:top 0 :bottom 1 :left 2 :right 3}}) +(fn tile-at [tiles x y] + (if (and (>= x 0) + (< x (. tiles :width)) + (>= y 0) + (< y (. tiles :height))) + (. tiles :tiles (+ 1 y) (+ 1 x)) + nil)) + +(fn find-first [tile-type tiles] + (var res nil) + (each [_ row (ipairs (. tiles :tiles))] + (each [_ tile (ipairs row)] + (when (= tile-type (. tile :type)) + (set res tile)))) + res) + +(fn tile-checked [tile checked] + (var res false) + (each [_ other (ipairs checked)] + (when (and (= (. tile :x-pos) (. other :x-pos)) + (= (. tile :y-pos) (. other :y-pos))) + (set res true))) + res) + +(fn count-surfaces-recur [tiles tile checked] + (var surfaces 0) + + (when (not (tile-checked tile checked)) + (table.insert checked tile) + + (let [x (/ (. tile :x-pos) (. tile-sheet :width)) + y (/ (. tile :y-pos) (. tile-sheet :height)) + width (. tiles :width) + height (. tiles :height)] + (when (>= x 0) + (let [tile (tile-at tiles (- x 1) y)] + (if (= :empty (. tile :type)) + (set surfaces (+ surfaces (count-surfaces-recur tiles tile checked))) + (set surfaces (+ 1 surfaces))))) + + (when (< x width) + (let [tile (tile-at tiles (+ x 1) y)] + (if (= :empty (. tile :type)) + (set surfaces (+ surfaces (count-surfaces-recur tiles tile checked))) + (set surfaces (+ 1 surfaces))))) + + (when (>= y 0) + (let [tile (tile-at tiles x (- y 1))] + (if (= :empty (. tile :type)) + (set surfaces (+ surfaces (count-surfaces-recur tiles tile checked))) + (set surfaces (+ 1 surfaces))))) + + (when (< y height) + (let [tile (tile-at tiles x (+ y 1))] + (if (= :empty (. tile :type)) + (set surfaces (+ surfaces (count-surfaces-recur tiles tile checked))) + (set surfaces (+ 1 surfaces))))))) + + surfaces) + +(fn count-surfaces [tiles] + (let [seed (find-first :empty tiles)] + (when seed + (count-surfaces-recur tiles seed [])))) + ;; Creates a new tile object of the given `type-type' positioned at world ;; coordinates (`x', `y'). (fn make-tile [tile-type x y] @@ -44,7 +109,7 @@ ;; Returns the tile object for a given pixel in `image'. (fn get-tile [image x y] - (var res (make-tile :empty (* x (. tiles :width)) (* y (. tiles :width)))) + (var res (make-tile :empty (* x (. tile-sheet :width)) (* y (. tile-sheet :width)))) (let [(r g b a) (: image :getPixel x y)] (each [tile-type colors (pairs tile-values)] (when (and (= (. colors 1) r) @@ -77,12 +142,17 @@ (fn load [name] (let [tiles-path (.. "maps/" name ".png") meta-path (.. "maps/" name ".fnl")] - (let [(tiles width height) (load-tiles (love.image.newImageData tiles-path))] + (let [(tiles width height) (load-tiles (love.image.newImageData tiles-path)) + tiles-temp {:tiles tiles :width width :height height}] {:tiles tiles :width width :height height + + :surfaces-slimed 0 + :surfaces-total (count-surfaces tiles-temp) + :meta (load-meta meta-path)}))) -{:tiles tiles +{:tiles tile-sheet :slime slime :load load} |