Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ball = Class{}
- function Ball:init(x, y, width, height) -- you spelled it intit
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.dx = math.random(2) == 1 and 100 or -100 -- turnary expression, randomly between 100 and -100
- self.dy = math.random(-50, 50)
- end
- function Ball:collides(box)
- if self.x > box.x + box.width or self.x + self.width < box.x then
- return false
- end
- if self.x > box.y + box.height or self.y + self.height < box.y then
- end
- return true
- end
- function Ball:reset()
- self.x = VIRTUAL_WIDTH/2-2 -- ballX = VIRTUAL_WIDTH/2-2
- self.y = VIRTUAL_HEIGHT/2-2 -- ballY = VIRTUAL_HEIGHT/2-2
- self.dx = math.random(2) == 1 and 100 or -100 -- ballDX = math.random(2) == 1 and -100 or 100
- self.dy = math.random(-50,50) * 1.5 --ballDY = math.random(-50,50)
- end
- function Ball:update(dt)
- self.x = self.x + self.dx * dt
- self.y = self.y + self.dy * dt
- end
- function Ball:render()
- love.graphics.rectangle('fill', self.x, self.y, 4, 4)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement