Skip to content

Instantly share code, notes, and snippets.

@ColonelThirtyTwo
Created October 25, 2013 00:46
Show Gist options
  • Save ColonelThirtyTwo/7147705 to your computer and use it in GitHub Desktop.
Save ColonelThirtyTwo/7147705 to your computer and use it in GitHub Desktop.
"Boost Shoes" Item for Cobalt
hook.add("gameInit", function()
localize.set(localize.language, "item_boostShoes", "Boost Shoes")
ITEMS.boostShoes = {
rechargeTime = 3,
jumpPower = 30,
jetTime = 0.3,
ai = {},
asObjectDestroy = ITEMS.jetShoes.asObjectDestroy,
buyable = true,
credits = 250,
cyborg = true,
droppable = true,
equipment = "jetShoes",
equipped = true,
feet = true,
gear = true,
iconName = "jetshoes_icon",
iconSprite = 750,
index = "boostShoes",
initMethod = function(self, ...)
ITEMS.jetShoes.initMethod(self, ...)
end,
initRuntimeMethod = ITEMS.jetShoes.initRuntimeMethod,
loaded = true,
mobility = true,
name = "Boost Shoes",
robot = true,
sellable = true,
sprite = 749,
spriteName = "jetshoes",
updateMethod = function(self, actor, dt, ...)
self.charge = self.charge + dt
if self.jetTimer then
self.jetTimer = self.jetTimer - dt
if self.jetTimer < 0 then
actor:emitSound("jetEnd")
self.jetTimer = nil
if self.leftFlame then
self.leftFlame:remove()
self.leftFlame = nil
end
if self.rightFlame then
self.rightFlame:remove()
self.rightFlame = nil
end
else
actor:emitLoop("jetLoop")
if not self.leftFlame or self.leftFlame._remove then
self.leftFlame = actor:emitOwnedFx("jetFlame")
self.rightFlame = actor:emitOwnedFx("jetFlame")
self.leftFlame.reference = actor
self.leftFlame.node = actor:getLeftFootNode()
self.leftFlame:setAngle(0)
self.rightFlame.reference = actor
self.rightFlame.node = actor:getRightFootNode()
self.rightFlame:setAngle(0)
end
end
end
end,
useMethod = function(self, actor, _, _)
if self.charge >= ITEMS[self.type].rechargeTime then
actor:emitSound("jetStart")
local power = ITEMS[self.type].jumpPower
local angle = actor:getAbsoluteAngle()
if actor.facingRight then
angle = angle + math.pi/2
else
angle = angle - math.pi/2
end
local dx = math.cos(angle)*-power
local dy = math.sin(angle)*-power
actor:addSpeedXY(dx, dy)
self.charge = 0
self.jetTimer = ITEMS[self.type].jetTime
end
end,
maxCharge = 1.8,
rechargeTime = 0.9,
}
OBJECTS.boostShoes = {
bounds = {
b = 4.875,
l = -10.5,
physical = true,
r = 10.5,
t = -4.875,
},
box2dControlled = true,
box2dControlledSpeed = true,
collisionMethod = OBJECTS.jetShoes.collisionMethod,
editor = OBJECTS.jetShoes.editor,
hasTemperature = true,
hitMethod = OBJECTS.jetShoes.hitMethod,
hitable = true,
id = "boostShoes",
index = "boostShoes",
initMethod = OBJECTS.jetShoes.initMethod,
initRuntimeMethod = OBJECTS.jetShoes.initRuntimeMethod,
itemRefIndex = "boostShoes",
lightMapRenderMethod = OBJECTS.jetShoes.lightMapRenderMethod,
lit = true,
onAddedMethod = OBJECTS.jetShoes.onAddedMethod,
physics = {
[1] = {
category = 256,
density = 5,
friction = 0.02,
height = 9.75,
isSensor = false,
mask = 1927,
ox = 0,
oy = 0,
restitution = 0,
shape = "box",
width = 21,
},
[2] = {
category = 256,
density = 5,
friction = 0.02,
height = 9.75,
isSensor = true,
mask = 16,
ox = 0,
oy = 0,
restitution = 0,
shape = "box",
width = 21,
},
bodyDef = {
allowSleep = true,
isBullet = false,
},
},
preRenderMethod = OBJECTS.jetShoes.preRenderMethod,
reactionMethod = OBJECTS.jetShoes.reactionMethod,
reflectable = true,
render = OBJECTS.jetShoes.render,
renderMethod = OBJECTS.jetShoes.renderMethod,
sensorMethod = OBJECTS.jetShoes.sensorMethod,
spriteOffset = 0.5,
spriteOffsetAngle = -1.5707963267949,
spriteOffsetAngleFlipped = -1.5707963267949,
spriteOffsetFlipped = 0.5,
updateMethod = OBJECTS.jetShoes.updateMethod,
warningForMethod = OBJECTS.jetShoes.warningForMethod,
}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment