Advertisement
joseleeph

Untitled

Dec 29th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. Ball = Class{}
  2.  
  3. function Ball:init(x, y, width, height) -- you spelled it intit
  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:reset()
  14. self.x = VIRTUAL_WIDTH/2-2
  15. self.y = VIRTUAL_HEIGHT/2-2
  16. self.dx = math.random(2) == 1 and 100 or -100
  17. self.dy = math.random(-50,50) * 1.5
  18. end
  19.  
  20. function Ball:update(dt)
  21. self.x = self.x + self.dx * dt
  22. self.y = self.y + self.dy * dt
  23. end
  24.  
  25. function Ball:render()
  26. love.graphics.rectangle('fill', self.x, self.y, 4, 4)
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement