Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. io.stdout:setvbuf('no')
  2.  
  3. player = {}
  4. platform = {}
  5. background = {}
  6. blocGrass = {}
  7. blocDirt = {}
  8. fireball = {}
  9. flag = {}
  10.  
  11. function love.load()
  12.  
  13. love.window.setMode(1920, 1080) -- Change les dimensions de la fenêtre
  14. love.window.setFullscreen( true)
  15. debug = false
  16.  
  17. background.img = love.graphics.newImage("image/Background.png")
  18.  
  19. platform.width = love.graphics.getWidth()
  20. platform.height = love.graphics.getHeight()
  21. platform.x = 0
  22. platform.y = platform.height / 2
  23.  
  24. blocGrass.img = love.graphics.newImage("image/grass.png") -- Paramètre de l'herbe
  25. blocGrass.x = 0
  26. blocGrass.y = love.graphics.getHeight() - (love.graphics.getHeight() /5)
  27. blocGrass.width = 32
  28. blocGrass.height = 32
  29. nbGrass = 0
  30.  
  31. blocDirt.img = love.graphics.newImage("image/dirt.png") -- Paramètre de la terre
  32. blocDirt.x = 0
  33. blocDirt.y = blocGrass.y + 32
  34. blocDirt.width = 32
  35. blocDirt.height = 32
  36. nbDirt = 0
  37. i = 0
  38.  
  39. flag.img = love.graphics.newImage("image/flag.png")
  40. flag.x = 1000
  41. flag.y = blocGrass.y
  42.  
  43. player.img = love.graphics.newImage("image/p1_front.png")
  44. player.x = 100
  45. player.y = blocGrass.y
  46. player.speed = 200
  47. player.y_velocity = 0
  48. player.ground = player.y
  49. player.jump_height = -300
  50. player.gravity = -500
  51.  
  52. fireball.x = 0
  53.  
  54. end
  55.  
  56. function placeGrass() -- on place tout les blocs
  57. while nbGrass < 60 do
  58. nbGrass = nbGrass+1
  59. love.graphics.draw(blocGrass.img, blocGrass.x + (blocGrass.height * (nbGrass - 1)), blocGrass.y)
  60. end
  61. nbGrass = 0
  62. end
  63.  
  64. function placeDirt()
  65. while nbDirt < 60 do
  66. nbDirt = nbDirt+1
  67. while i < 7 do
  68. love.graphics.draw(blocDirt.img, blocDirt.x + (blocDirt.height * (nbDirt - 1)), blocDirt.y + (blocDirt.width *(i-1)))
  69. i = i + 1
  70. end
  71. i = 1
  72. end
  73. nbDirt = 0
  74. end
  75. function toggleDebug()
  76. debug = not debug
  77. end
  78.  
  79. function initializeFireball()
  80. resetFireball()
  81. fireball.affich = not fireball.affich
  82. fireball.deplace = true
  83. end
  84. function resetFireball()
  85. fireball.img = love.graphics.newImage("image/fireball.png")
  86. fireball.x = player.x + player.img:getWidth()
  87. fireball.y = player.y - player.img:getHeight()/2
  88. fireball.vitesse = 5
  89. fireball.rotation = 0
  90. fireball.affich = false
  91. fireball.deplace = false
  92. end
  93. function refreshFireball(pt)
  94. fireball.x = fireball.x + fireball.vitesse
  95. fireball.rotation = fireball.rotation + 0.2
  96. end
  97. function love.update(dt)
  98.  
  99. if love.keyboard.isScancodeDown("d") then
  100. if player.x < (love.graphics.getWidth() - player.img:getWidth()) then
  101. player.x = player.x + (player.speed * dt)
  102. end
  103. end
  104. if love.keyboard.isScancodeDown("a") then
  105. if player.x > 0 then
  106. player.x = player.x - (player.speed * dt)
  107. end
  108. end
  109.  
  110. if love.keyboard.isScancodeDown("space") then
  111. if player.y_velocity == 0 then
  112. player.y_velocity = player.jump_height
  113. end
  114. end
  115. if player.y_velocity ~= 0 then
  116. player.y = player.y + player.y_velocity * dt
  117. player.y_velocity = player.y_velocity - player.gravity * dt
  118. end
  119.  
  120. if player.y > player.ground then
  121. player.y_velocity = 0
  122. player.y = player.ground
  123. end
  124.  
  125. if player.x < 0.3 then
  126. player.x = 0
  127. end
  128.  
  129. if player.x > 1854 then
  130. player.x = 1854
  131. end
  132.  
  133. if fireball.deplace == true then
  134. refreshFireball(dt)
  135. end
  136.  
  137. if fireball.x > flag.x then
  138. fireball.affich = false
  139. end
  140. fps = love.timer.getFPS()
  141.  
  142. end
  143.  
  144. function love.draw()
  145. love.graphics.draw(background.img)
  146. love.graphics.setColor(255,255,255)
  147.  
  148. --love.graphics.rectangle("fill", platform.x, 520, platform.width, 50)
  149. love.graphics.draw(flag.img, flag.x, blocGrass.y, 0, 1, 1, 0, 70)
  150. love.graphics.draw(player.img, player.x, player.y, 0, 1, 1, 0, 92)
  151.  
  152. if fireball.affich == true then
  153. love.graphics.draw(fireball.img, fireball.x, fireball.y, fireball.rotation, 1, 1, fireball.img:getWidth()/2, fireball.img:getHeight()/2)
  154. end
  155.  
  156. if debug == true then
  157. love.graphics.setColor(255,0,0)
  158. love.graphics.print(player.y_velocity, 0, 0)
  159. love.graphics.circle("fill", player.x, player.y, 5)
  160. love.graphics.print(player.y, 0, 15)
  161. love.graphics.print(player.x, 0, 30)
  162. love.graphics.print("fps : ", 1850, 0)
  163. love.graphics.print(fps, 1900, 0)
  164. love.graphics.circle("fill", 1280, blocGrass.y, 5)
  165. if fireball.affich == true then
  166. love.graphics.setColor(0,0,255)
  167. love.graphics.print(fireball.x, 1850, 15)
  168. love.graphics.circle("fill", fireball.x, fireball.y,5)
  169. end
  170. love.graphics.setColor(255,255,255)
  171. end
  172.  
  173. placeGrass()
  174. placeDirt()
  175.  
  176.  
  177. end
  178.  
  179. function love.keypressed(key, scancode, isRepeat)
  180. if scancode == "f1" then
  181. toggleDebug()
  182. end
  183. if scancode == "g" then
  184. love.window.close()
  185. end
  186. if scancode == "e" then
  187. initializeFireball()
  188. end
  189. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement