Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ball = {}
- Ball.__index = Ball
- function Ball.create(x, y, width, height)
- -- Set up default arguments.
- x = x or 0
- y = y or 0
- width = width or 20
- height = height or 20
- local ball = {}
- setmetatable(ball, Ball)
- -- Set data members from params.
- ball.x = x
- ball.y = y
- ball.width = width
- ball.height = height
- -- Set default data members not in constructor params.
- ball.speed = 0
- ball.heading = {}
- ball.heading.x = 0
- ball.heading.y = 0
- return ball
- end
- function Ball:setSpeed(speed)
- self.speed = speed
- end
- function Ball:setHeading(x, y)
- self.heading.x = x
- self.heading.y = y
- end
- function Ball:tick(dt)
- self.x = self.x + math.cos(self.heading.x / (self.speed * dt) )
- self.y = self.y + math.cos(self.heading.y / (self.speed * dt) )
- end
- function Ball:render()
- love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement