So I gave this a try and came up with this somewhat boilerplaty code (I crindged a little bit writing it)
Code: Select all
components = {
{
class="MeleeAttack",
onAttack = function(self)
local facing = party.facing
local level = party.level
local x = party.x
local y = party.y
local foundOne = false
local caveIns
--get entity in front of the party
if facing == 0 then
for e in Dungeon.getMap(level):entitiesAt(x,y-1) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
elseif facing == 1 then
for e in Dungeon.getMap(level):entitiesAt(x+1,y) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
elseif facing ==2 then
for e in Dungeon.getMap(level):entitiesAt(x,y+1) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
elseif facing == 3 then
for e in Dungeon.getMap(level):entitiesAt(x-1,y) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
else
return
end
--if it did find one then destroy it
if foundOne then
caveIns:destroy()
end
end
},
}
What I do is, I get the entity in front of the party, check if its go name is a cave_in, if so I destroy it.
You should probably add some fancy effects/sounds or a shovel-dig like fade in/out to smooth that out
So yeah, that's it from me.
//edit: the code is bound to the pickaxe clone/whatever item you wish
//edit2: took the below advice to heart and voilá, somewhat tidier
Code: Select all
components = {
{
class="MeleeAttack",
onAttack = function(self)
local facing = party.facing
local level = party.level
local dx, dy = getForward(facing)
local inFrontX = party.x + dx
local inFrontY = party.y + dy
local foundOne = false
local caveIns
--get entity in front of the party
for e in Dungeon.getMap(level):entitiesAt(inFrontX,inFrontY) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
e:destroy()
end
end
end
},
}