Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
Phil Hagelberg
exo-encounter-667
Commits
a90ccb4e
Commit
a90ccb4e
authored
Apr 23, 2018
by
Phil Hagelberg
Browse files
Track wrappers in tiled lib so we can actually work with objects in bump.
parent
fa76dd8c
Changes
5
Hide whitespace changes
Inline
Side-by-side
door.fnl
deleted
100644 → 0
View file @
fa76dd8c
(local lume (require "lib.lume"))
(defn find [map which]
(lume.match map.layers.doors.objects (fn [d] (= which d.name))))
{:open (fn [map which]
(let [door (find map which)]
(when door
;; TODO: ugh we can't change collidable at runtime?!
;; I guess remove the closed door and replace with an open object?
(set door.properties.collidable false))))}
draw.fnl
View file @
a90ccb4e
...
...
@@ -61,6 +61,6 @@
sensor.x (- sensor.y sensor.height))))
:draw-doors (fn [layer]
(each [_ door (ipairs layer.objects)]
(love.graphics.draw (if door.properties.
collidable
door-img door-
open-
img)
(love.graphics.draw (if door.properties.
open
door-
open-
img door-img)
door.x (- door.y door.height))))}
laser.fnl
View file @
a90ccb4e
...
...
@@ -46,7 +46,7 @@
theta hit.item)]
(if theta2
(do (table.insert segments [x y new-x new-y])
(fire new-x new-y theta2 world segments
(fire new-x new-y theta2 world
map
segments
[hit.item] (- limit 1)))
(do (table.insert ignore hit.item)
(fire x y theta world map segments ignore limit))))
...
...
@@ -58,7 +58,7 @@
(transparent? hit.item)
(do (table.insert ignore hit.item)
(fire x y theta world map segments ignore limit))
(fire x y theta world map segments ignore limit))
(do (table.insert segments [x y hit.x1 hit.y1])
segments))
...
...
lib/tiled/plugins/bump.lua
View file @
a90ccb4e
...
...
@@ -6,6 +6,9 @@
local
lg
=
require
((
...
):
gsub
(
'plugins.bump'
,
'graphics'
))
local
wrappers
=
{}
local
bump_world
=
nil
return
{
bump_LICENSE
=
"MIT/X11"
,
bump_URL
=
"https://github.com/karai17/Simple-Tiled-Implementation"
,
...
...
@@ -17,6 +20,7 @@ return {
-- @return collidables table containing the handles to the objects in the Bump world.
bump_init
=
function
(
map
,
world
)
local
collidables
=
{}
bump_world
=
world
for
_
,
tileset
in
ipairs
(
map
.
tilesets
)
do
for
_
,
tile
in
ipairs
(
tileset
.
tiles
)
do
...
...
@@ -38,6 +42,7 @@ return {
}
wrappers
[
object
]
=
t
world
:
add
(
t
,
t
.
x
,
t
.
y
,
t
.
width
,
t
.
height
)
table.insert
(
collidables
,
t
)
end
...
...
@@ -55,6 +60,7 @@ return {
properties
=
tile
.
properties
}
wrappers
[
tile
]
=
t
world
:
add
(
t
,
t
.
x
,
t
.
y
,
t
.
width
,
t
.
height
)
table.insert
(
collidables
,
t
)
end
...
...
@@ -82,6 +88,7 @@ return {
properties
=
object
.
properties
}
wrappers
[
object
]
=
t
world
:
add
(
t
,
t
.
x
,
t
.
y
,
t
.
width
,
t
.
height
)
table.insert
(
collidables
,
t
)
end
...
...
@@ -98,6 +105,7 @@ return {
properties
=
tile
.
properties
}
wrappers
[
tile
]
=
t
world
:
add
(
t
,
t
.
x
,
t
.
y
,
t
.
width
,
t
.
height
)
table.insert
(
collidables
,
t
)
end
...
...
@@ -123,10 +131,12 @@ return {
properties
=
obj
.
properties
}
-- PNH: what the hell?
if
obj
.
gid
then
t
.
y
=
t
.
y
-
obj
.
height
end
wrappers
[
obj
]
=
t
world
:
add
(
t
,
t
.
x
,
t
.
y
,
t
.
width
,
t
.
height
)
table.insert
(
collidables
,
t
)
end
-- TODO implement other object shapes?
...
...
@@ -180,7 +190,15 @@ return {
end
lg
.
pop
()
end
end
,
-- PNH: we added this so we could work around STI shenanigans and actually
-- perform operations on the world directly. STI wraps each object in a
-- table before adding it to the bump world, so we look up the object in
-- the wrapper mapping before handing off to bump.
bump_wrap
=
function
(
method
,
object
,
...
)
return
bump_world
[
method
](
bump_world
,
wrappers
[
object
],
...
)
end
,
}
--- Custom Properties in Tiled are used to tell this plugin what to do.
...
...
sensor.fnl
View file @
a90ccb4e
;; sensors are represented in tiled as any item on the "sensor" layer.
;; they must have the collidable property set to work.
(local door (require "door"))
(local lume (require "lib.lume"))
(defn open [world map door]
(set door.properties.open true)
;; we can't use an object from the map directly with the bump world, because
;; the map wraps it in another table, so we have to go thru our hacked
;; addition to the map which looks up the wrapper and uses that instead.
(when (map.bump_wrap :hasItem door)
(print :removed)
(map.bump_wrap :remove door)))
(defn activate [world map item]
(set item.properties.on true)
(when item.properties.door
(door.open map item.properties.door)))
(let [d (lume.match map.layers.doors.objects
(fn [d] (= d.name item.properties.door)))]
(open world map d))))
{:is? (fn [item] (and item.properties item.properties.sensor))
:activate activate
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment