Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. souris = Image.load("mouse.png")
  2. Curseur = { i = souris , x = 220 , y = 120}
  3. --
  4. fond = Image.load("terrain.png")
  5. --
  6. bleu = Color.new(255, 0, 0)
  7. --
  8. point = Image.load("point.png")
  9. score = Image.load("score.png")
  10. -----
  11. score = 0
  12.  
  13. function resetFruit(fruit)
  14. fruit.position = { x = fruit.pointDeDepart.x, y = fruit.pointDeDepart.y}
  15. fruit.statut = "enabled"
  16. fruit.vitesse = math.random(35, 75)
  17. fruit.angle = math.rad(math.random(fruit.angleDeTir.mini, fruit.angleDeTir.maxi))
  18.  
  19. return fruit
  20. end
  21.  
  22. -- Declaration des variables
  23.  
  24. math.randomseed(os.time())
  25. timer = Timer.new()
  26. timer:start()
  27.  
  28. -------------
  29.  
  30. fruits = {
  31. {--pasteque
  32. image = Image.load("pasteque.png"),
  33. position = { x = null, y = null},
  34. pointDeDepart = { x = 30, y = 272},
  35. angleDeTir = { mini = 64, maxi = 65 },
  36. statut = "disabled",
  37. vitesse = null,
  38. angle = null
  39. },
  40. {--mangue
  41. image = Image.load("orange.png"),
  42. position = { x = null, y = null},
  43. pointDeDepart = { x = 30, y = 272},
  44. angleDeTir = { mini = 64, maxi = 65 },
  45. statut = "disabled",
  46. vitesse = null,
  47. angle = null
  48. },
  49. {--coco
  50. image = Image.load("coco.png"),
  51. position = { x = null, y = null},
  52. pointDeDepart = { x = 30, y = 272},
  53. angleDeTir = { mini = 64, maxi = 65 },
  54. statut = "disabled",
  55. vitesse = null,
  56. angle = null
  57. }
  58. }
  59.  
  60. -------------
  61.  
  62.  
  63. fruits[1] = resetFruit(fruits[1])
  64. fruits[2] = resetFruit(fruits[2])
  65. fruits[3] = resetFruit(fruits[3])
  66. score = 0
  67. --------------------
  68.  
  69. while true do
  70. screen:clear()
  71.  
  72. pad = Controls.read()
  73.  
  74. screen:blit (0,0,fond)
  75. ---------------------------------------
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. if Curseur.x >= fruits[1].position.x and Curseur.x <= fruits[1].position.x + 71 and Curseur.y >= fruits[1].position.y and Curseur.y <= fruits[1].position.y + 77 then
  83. screen:blit (10,40,point)
  84. end
  85.  
  86.  
  87. if Curseur.x >= fruits[2].position.x and Curseur.x <= fruits[2].position.x + 71 and Curseur.y >= fruits[2].position.y and Curseur.y <= fruits[2].position.y + 77 then
  88. screen:blit (10,40,point)
  89. end
  90. if Curseur.x >= fruits[3].position.x and Curseur.x <= fruits[3].position.x + 71 and Curseur.y >= fruits[3].position.y and Curseur.y <= fruits[3].position.y + 77 then
  91. screen:blit (10,40,point)
  92. end
  93.  
  94. for i = 1, #fruits do
  95. if fruits[i].statut == "enabled" then
  96.  
  97. fruits[i].position.x = fruits[i].position.x +2
  98. fruits[i].position.y = -9.8 / 2 * fruits[i].position.x ^ 2 / (fruits[i].vitesse ^ 2 * math.cos(fruits[i].angle) ^ 2) + fruits[i].position.x * math.tan(fruits[i].angle) + 1.90
  99.  
  100. screen:blit(fruits[i].position.x,172.1 - fruits[i].position.y, fruits[i].image)
  101.  
  102. if fruits[i].position.x > 480 or fruits[i].position.x < 0 or fruits[i].position.y > 272 or fruits[i].position.y + fruits[i].image:height() < 0 then
  103. fruits[i].statut = "disabled"
  104. end
  105. if fruits[i].position.x > 480 or fruits[i].position.x < 0 or fruits[i].position.y > 272 or fruits[i].position.y + fruits[i].image:height() < 0 then
  106. score = score+1
  107. end
  108.  
  109. screen:print(40,40,"score"..score,bleu)
  110. elseif fruits[i].statut == "disabled" then
  111. if timer:time() >= 5 then
  112. fruits[i]=resetFruit(fruits[i])
  113. screen:print(10,10*i,"New!",rouge)
  114. timer:reset(0)
  115. timer:start()
  116. end
  117. end
  118. end
  119. ---------------------------------------------------------------------------
  120. if math.abs(pad:analogY()) > 33 then
  121. Curseur.y = Curseur.y + pad:analogY() / 12 --plus c'est bas plus sa iras vite
  122. end
  123. if math.abs(pad:analogX()) > 33 then
  124. Curseur.x = Curseur.x + pad:analogX() / 12
  125.  
  126. end
  127. if Curseur.y < 0 then Curseur.y = 0 elseif Curseur.y > 272 - Curseur.i:height()/2 then
  128. Curseur.y = 272 - Curseur.i:height()/2
  129. end
  130. if Curseur.x < 0 then Curseur.x = 0 elseif Curseur.x > 480 - Curseur.i:width()/2 then
  131. Curseur.x = 480 - Curseur.i:width()/2
  132. end
  133. screen:blit(Curseur.x,Curseur.y,Curseur.i)
  134.  
  135.  
  136. screen.waitVblankStart()
  137. screen.flip()
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement