Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- pico8
  2. -- Riki Klein
  3. -- Bouncing Ball
  4. -- 18.10.17
  5. -- v1
  6.  
  7.  
  8. cls()
  9.  
  10.  
  11. -- gets called once on startup
  12. function _init()
  13.     count = 0
  14.    
  15.     ball = {
  16.         x = 64, -- x position
  17.         y = 64, -- y position
  18.         r = 4,  -- radius
  19.         c = 10, -- color
  20.         vx = 0, -- x velocity
  21.         vy = 0  -- y velocity
  22.     }
  23.    
  24.     ball.vx = rnd(10) - 9
  25.     ball.vy = rnd(10) - 9
  26.    
  27.     box = {
  28.         x = 0,  -- x position
  29.         y = 0,  -- y position
  30.         w = 10, -- width
  31.         h = 10, -- height
  32.         c = 5   -- color
  33.     }
  34. end
  35.  
  36.  
  37. -- gets called 30 times a second
  38. function _update()
  39.     count = count+1
  40.    
  41.    
  42.     -- ball movement
  43.     ball.x += ball.vx  -- short for ball.x = ball.x +1
  44.     ball.y += ball.vy
  45.  
  46.  
  47.  -- wrap ball
  48. --  if (ball.x - ball.r > 127) then
  49. --      ball.x = -ball.r
  50. --  end
  51.    
  52.     -- reflect ball
  53.     if (ball.y - ball.r < 0) then
  54.         ball.vy *= -1
  55.     end
  56.  
  57.  if (ball.x - ball.r < 0) then
  58.         ball.vx *= -1
  59.     end
  60.    
  61.     if (ball.y + ball.r > 128) then
  62.         ball.vy *= -1
  63.     end
  64.    
  65.     if (ball.x + ball.r > 128) then
  66.         ball.vx *= -1
  67.     end
  68.    
  69. end
  70.  
  71. .y,
  72.         ball.r,
  73.         ball.c
  74. -- gets called 30 times a second
  75. -- (after the _update function)
  76. function _draw()
  77.     cls()
  78.    
  79.     print("frame: "..count, 0, 0)
  80.  
  81.     -- draw the ball
  82.     circfill(
  83.         ball.x,
  84.         ball
  85.     )
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement