fysplane/player.lua

68 lines
1.6 KiB
Lua
Raw 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
}
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;
press = function(self, key)
for action, keycode in pairs(self.keys) do
if key == keycode then
2014-10-19 00:41:25 +00:00
if self.actions[action] and self.plane then
self.actions[action](true)
end
end
end
end;
release = function(self, key)
for action, keycode in pairs(self.keys) do
if key == keycode then
2014-10-19 00:41:25 +00:00
if self.actions[action] and self.plane then
self.actions[action](false)
end
end
end
end;
}