Guest User

Untitled

a guest
Jul 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. Object = {}
  2.  
  3. function Object:New(x, y)
  4.     local obj = {}
  5.         obj.x = x or 0
  6.         obj.y = y or 0
  7.         obj.xSpeed = 0
  8.         obj.ySpeed = 0
  9.             obj.rSpeed = 0
  10.             obj.direction = 0
  11.         obj.sprite = nil
  12.  
  13.     function obj:setSprite(type, color, width_radius, height)
  14.         self.sprite = Sprite:New(type, color, width_radius, height)
  15.     end
  16.  
  17.     function obj:moveTo(x, y) -- Move object to specified destination
  18.         self.x = x
  19.         self.y = y
  20.     end
  21.  
  22.     function obj:moveBy(x, y) -- Move object by amounts x and y
  23.         self.x = self.x + x
  24.         self.y = self.y + y
  25.     end
  26.  
  27.     function obj:setSpeed( x, y )
  28.         self.xSpeed = x
  29.         self.ySpeed = y
  30.  
  31.         self.rSpeed, self.direction = resultant(self.xSpeed, self.ySpeed)
  32.     end
  33.  
  34.     function obj:addSpeed( x, y )
  35.         self.xSpeed = self.xSpeed + x
  36.         self.ySpeed = self.ySpeed + y
  37.  
  38.         self.rSpeed, self.direction = resultant(self.xSpeed, self.ySpeed)
  39.     end
  40.  
  41.     function obj:update(dt)
  42.     end
  43.  
  44.     function obj:draw()
  45.         self.sprite:draw(self.x, self.y)
  46.     end
  47.  
  48.     return obj
  49. end
Add Comment
Please, Sign In to add comment