Commit 8e59cefd authored by Phil Hagelberg's avatar Phil Hagelberg

Support messages.

parent 40ff2a6d
(local lume (require :lib.lume))
(local invisibles [:furniture-starts :enemy-starts :player :goal :patrols
:blockers])
:messages :blockers])
(fn [map]
(let [layers {}]
......
(local lume (require :lib.lume))
(local text-canvas (love.graphics.newCanvas))
(local message-height 20)
(local messages [])
(fn create [text duration]
(lume.push messages {:text text :duration duration}))
(fn draw [dt]
(let [prev-canvas (love.graphics.getCanvas)
(_ win-height) (: love.window :getMode)
height (* (# messages) message-height)
top-y (- win-height height)]
(love.graphics.setCanvas text-canvas)
(love.graphics.clear)
(love.graphics.setColor 0 0 0 .2)
(love.graphics.rectangle "fill" 0 top-y 400 height)
(each [index message (ipairs messages)]
(love.graphics.print message 0 (- top-y (* (- index 1) message-height))))
(love.graphics.setCanvas prev-canvas)
(love.graphics.draw text-canvas 0 0)))
;; a message is any object on the map that is marked as collidable and sensor
;; (booleans) and has a custom property called msg.
;; that message will be displayed once for 4 seconds upon entry of that object.
(local seen {})
(var current nil)
(var t 0)
(fn draw []
(when current
(love.graphics.setColor 1 1 1)
(love.graphics.print current 48 8)))
(fn update [dt]
(each [index message (ipairs messages)]
(if (> message.duration 0)
(tset index {:text message.text :duration (- message.duration dt)})
; TODO: Remove first message
)))
(set t (if current (+ t dt) 0))
(when (> t 4) (set current nil)))
(fn init []
(lume.clear seen)
(set current nil))
(fn show [msg]
(when (not (. seen msg))
(set (current) (values msg 0))
(tset seen msg true)))
(fn find [a-data b-data]
(or (and a-data.properties a-data.properties.msg b-data.blob a-data)
(and b-data.properties b-data.properties.msg a-data.blob b-data)))
{:init init :draw draw :update update :show show :find find}
......@@ -7,6 +7,7 @@
(local inventory (require :inventory))
(local lint (require :lint))
(local utils (require :utils))
(local message (require :message))
;; a whole new wooooooooorld 𝅘𝅥𝅮
(local world (love.physics.newWorld 0 0 true))
......@@ -61,6 +62,7 @@
(when (love.keyboard.isDown "tab")
(: map :box2d_draw (- camera.tx) (- camera.ty)))
(inventory.draw)
(message.draw)
(when killed?
(love.graphics.setColor fade-screen fade-screen fade-screen
(- 1 fade-screen))
......@@ -135,7 +137,10 @@
(when winner?
(set won? true))
(when (and killer? (not won?))
(set killed? true))))
(set killed? true))
(let [msg (message.find a-data b-data)]
(when msg
(message.show msg.properties.msg)))))
(fn pre-solve [a b coll]
(let [a-data (: a :getUserData)
......@@ -159,7 +164,8 @@
(enemy.init map world)
(furniture.init map world)
(doors.init map world)
(inventory.init map world))
(inventory.init map world)
(message.init))
(local touch-accel 16)
......@@ -172,6 +178,7 @@
:draw draw
:update (fn [dt set-mode zoom-scale]
(: world :update dt)
(message.update dt)
(doors.update map world dt)
(each [_ blob (ipairs blobs)]
;; reduce smearing by running blob physics at finer granularity
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment