Skip to content

Commit

Permalink
medbay bed is now responsive see issue #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertV committed Mar 11, 2014
1 parent 7dec766 commit 57f7cbf
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 2 deletions.
19 changes: 19 additions & 0 deletions SMEE/objects/generic/sr1medbaybed/healthstatus.frames
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{

"frameGrid" : {
"size" : [8, 10],
"dimensions" : [4, 4],
"names" : [
[ "off", "turnOn.1", "turnOn.2", null ],
[ "max.1", "max.2", "max.3", "max.4" ],
[ "med.1", "med.2", "med.3", "med.4" ],
[ "low.1", "low.2", "low.3", "low.4" ]

]
},
"aliases" : {
"default" : "off",
"turnOff.1" : "turnOn.2",
"turnOff.2" : "turnOn.1"
}
}
Binary file added SMEE/objects/generic/sr1medbaybed/healthstatus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions SMEE/objects/generic/sr1medbaybed/scanoverlay.frames
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{

"frameGrid" : {
"size" : [30, 10],
"dimensions" : [6, 1],
"names" : [
[ "off", "on.1", "on.2", "on.3", "on.4", "on.5"]
]
},
"aliases" : {
"default" : "off",
"on.6" : "on.4",
"on.7" : "on.3",
"on.8" : "on.2"
}
}
Binary file added SMEE/objects/generic/sr1medbaybed/scanoverlay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
178 changes: 178 additions & 0 deletions SMEE/objects/generic/sr1medbaybed/sr1medbaybed.animation
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"animatedParts" : {
"stateTypes" : {
"responsiveState" : {
"default" : "off",
"states" : {
"off" : {
"frames" : 1,
"cycle" : 0.15
},

"max" : {
"frames" : 4,
"cycle" : 1.0,
"mode" : "loop"
},

"med" : {
"frames" : 4,
"cycle" : 1.0,
"mode" : "loop"
},

"low" : {
"frames" : 4,
"cycle" : 1.0,
"mode" : "loop"
},

"turnOn" : {
"frames" : 2,
"cycle" : 0.5
},

"turnOff" : {
"frames" : 2,
"cycle" : 0.5
}
}
},
"scanState" : {
"default" : "off",
"states" : {
"off" : {
"frames" : 1,
"cycle" : 0.15
},

"on" : {
"frames" : 8,
"cycle" : 2.5,
"mode" : "loop"
}
}
}

},

"parts" : {
"sr1medbaybed" : {
"properties" : {
"offset" : [0, 0],
"centered" : false,
"zLevel" : 0,
"back" : true
},

"partStates" : {
"responsiveState" : {
"off" : {
"properties" : {
"image" : "<partImage>"
}
},

"max" : {
"properties" : {
"image" : "<partImage>"
}
},
"med" : {
"properties" : {
"image" : "<partImage>"
}
},

"low" : {
"properties" : {
"image" : "<partImage>"
}
},

"turnOn" : {
"properties" : {
"image" : "<partImage>"
}
},

"turnOff" : {
"properties" : {
"image" : "<partImage>"
}
}
}
}
},
"healthstatus" : {
"properties" : {
"offset" : [5.4, 1.2],
"centered" : false,
"zLevel" : 1
},

"partStates" : {
"responsiveState" : {
"off" : {
"properties" : {
"image" : "<partImage>:off"
}
},

"max" : {
"properties" : {
"image" : "<partImage>:max.<frame>"
}
},
"med" : {
"properties" : {
"image" : "<partImage>:med.<frame>"
}
},

"low" : {
"properties" : {
"image" : "<partImage>:low.<frame>"
}
},

"turnOn" : {
"properties" : {
"image" : "<partImage>:turnOn.<frame>"
}
},

"turnOff" : {
"properties" : {
"image" : "<partImage>:turnOff.<frame>"
}
}
}
}
},
"scanoverlay" : {
"properties" : {
"offset" : [0, 0], // TODO adjust
"centered" : false,
"zLevel" : 2
},

"partStates" : {
"scanState" : {
"off" : {
"properties" : {
"image" : "<partImage>:off"
}
},

"on" : {
"properties" : {
"image" : "<partImage>:max.<frame>"
}
}
}
}
}
}
}
}
106 changes: 106 additions & 0 deletions SMEE/objects/generic/sr1medbaybed/sr1medbaybed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
function init(virtual)
entity.setInteractive(true)

if not virtual then
responsiveObject.init()
responsiveObject.start()

self.occupiedBy = nil
end
end


function onInteraction(args)
-- scan animation
-- world.logInfo("loungableID: ".. tostring(entity.id()) .. " name: " .. world.entityName(entity.id()) )
-- TODO loungableOccupied does not work right now wait for a new patch
-- if world.loungableOccupied(entity.id()) then
-- entity.setAnimationStage("scanState", "on")
--else
-- entity.setAnimationStage("scanState", "off")
--end

local flipDirection = entity.configParameter("sitFlipDirection")
local position = entity.configParameter("sitPosition")
local orientation = entity.configParameter("sitOrientation")

return { "SitDown", {
sitFlipDirection = flipDirection,
sitPosition = position,
sitOrientation = orientation
}}
end

function switchHealthState()

if self.occupiedBy == nil then
return
end

local h = world.entityHealth(self.occupiedBy)
local p = h[1] / h[2]

if p > 0.66 then
entity.setAnimationState("responsiveState","max")
elseif p >= 0.33 and p <= 0.66 then
entity.setAnimationState("responsiveState","med")
else
entity.setAnimationState("responsiveState","low")
end
end


function main()

-- first count down timer
if self.timer > 0 then
self.timer = self.timer - 1
elseif self.timer == 0 then
-- check if timer 0 and an animation switch is needed
self.timer = -1

-- transitions
if entity.animationState("responsiveState") == self.anims.transActive.name then
switchHealthState()
elseif entity.animationState("responsiveState") == self.anims.transIdle.name then
responsiveObject.nextAnimation("idle")
else
if responsiveObject.isIdle() and #self.anims.idle > 1 then
responsiveObject.nextAnimation("idle")
elseif #self.anims.active > 1 then
switchHealthState()
end
end

end

-- detect player
local entityIds = world.playerQuery(
entity.position(),
self.detectRadius,
{
inSightOf = entity.id(),
order = "nearest"
}
)

if responsiveObject.isIdle() then
if #entityIds > 0 then
self.occupiedBy = entityIds[1]
responsiveObject.switchToActive()
end
elseif not responsiveObject.isIdle() then
if #entityIds == 0 then
self.occupiedBy = nil
responsiveObject.switchToIdle()
else
switchHealthState()
end
end
end


function die()
responsiveObject.die()
self.occupiedBy = nil
end
54 changes: 52 additions & 2 deletions SMEE/objects/generic/sr1medbaybed/sr1medbaybed.object
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"objectType" : "loungeable",
"interactAction" : "sitdown",
"sitFlipDirection" : true,
"sitPosition" : [-14, 17], // -10, 13
"sitPosition" : [-11, 15],
"sitOrientation" : "lay",
"sitAngle" : 90,
"sitCoverImage" : "/objects/generic/sr1medbaybed/sr1medbaybedcover.png",
Expand All @@ -35,5 +35,55 @@
"anchors" : [ "bottom" ]

}
]
],

"scripts" : [ "/scripts/smee/responsiveobject.lua", "sr1medbaybed.lua" ],
"scriptDelta" : 10,

"animation" : "sr1medbaybed.animation",
"animationParts" : {
"sr1medbaybed" : "sr1medbaybed.png",
"healthstatus" : "healthstatus.png",
"scanoverlay" : "scanoverlay.png"
},
"animationPosition" : [-24, 0],

// responsive object parameters
"consoleSounds" : [ "/sfx/ships/console.ogg" ],
"responsiveObject" : {
"detectRadius" : 4,
"detectLineOfSight" : true,
"responsiveAnimations" : {
"idle" : [
{
"name" : "off",
"time" : -1
}
],
"active" : [
{
"name" : "max", // max health > 66%
"time" : -1
},
{
"name" : "med", // medium health >= 33% <= 66%
"time" : -1
},
{
"name" : "low", // low health < 33%
"time" : -1
}
],
"transActive" : {
"name" : "turnOn",
"time" : 2,
"sounds" : "consoleSounds"
},
"transIdle" : {
"name" : "turnOff",
"time" : 2,
"sounds" : "consoleSounds"
}
}
}
}
Binary file modified SMEE/objects/generic/sr1medbaybed/sr1medbaybedcover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57f7cbf

Please sign in to comment.