~technomancy/fennel-compendium

1fa7d5557efc1c85e2ac812a6c2b5158f82f3ae7 — Phil Hagelberg 1 year, 3 months ago 14c737b
Fix a bunch of busted stuff in Fallen.
M .gitignore => .gitignore +34 -0
@@ 1,3 1,37 @@
/fennel
/fennel.lua
/fennelview.lua
/fallen/game-over.lua
/fallen/init.lua
/fallen/loader.lua
/fallen/sound.lua
/fallen/action.lua
/fallen/attack-resolution.lua
/fallen/attack.lua
/fallen/bump-plugin.lua
/fallen/ctrl.lua
/fallen/draw.lua
/fallen/editor-ctrl.lua
/fallen/explosion.lua
/fallen/farmer-logic.lua
/fallen/final.lua
/fallen/game.lua
/fallen/knight-logic.lua
/fallen/map.lua
/fallen/mode-intro.lua
/fallen/npc.lua
/fallen/npc1-logic.lua
/fallen/opening.lua
/fallen/pfbs.lua
/fallen/restart.lua
/fallen/robo-satan-logic.lua
/fallen/staging.lua
/fallen/state.lua
/fallen/stones.lua
/fallen/subtile.lua
/fallen/timer.lua
/fallen/ui-hud.lua
/fallen/ui-menu-params.lua
/fallen/ui-text-box.lua
/fallen/ui.lua
/fallen/wrap.lua

M fallen/attack.fnl => fallen/attack.fnl +3 -3
@@ 31,7 31,7 @@
    (when (not (: attack.world :hasItem atk))
               (: attack.world :add atk atk.x atk.y atk.w atk.h)
)
    (local [aX aY cols len][(: attack.world :move atk atk.x 
    (local [aX aY cols len] [(: attack.world :move atk atk.x 
         atk.y (fn [item other] "cross"))])
    ((require attack.collision-resolution-file) atk cols len))



@@ 79,8 79,8 @@

(fn attack.draw [?tx ?ty ?sx ?sy]
    (love.graphics.push "all") ;;pop translate scale
    (love.graphics.translate (math.floor(or ?tx 0))
                             (math.floor(or ?ty 0)))
    (love.graphics.translate (math.floor (or ?tx 0))
                             (math.floor (or ?ty 0)))
    (love.graphics.scale  (or ?sx 1) (or ?sy (or ?sx 1)))
    (local collidables (: attack.world :getItems))
    (each [_ t (ipairs collidables)]

M fallen/bump-plugin.fnl => fallen/bump-plugin.fnl +2 -2
@@ 31,8 31,8 @@

(fn draw  [collidables world ?tx ?ty ?sx ?sy]
    (love.graphics.push)
    (love.graphics.translate (math.floor(or ?tx 0))
                             (math.floor(or ?ty 0)))
    (love.graphics.translate (math.floor (or ?tx 0))
                             (math.floor (or ?ty 0)))
    (love.graphics.scale  (or ?sx 1) (or ?sy (or ?sx 1)))
    (each [_ collidable (pairs (: world :getItems))]
          (love.graphics.rectangle

M fallen/conf.lua => fallen/conf.lua +1 -1
@@ 6,5 6,5 @@ love.conf = function(t)
   t.window.width = 900
   t.window.height = 600
   t.window.vsync = true
   t.version = "11.2"
   -- t.version = "11.2"
end

M fallen/ctrl.fnl => fallen/ctrl.fnl +1 -1
@@ 214,7 214,7 @@
    (set goal-x (or real-state.player.state.x 0))
    (set goal-y (or real-state.player.state.y 0))
    (when (not real-state.frozen)
      (lume.map keymap (fn[x] (when x.state
      (lume.map keymap (fn [x] (when x.state
                                (x.update dt))))
      )
    (if ( and state.grounded (>= state.v -0.1))

M fallen/editor-ctrl.fnl => fallen/editor-ctrl.fnl +2 -2
@@ 61,7 61,7 @@
    (love.graphics.setColor 0 0 0)
    (love.graphics.rectangle "line" (* tile i ) (* tile  j ) tile tile))

(fn draw-prefab-hover[]
(fn draw-prefab-hover []
    (love.graphics.draw hoverBatch))

(fn update-prefab-hover [mapin x y]


@@ 123,7 123,7 @@
        (set cheight (* tileSize map-height)))
      (set mapin (map.new map-width map-height 1 tileSize))
      )
    (set hoverBatch(love.graphics.newSpriteBatch  pfbs.sample-sprite-sheet 100))
    (set hoverBatch (love.graphics.newSpriteBatch  pfbs.sample-sprite-sheet 100))
    (global g_map mapin)
    (map.updateTilesetBatch tilesetBatch pfbs.tiles mapin tileSize tileLayers))


M fallen/farmer-logic.fnl => fallen/farmer-logic.fnl +3 -3
@@ 139,19 139,19 @@
    (tset farmer :ox -60)
    (set chat false)
    (ui.toggle-off "chat-farmer")
    (local [p60 len][(: attack.world :queryRect
    (local [p60 len] [(: attack.world :queryRect
                           (- state.npcs.farmer.x 60)
                           (- state.npcs.farmer.y 60) 
                           120 120
                           (fn [item] (= item.type "player")))])
    
    (local [p30 len][(: attack.world :queryRect
    (local [p30 len] [(: attack.world :queryRect
                           (- state.npcs.farmer.x 30)
                           (- state.npcs.farmer.y 30) 
                           60 60
                           (fn [item] (= item.type "player")))])

    (local [p90 len][(: attack.world :queryRect
    (local [p90 len] [(: attack.world :queryRect
                        (- state.npcs.farmer.x 85)
                        (- state.npcs.farmer.y 85) 
                        170 170

M fallen/final.fnl => fallen/final.fnl +4 -5
@@ 3,7 3,7 @@

(local sound (require "sound"))

{:draw (fn[]          
{:draw (fn []          
          (love.graphics.rectangle "fill" 0 0 900 600)
          (love.graphics.draw image 130 100)
          (love.graphics.setColor 0 0 0 1)


@@ 12,7 12,6 @@

          (love.graphics.printf "Turns out it was a simulation after all" 100 500 700 "center")
          )
       :activate (fn[dt]
                    (sound.stop :opening))
       :update (fn[dt])
       :keypressed (fn[key] (when (= key "escape") (love.event.quit)))}
       :activate (fn [dt] (sound.stop :opening))
       :update (fn [dt])
       :keypressed (fn [key] (when (= key "escape") (love.event.quit)))}

M fallen/game.fnl => fallen/game.fnl +2 -2
@@ 106,7 106,7 @@
    (set state.camera.opening.? false)    
    (set state.frozen false))

(fn opening[]
(fn opening []
    (when state.scene.start-opening
      (set state.camera.opening.? true)
      (set state.camera.opening.time 0)


@@ 144,7 144,7 @@
      (init.collision-init bump-plugin bump  attack)
      (init.player-init pfbs attack)      
      (init.npcs-init npc)
      (fade-from-white (fn[] (set fade-from-white-? false)))
      (fade-from-white (fn [] (set fade-from-white-? false)))
      (ui.new-scene "menu" (require "ui-menu-params"))
      (ui.new-scene "hud" (require "ui-hud"))
      (ui.toggle-on "hud")

M fallen/knight-logic.fnl => fallen/knight-logic.fnl +3 -3
@@ 109,19 109,19 @@
    (tset knight :ox -60)
    (set chat false)
    (ui.toggle-off "chat-knight")
    (local [p60 len][(: attack.world :queryRect
    (local [p60 len] [(: attack.world :queryRect
                           (- knight.x 60)
                           (- knight.y 60) 
                           120 120
                           (fn [item] (= item.type "player")))])
    
    (local [p30 len][(: attack.world :queryRect
    (local [p30 len] [(: attack.world :queryRect
                           (- knight.x 30)
                           (- knight.y 30) 
                           60 60
                           (fn [item] (= item.type "player")))])

    (local [p90 len][(: attack.world :queryRect
    (local [p90 len] [(: attack.world :queryRect
                        (- knight.x 85)
                        (- knight.y 85) 
                        170 170

M fallen/loader.fnl => fallen/loader.fnl +1 -1
@@ 32,7 32,7 @@
    ;;(local param (require file))
    ;; (local param (: json :decode (love.filesystem.read file)))
    (local image (love.graphics.newImage (.. "assets/" param.meta.image)))
    (local grid (anim8.newGrid 32 32 (: image :getWidth)(: image :getHeight)))
    (local grid (anim8.newGrid 32 32 (: image :getWidth) (: image :getHeight)))
    (local animations {})
    (each [_ frame (ipairs param.meta.frameTags)]          
          (tset animations frame.name

M fallen/map.fnl => fallen/map.fnl +3 -3
@@ 19,8 19,8 @@


(fn map.xy-to-tile [[x y] tileSize camera map-width map-height]
    [(% (math.floor(/ (- (/ (- x camera.x) camera.scale) 0) tileSize)) map-width)
     (math.max 1 (math.min (math.floor(/ (- (/ (- y camera.y) camera.scale) 0) tileSize)) (- map-height 1)))])
    [(% (math.floor (/ (- (/ (- x camera.x) camera.scale) 0) tileSize)) map-width)
     (math.max 1 (math.min (math.floor (/ (- (/ (- y camera.y) camera.scale) 0) tileSize)) (- map-height 1)))])

(fn map.xyl-to-id [x y l width height]
    (+ (* y width) x))


@@ 56,7 56,7 @@
    (let [tiles
          (. mapin.data l)
          neighbour?          
          (fn[i j]
          (fn [i j]
            (var max 0)
            (let [xp (if ?width
                         (if  (= (+ x i ) (+ ?width 0)) 0

M fallen/npc1-logic.fnl => fallen/npc1-logic.fnl +3 -3
@@ 108,19 108,19 @@
    (tset npc1 :ox -60)
    (set chat false)
    (ui.toggle-off "chat-npc1")
    (local [p60 len][(: attack.world :queryRect
    (local [p60 len] [(: attack.world :queryRect
                           (- npc1.x 60)
                           (- npc1.y 60) 
                           120 120
                           (fn [item] (= item.type "player")))])
    
    (local [p30 len][(: attack.world :queryRect
    (local [p30 len] [(: attack.world :queryRect
                           (- npc1.x 30)
                           (- npc1.y 30) 
                           60 60
                           (fn [item] (= item.type "player")))])

    (local [p90 len][(: attack.world :queryRect
    (local [p90 len] [(: attack.world :queryRect
                        (- npc1.x 85)
                        (- npc1.y 85) 
                        170 170

M fallen/opening.fnl => fallen/opening.fnl +4 -4
@@ 40,7 40,7 @@
(fn draw-gabe [x y]
    (var quad (grid-to-quad {:x 4 :y 0 :w 1 :h 1} 32))
    (when
     (= gabe-index 0)(set quad (grid-to-quad {:x 3 :y 0 :w 1 :h 1} 32)))
     (= gabe-index 0) (set quad (grid-to-quad {:x 3 :y 0 :w 1 :h 1} 32)))
    (love.graphics.draw image quad x y))




@@ 134,8 134,8 @@
    (love.graphics.rectangle "fill" 0 0  canvas-width canvas-height)
    (love.graphics.setColor 1 1 1 1)
    (love.graphics.push)
    (love.graphics.translate (math.floor(or ?tx 0))
                             (math.floor(or ?ty 0)))
    (love.graphics.translate (math.floor (or ?tx 0))
                             (math.floor (or ?ty 0)))
    (love.graphics.scale  (or ?sx 1) (or ?sy (or ?sx 1)))




@@ 181,6 181,6 @@

(fn keypressed [key set-mode]
    (when (= key "escape")
      (fade-to-white (fn [](set-mode "game" scale canvas-width canvas-height level)))))
      (fade-to-white (fn [] (set-mode "game" scale canvas-width canvas-height level)))))

{:draw draw :update update :keypressed keypressed :activate activate}

M fallen/pfbs.fnl => fallen/pfbs.fnl +2 -2
@@ 180,7 180,7 @@

(local background-image (newBackground 900 1800))

(fn draw-sky[canvas-width canvas-height]
(fn draw-sky [canvas-width canvas-height]
    (local map-width 900)
    (local map-height 1800)
    (local quad  (love.graphics.newQuad 0 0 map-width map-height map-width map-height))


@@ 206,7 206,7 @@
    (map.remove mapin x y :for2))


(fn set-brush[brush]
(fn set-brush  [brush]
    (fn []
        (tset pfbs :editor :brush brush)))


M fallen/robo-satan-logic.fnl => fallen/robo-satan-logic.fnl +2 -3
@@ 65,7 65,7 @@
      (set state.frozen true)
      (set player.health 0)
      (tset player :death-suspended true)
      (set state.player.state.anim.animations.Explode.onLoop 'pauseAtEnd')
      (set state.player.state.anim.animations.Explode.onLoop "pauseAtEnd")
      (set player.flip false)
      (set player.anim-index "Explode")
      (set player.explosion.? true)


@@ 83,7 83,6 @@
           (tset player :health (- state.player.state.health 2))
           (set satan.has-hit true))
        ))
;;(var satan.timer 0)

(fn self-distruct [dt satan player]
    ;; after 1200 set screen white for 2000


@@ 176,7 175,7 @@
(fn run-satan [dt satan player]
    ;;(pp satan.alive)
    (if
     (not satan.alive) (do (pp "dead")(tset satan :anim-index "Dead"))
     (not satan.alive) (do (pp "dead") (tset satan :anim-index "Dead"))
     (not satan.hostile) (friend dt satan player)
     (and satan.hostile satan.invincible) (self-distruct dt satan player)
     satan.hostile (hostile dt satan player)

M fallen/stones.fnl => fallen/stones.fnl +2 -2
@@ 44,8 44,8 @@

(fn draw [?tx ?ty ?sx ?sy]
    (love.graphics.push)
    (love.graphics.translate (math.floor(or ?tx 0))
                             (math.floor(or ?ty 0)))
    (love.graphics.translate (math.floor (or ?tx 0))
                             (math.floor (or ?ty 0)))
    (love.graphics.scale  (or ?sx 1) (or ?sy (or ?sx 1)))

    (gabe-draw gabe.x gabe.y)

M fallen/subtile.fnl => fallen/subtile.fnl +4 -4
@@ 18,8 18,8 @@
    (let [squares {}]
      (for [i 0 (- w 1)]
           (for [j 0 (- h 1)]
                (tset squares (+ 1(# squares)) (+ x i))
                (tset squares (+ 1(# squares)) (+ y j))))
                (tset squares (+ 1 (# squares)) (+ x i))
                (tset squares (+ 1 (# squares)) (+ y j))))
      (sample-grid (unpack squares) )))




@@ 64,7 64,7 @@
          c
          (. [7 6 7 6 10  3 10 9] (sel neigh.down neigh.down-left neigh.left))
          d
          (. [13 12 13 12 10 1 10 9](sel neigh.down neigh.down-right neigh.right))]
          (. [13 12 13 12 10 1 10 9] (sel neigh.down neigh.down-right neigh.right))]
      [a b c d]))




@@ 79,7 79,7 @@
                                      :up-right :up-left
                                      :down-right :down-left])]                 
                 (tset  tab i value
                        (% (math.floor(/ i (math.pow 2 (- key 1)) )) 2))))
                        (% (math.floor (/ i (math.pow 2 (- key 1)) )) 2))))
       tab))

subtile

M fallen/ui-hud.fnl => fallen/ui-hud.fnl +1 -1
@@ 19,7 19,7 @@
    (local empty (grid-to-quad {:x 8 :y 0 :w 1 :h 1} 16))
    (local health state.player.state.health)
    (for [i 0 2]
         (local x (+ 2(* i 12)))
         (local x (+ 2 (* i 12)))
         (if (> health (+ (* 2 i) 1)) (love.graphics.draw image full x 4)
             (> health (+ (* 2 i) )) (love.graphics.draw image half x 4)
             (love.graphics.draw image empty x 4))))

M fallen/ui-text-box.fnl => fallen/ui-text-box.fnl +1 -1
@@ 71,6 71,6 @@

(fn [text active?]
    (tset text-box :default-draw (partial text-box-draw text))
    (local ret{:1 text-box})
    (local ret {:1 text-box})
    (when active? (tset ret 2 esc))
    ret)

M fallen/ui.fnl => fallen/ui.fnl +3 -3
@@ 113,10 113,10 @@

(fn ui.draw [?tx ?ty ?sx ?sy]
    (love.graphics.push)
    (love.graphics.translate (math.floor(or ?tx 0))
                             (math.floor(or ?ty 0)))
    (love.graphics.translate (math.floor (or ?tx 0))
                             (math.floor (or ?ty 0)))
    (love.graphics.scale  (or ?sx 1) (or ?sy (or ?sx 1)))
    (each [_ scene (pairs ui.scenes)]          
    (each [_ scene (pairs ui.scenes)]
          (when scene.active
            (scene.draw scene)))
    (love.graphics.pop))

M fallen/wrap.fnl => fallen/wrap.fnl +1 -1
@@ 88,7 88,7 @@
    (love.graphics.setCanvas)
    (love.graphics.draw ui 0 0)))

(fn love.update[dt]
(fn love.update [dt]
    (mode.update dt set-mode))