Advertisement
Guest User

Untitled

a guest
Oct 24th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. platform = {}
  2. player = {}
  3.  
  4. function love.load()
  5.     platform.width = love.graphics.getWidth()
  6.     platform.height = love.graphics.getHeight()
  7.  
  8.     platform.x = 0
  9.     platform.y = platform.height / 2
  10.  
  11.     player.x = love.graphics.getWidth() / 2
  12.     player.y = love.graphics.getHeight() / 2
  13.  
  14.     player.speed = 200
  15.  
  16.     player.img = love.graphics.newImage('purple.png')
  17.  
  18.     player.ground = player.y
  19.  
  20.     player.y_velocity = 0
  21.  
  22.     player.jump_height = -300
  23.     player.gravity = -500
  24. end
  25.  
  26. function love.update(dt)
  27.     if love.keyboard.isDown('d') then
  28.         if player.x < (love.graphics.getWidth() - player.img:getWidth()) then
  29.             player.x = player.x + (player.speed * dt)
  30.         end
  31.     elseif love.keyboard.isDown('a') then
  32.         if player.x > 0 then
  33.             player.x = player.x - (player.speed * dt)
  34.         end
  35.     end
  36.  
  37.     if love.keyboard.isDown('space') then
  38.         if player.y_velocity == 0 then
  39.             player.y_velocity = player.jump_height
  40.         end
  41.     end
  42.  
  43.     if player.y_velocity ~= 0 then
  44.         player.y = player.y + player.y_velocity * dt
  45.         player.y_velocity = player.y_velocity - player.gravity * 0.01
  46.     end
  47.  
  48.     i=dt
  49.    
  50.     if player.y > player.ground then
  51.         player.y_velocity = 0
  52.         player.y = player.ground
  53.     end
  54. end
  55.  
  56. function love.draw()
  57.     love.graphics.setColor(255, 255, 255)
  58.     love.graphics.rectangle('fill', platform.x, platform.y, platform.width, platform.height)
  59.  
  60.     love.graphics.draw(player.img, player.x, player.y, 0, 1, 1, 0, 32)
  61.     love.graphics.print(i, 100, 100, 0, 10, 10)
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement