fysplane/player.lua

81 lines
1.8 KiB
Lua
Raw Permalink Normal View History

Class = require 'hump/class'
require 'settings'
Player = Class{
init = function(self, id, name)
self.id = id
self.name = name
self.keys = KEYMAP[self.id]
self.actions = {
cw = function(down)
self.plane:cw(down)
end,
ccw = function(down)
self.plane:ccw(down)
end,
shoot = function(down)
self.plane:shoot(down)
end,
accelerate = function(down)
self.plane:accelerate(down)
end,
decelerate = function(down)
self.plane:decelerate(down)
end,
flip = function(down)
self.plane:flip(down)
end
}
2014-10-18 20:27:40 +00:00
self.score = 0
print(self.name .. ' (' .. self.id .. ') ready for action!')
end;
setPlane = function(self, plane)
self.plane = plane
2014-10-19 00:41:25 +00:00
if plane ~= nil then
plane:setOwner(self)
2014-10-19 00:56:32 +00:00
self.health = 1000
2014-10-19 00:41:25 +00:00
end
end;
2014-10-19 01:00:00 +00:00
getPlane = function(self)
return self.plane
end;
2014-10-19 01:45:38 +00:00
addScore = function(self, score)
self.score = self.score + score
end;
update = function(self, dt)
end;
pressDown = function(self, key, down)
2014-10-23 18:42:30 +00:00
local found = false
for action, bindings in pairs(self.keys) do
for idx, keycode in pairs(bindings) do
if key == keycode then
found = true
if self.actions[action] and self.plane then
self.actions[action](down)
end
end
end
end
2014-10-23 18:42:30 +00:00
return found
end;
press = function(self, key)
return self:pressDown(key, true)
end;
release = function(self, key)
return self:pressDown(key, false)
end;
joystick = function(self, ...)
self.plane:analog(...)
end
}