Advertisement
fzed51

[lua] inertialUnit Class

Aug 25th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. inertialUnit = {
  2.     ['x'] = 0,
  3.     ['y'] = 0,
  4.     ['z'] = 0,
  5.     ['d'] = 0,
  6.     ['mouv'] = {
  7.         [0]   = { 0, 0, 1},
  8.         [1]   = { 1, 0, 0},
  9.         [2]   = { 0, 0,-1},
  10.         [3]   = {-1, 0, 0},
  11.         ['u'] = { 0, 1, 0},
  12.         ['d'] = { 0,-1, 0}
  13.     }
  14. }
  15. function inertialUnit:new (o)
  16.     o = o or {}   -- create object if user does not provide one
  17.     setmetatable(o, self)
  18.     self.__index = self
  19.     return o
  20. end
  21. function inertialUnit.__tostring(self)
  22.     return "[ Object inertialUnit {x : ".. self.x ..", y : ".. self.y ..", z : ".. self.z ..", delta : ".. self.d .."} ]"
  23. end
  24. function inertialUnit:getPos()
  25.   local o = {}
  26.   o.x, o.y, o.z, o.d = self.x, self.y, self.z, self.d
  27.   return o
  28. end
  29. function inertialUnit:setPos(x, y, z, d)
  30.   self.x = x
  31.   self.y = y
  32.   self.z = z
  33.   self.d = d
  34. end
  35. function inertialUnit:deplace (mouv)
  36.     self.x = self.x + mouv[1]
  37.     self.y = self.y + mouv[2]
  38.     self.z = self.z + mouv[3]
  39. end
  40. function inertialUnit:tourne (angle)
  41.     self.d = ( self.d + angle ) % 4
  42. end
  43. function inertialUnit:forward()
  44.     self:deplace( self.mouv[ self.d ] )
  45. end
  46. function inertialUnit:back()
  47.     self:deplace( self.mouv[ ( self.d + 2 ) % 4 ] )
  48. end
  49. function inertialUnit:up()
  50.     self:deplace( self.mouv[ 'u' ] )
  51. end
  52. function inertialUnit:down()
  53.     self:deplace( self.mouv[ 'd' ] )
  54. end
  55. function inertialUnit:right()
  56.     self:tourne( 1 )
  57. end
  58. function inertialUnit:left()
  59.     self:tourne( -1 )
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement