player.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. function love.update(dt)
  2. world:update(dt) -- start the world
  3. love.graphics.print(player.body:getY(), canw/2, canv/2)
  4. love.graphics.print(platform.body:getY(), canw/3, canv/2)
  5. if love.keyboard.isDown("right") then
  6. plritate()
  7. if player.body:getX() < (love.graphics.getWidth() - player.img:getWidth()) then
  8. player.body:setLinearVelocity(player.speed,0+player.body:getY()/3 )
  9. end
  10. elseif love.keyboard.isDown("left") then
  11. plrotate()
  12. if player.x > 0 then
  13. player.body:setLinearVelocity(-player.speed,0+player.body:getY()/3 )
  14. end
  15. end
  16. if love.keyboard.isDown("space") then
  17. if player.body:getY() + 200 > platform.body:getY() then
  18. player.body:setLinearVelocity(0,player.jump)
  19. end
  20. end
  21. if love.keyboard.isDown("down") then
  22. player.body:setPosition(650/2, 650/2)
  23. -- reset velocity to 0
  24. player.body:setLinearVelocity(0, 0)
  25. end
  26. end
  27. function plrotate()
  28. player.img = love.graphics.newImage('images/tux1.png')
  29. end
  30. function plritate()
  31. player.img = love.graphics.newImage('images/tux.png')
  32. end