Advertisement
GameCodeurStudent

Untitled

Nov 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. -- Cette ligne permet d'afficher des traces dans la console pendant l'éxécution
  2. io.stdout:setvbuf('no')
  3.  
  4. -- Cette ligne permet de déboguer pas à pas dans ZeroBraneStudio
  5. if arg[#arg] == "-debug" then require("mobdebug").start() end
  6.  
  7. vaisseau = {}
  8. vaisseau.canvas = love.graphics.newCanvas(20,30)
  9. vaisseau.x = 0
  10. vaisseau.y = 0
  11. vaisseau.angle = 270
  12. vaisseau.vx = 0
  13. vaisseau.vy = 0
  14. vaisseau.speed = 3
  15.  
  16. function love.load()
  17.  
  18. largeur = love.graphics.getWidth()
  19. hauteur = love.graphics.getHeight()
  20.  
  21. vaisseau.x = largeur / 2
  22. vaisseau.y = hauteur / 2
  23.  
  24. love.graphics.setCanvas(vaisseau.canvas)
  25. love.graphics.setColor(255,128,128)
  26. love.graphics.setLineWidth(1.5)
  27. love.graphics.polygon("line", {0, 0, 10, 30, 20, 0, 10, 10})
  28. love.graphics.setCanvas()
  29. end
  30.  
  31. function love.update(dt)
  32. if love.keyboard.isDown("right") then
  33. vaisseau.angle = vaisseau.angle + (90 * dt)
  34. if vaisseau.angle > 360 then vaisseau.angle = 0 end
  35. end
  36.  
  37. if love.keyboard.isDown("left") then
  38. vaisseau.angle = vaisseau.angle - (90 * dt)
  39. if vaisseau.angle < 0 then vaisseau.angle = 360 end
  40. end
  41.  
  42. if love.keyboard.isDown("up") then
  43. local angle_radian = math.rad (vaisseau.angle)
  44. local force_x = math.cos(angle_radian) * (vaisseau.speed * dt)
  45. local force_y = math.sin(angle_radian) * (vaisseau.speed * dt)
  46. vaisseau.vx = vaisseau.vx + force_x
  47. vaisseau.vy = vaisseau.vy + force_y
  48. end
  49.  
  50. --vaisseau.vy = vaisseau.vy + (0.6 * dt)
  51.  
  52. -- if math.abs(vaisseau.vx) > 1 then
  53. -- if vaisseau.vx > 0 then
  54. -- vaisseau.vx = 1
  55. -- else
  56. -- vaisseau.vx = -1
  57. -- end
  58. -- end
  59. -- if math.abs(vaisseau.vy) > 1 then
  60. -- if vaisseau.vy > 0 then
  61. -- vaisseau.vy = 1
  62. -- else
  63. -- vaisseau.vy = -1
  64. -- end
  65. -- end
  66.  
  67. -- vaisseau.x = vaisseau.x + vaisseau.vx
  68. -- vaisseau.y = vaisseau.y + vaisseau.vy
  69. end
  70.  
  71. function love.draw()
  72. love.graphics.draw(vaisseau.canvas,vaisseau.x,vaisseau.y,vaisseau.angle,1,1)
  73. --love.graphics.polygon('fill', 125, 100, 135, 75, 145, 100)
  74. love.graphics.print("Score : 0", 10, 10)
  75. love.graphics.print("Vie : 3", 10, 30)
  76. end
  77.  
  78. function love.keypressed(key)
  79.  
  80. print(key)
  81.  
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement