Advertisement
joseleeph

Untitled

Dec 29th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. Ball = Class{}
  2.  
  3. function Ball:init(x, y, width, height) -- inheritance allows you to have a baseclass that you can spawn children classes that takes all the attributes of the baseclass and add your own custom behavior
  4. self.x = x
  5. self.y = y
  6. self.width = width
  7. self.height = height
  8.  
  9. self.dx = math.random(2) == 1 and 100 or -100
  10. self.dy = math.random(-50, 50)
  11. end
  12.  
  13. function Ball:update(dt)
  14. self.x = self.x + self.dx * dt
  15. self.y = self.x + self.dy * dt
  16. end
  17.  
  18. function Ball:reset()
  19. self.x = VIRUTAL_WIDTH/2-2
  20. self.y = VIRTUAL_HEIGHT/2-2
  21.  
  22. --self.dx = math.random(2) == 1 and -100 or 100
  23. self.dx = math.random(2) == 1 and 100 or -100
  24. self.dy = math.random(-50,50) * 1.5
  25. end
  26.  
  27. function Ball:render()
  28. love.graphics.rectangle('fill', self.x, self.y, 4, 4)
  29. end
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement