Advertisement
S0lll0s

Löve2D Jumping Circle controls

Nov 26th, 2014
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. local x, y = 400, 100
  2. local vx, vy = 0, 0
  3. local gravity = 200
  4. local jumpspeed = 200
  5. local maxspeed = 300
  6.  
  7. function love.update( dt )
  8.     x = x + vx*dt
  9.     y = y + vy*dt
  10.    
  11.     vy = vy + gravity*dt
  12.     vx = vx * 0.9 -- Reibung
  13.     if math.abs( vx ) < 10 then
  14.         vx = 0
  15.     end
  16.    
  17.     if y >= 500 then
  18.         y = 500 -- nicht in den Boden fallen
  19.         vy = 0
  20.     end
  21.    
  22.     if love.keyboard.isDown( "left" ) then
  23.         vx = -maxspeed
  24.     elseif love.keyboard.isDown( "right" ) then
  25.         vx = maxspeed
  26.     end
  27.        
  28.     if love.keyboard.isDown( "up" ) and y >= 500 then
  29.         vy = -jumpspeed
  30.     end
  31. end
  32.  
  33. function love.draw()
  34.     love.graphics.circle( "fill", x, y, 10 )
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement