All pastes #2128891 Raw Edit

Mine

public text v1 · immutable
#2128891 ·published 2012-03-16 19:10 UTC
rendered paste body

if not ShipMetatable then ShipMetatable = {} end

function ShipMetatable.__index(t, k)
	if rawget(t, k) then return rawget(t, k) end
	return ShipMetatable[k]
end

function ShipMetatable:init(def)
	local body = Body(def)
	local prop = Prop {
		Name = def.Name .. "Prop"
	}
	prop:setTexture(Texture("textures/check.jpg"))
	prop:setMesh(Mesh("meshes/interceptor.xsm"))
	body:addChild(prop)
	Spawn(body)
	Spawn(prop)
	self.body = body
	self.prop = prop
end

function ShipMetatable:control(control, value)
-- 	print(control, value)
	if value > 0 then value = value + 5000 end
	if value < 0 then value = value - 5000 end
	value = -(value*1.5)/32768
	if control == "yaw" then
		self.body:setAngularVelocity(0, 0, value)
	elseif control == "roll" then
		self.body:setAngularVelocity(value, 0, 0)
	elseif control == "pitch" then
		self.body:setAngularVelocity(0, value, 0)
	end
	if control == "fire" then
-- 		self.body:setAngularVelocity(0, 0, 0)
-- 		self.body:applyCentralImpulse(0, 100, 0)
-- 		self.body:applyTorque(0, 0, -100)
	end
	flush()
end

function Ship(def)
	local ship = {}
	setmetatable(ship, ShipMetatable)
	ship:init(def)
	return ship
end