2014-10-18 14:58:04 +00:00
|
|
|
Class = require 'hump/class'
|
|
|
|
require 'settings'
|
|
|
|
|
|
|
|
Player = Class{
|
|
|
|
init = function(self, id, name)
|
|
|
|
self.id = id
|
|
|
|
self.name = name
|
|
|
|
self.keys = KEYMAP[self.id]
|
2014-10-18 17:00:13 +00:00
|
|
|
self.actions = {
|
|
|
|
cw = function(down)
|
|
|
|
self.plane:cw(down)
|
|
|
|
end,
|
|
|
|
ccw = function(down)
|
|
|
|
self.plane:ccw(down)
|
|
|
|
end,
|
2014-10-18 18:34:58 +00:00
|
|
|
shoot = function(down)
|
|
|
|
self.plane:shoot(down)
|
|
|
|
end
|
2014-10-18 17:00:13 +00:00
|
|
|
}
|
2014-10-18 14:58:04 +00:00
|
|
|
|
|
|
|
print(self.name .. ' (' .. self.id .. ') ready for action!')
|
|
|
|
end;
|
|
|
|
|
2014-10-18 16:44:52 +00:00
|
|
|
setPlane = function(self, plane)
|
|
|
|
self.plane = plane
|
|
|
|
end;
|
|
|
|
|
2014-10-18 14:58:04 +00:00
|
|
|
press = function(self, key)
|
|
|
|
for action, keycode in pairs(self.keys) do
|
|
|
|
if key == keycode then
|
|
|
|
print(self.name .. ' pressed ' .. action .. '!')
|
2014-10-18 17:00:13 +00:00
|
|
|
if self.actions[action] then
|
|
|
|
self.actions[action](true)
|
|
|
|
end
|
2014-10-18 14:58:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
release = function(self, key)
|
|
|
|
for action, keycode in pairs(self.keys) do
|
|
|
|
if key == keycode then
|
|
|
|
print(self.name .. ' released ' .. action .. '!')
|
2014-10-18 17:00:13 +00:00
|
|
|
if self.actions[action] then
|
|
|
|
self.actions[action](false)
|
|
|
|
end
|
2014-10-18 14:58:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end;
|
2014-10-18 17:00:13 +00:00
|
|
|
}
|