Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pico8
- -- Riki Klein
- -- Bouncing Ball
- -- 18.10.17
- -- v1
- cls()
- -- gets called once on startup
- function _init()
- count = 0
- ball = {
- x = 64, -- x position
- y = 64, -- y position
- r = 4, -- radius
- c = 10, -- color
- vx = 0, -- x velocity
- vy = 0 -- y velocity
- }
- ball.vx = rnd(10) - 9
- ball.vy = rnd(10) - 9
- box = {
- x = 0, -- x position
- y = 0, -- y position
- w = 10, -- width
- h = 10, -- height
- c = 5 -- color
- }
- end
- -- gets called 30 times a second
- function _update()
- count = count+1
- -- ball movement
- ball.x += ball.vx -- short for ball.x = ball.x +1
- ball.y += ball.vy
- -- wrap ball
- -- if (ball.x - ball.r > 127) then
- -- ball.x = -ball.r
- -- end
- -- reflect ball
- if (ball.y - ball.r < 0) then
- ball.vy *= -1
- end
- if (ball.x - ball.r < 0) then
- ball.vx *= -1
- end
- if (ball.y + ball.r > 128) then
- ball.vy *= -1
- end
- if (ball.x + ball.r > 128) then
- ball.vx *= -1
- end
- end
- .y,
- ball.r,
- ball.c
- -- gets called 30 times a second
- -- (after the _update function)
- function _draw()
- cls()
- print("frame: "..count, 0, 0)
- -- draw the ball
- circfill(
- ball.x,
- ball
- )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement