Commit ea8c4110 authored by Phil Hagelberg's avatar Phil Hagelberg

Doors can open and close, but don't draw correctly yet.

parent fbf31501
......@@ -1025,8 +1025,11 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="41" name="door-starts">
<object id="70" name="blue" x="930" y="2085.5" width="29" height="117.5"/>
<objectgroup id="41" name="doors">
<properties>
<property name="collidable" type="bool" value="true"/>
</properties>
<object id="70" name="blue" x="929.5" y="2080" width="29" height="126.5"/>
</objectgroup>
<objectgroup id="8" name="furniture-starts">
<object id="46" name="chair" gid="142" x="192" y="2016" width="32" height="32"/>
......
(local utils (require :utils))
(fn draw [world]
(each [_ body (ipairs (utils.get-bodies world :door))]
(let [data (: body :getUserData)]
(when (> data.closed 0)
(let [[fixture] (: body :getFixtures)
(x1 y1 x2 y2) (: fixture :getBoundingBox)
h (math.max 0 (* (- y2 y1) data.closed))]
(love.graphics.setColor 0 0 0)
(love.graphics.rectangle "fill" x1 y1 (- x2 x1) h))))))
(fn add-door [door world]
(let [body (love.physics.newBody world door.x door.y :dynamic)
shape (love.physics.newRectangleShape door.width door.height)
fixture (love.physics.newFixture body shape)]
(: fixture :setUserData {:door true})
(: body :setUserData {:x door.x :y door.y :w door.width :h door.height
:name door.name :closed 1 :door true})))
(fn get-door [world name]
(let [body (lume.match (: world :getBodies)
(fn [b] (. (or (: b :getUserData) {}) :map)))]
(lume.match (: body :getFixtures)
(fn [f] (= (. (or (: f :getUserData) {}) :name) name)))))
(fn init [map world]
(utils.clear world :door)
(let [(starts-layer layer-index) (utils.get-layer map :door-starts)
layer (or (utils.get-layer map :doors)
(: map :addCustomLayer :doors layer-index))]
(each [_ door (ipairs (. starts-layer :objects))]
(add-door door world))
(set layer.draw (partial draw world))))
(let [body (lume.match (: world :getBodies)
(fn [b] (. (or (: b :getUserData) {}) :map)))]
(each [_ f (ipairs (: body :getFixtures))]
(when (= (. (or (: f :getUserData) {}) :type) :door)
(: f :setSensor false)))))
(fn update [map world dt]
(each [_ body (ipairs (utils.get-bodies world :door))]
......@@ -42,17 +28,9 @@
(set data.closing? false))))))
(fn toggle [world name]
(each [_ body (ipairs (utils.get-bodies world :door))]
(let [data (: body :getUserData)]
(when (= data.name name)
(if (= data.closed 1)
(set data.opening? true)
(= data.closed 0)
(set data.closing? true)
data.closing?
(set (data.closing? data.opening) (values false true))
data.opening?
(set (data.closing? data.opening) (values true false)))))))
(let [fixture (get-door world name)]
(print :fixture fixture)
(: fixture :setSensor (not (: fixture :isSensor)))))
(fn open [world name]
(each [_ body (ipairs (utils.get-bodies world :door))]
......
......@@ -22,7 +22,8 @@ return {
local collision = {
body = body,
}
mapBody = body
body:setUserData({map=true})
local function addObjectToWorld(objshape, vertices, userdata, object)
local shape
......@@ -74,7 +75,9 @@ return {
}
local userdata = {
object = o,
object = o,
name = object.name,
type = object.type,
properties = object.properties
}
......
(local lume (require :lib.lume))
(local invisibles [:furniture-starts :enemy-starts :player :goal :patrols
:blockers :door-starts])
:blockers])
(fn [map]
(let [layers {}]
......
......@@ -1206,23 +1206,25 @@ return {
{
type = "objectgroup",
id = 41,
name = "door-starts",
name = "doors",
visible = true,
opacity = 1,
offsetx = 0,
offsety = 0,
draworder = "topdown",
properties = {},
properties = {
["collidable"] = true
},
objects = {
{
id = 70,
name = "blue",
type = "",
type = "door",
shape = "rectangle",
x = 930,
y = 2085.5,
x = 929.5,
y = 2080,
width = 29,
height = 117.5,
height = 126.5,
rotation = 0,
visible = true,
properties = {}
......
......@@ -56,6 +56,8 @@
(fn draw []
(: map :draw (- camera.tx) (- camera.ty))
(when (love.keyboard.isDown "tab")
(: map :box2d_draw (- camera.tx) (- camera.ty)))
(when killed?
(love.graphics.setColor fade-screen fade-screen fade-screen
(- 1 fade-screen))
......@@ -112,11 +114,9 @@
(and b-data.properties b-data.properties.goal a-data.blob))]
(when (and (love.keyboard.isDown "lshift")
(not (and a-data.blob b-data.blob)))
(print :a-and-b)
(print :collision-between a b)
(pp a-data)
(pp b-data))
(when a-data.door (global d a))
(when b-data.door (global d b))
(when winner?
(set won? true))
(when (and killer? (not won?))
......
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