Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. largeur = love.graphics:getHeight()
  2. hauteur = love.graphics:getWidth()
  3.  
  4.  
  5. Carre_Bleu = {}
  6.  
  7. Carre_Bleu.x = largeur/2
  8. Carre_Bleu.y = hauteur/2
  9. Carre_Bleu.w = 100
  10. Carre_Bleu.h = 100
  11.  
  12.  
  13. Carre_Rouge = {}
  14.  
  15. Carre_Rouge.x = largeur/2
  16. Carre_Rouge.y = hauteur/2
  17. Carre_Rouge.w = 100
  18. Carre_Rouge.h = 100
  19.  
  20.  
  21. function love.load()
  22.  
  23.   image1 = love.graphics.newImage("image/Carre Bleu.png")
  24.   image2 = love.graphics.newImage("image/Carre Rouge.png")
  25.   image3 = love.graphics.newImage("image/Carre Vert.png")
  26.  
  27.  
  28. end
  29.  
  30. function love.update(dt)
  31.     --ici on test la collision entre les deux carrés si ils sont en contact "collision ok" est ecrit dans le terminal
  32.     if Carre_Bleu.x < Carre_Rouge.x + Carre_Rouge.w and
  33.       Carre_Bleu.x + Carre_Bleu.w > Carre_Rouge.x and
  34.       Carre_Bleu.y < Carre_Rouge.y + Carre_Rouge.h and
  35.       Carre_Bleu.h + Carre_Bleu.y > Carre_Rouge.y   then
  36.         print("collision ok")
  37.     end
  38.  
  39.    if love.keyboard.isDown("right") then
  40.      
  41.    Carre_Bleu.x = Carre_Bleu.x + 4
  42.    
  43.   end
  44.  
  45.   if love.keyboard.isDown("left") then
  46.     Carre_Bleu.x = Carre_Bleu.x - 4
  47.   end
  48.  
  49.   if love.keyboard.isDown("up") then
  50.    Carre_Bleu.y = Carre_Bleu.y - 4
  51.   end
  52.  
  53.   if love.keyboard.isDown("down") then
  54.     Carre_Bleu.y = Carre_Bleu.y + 4
  55.   end
  56.  
  57.  
  58.    if love.keyboard.isDown("q") then
  59.      
  60.     Carre_Rouge.x = Carre_Rouge.x + 4
  61.    
  62.   end
  63.  
  64.   if love.keyboard.isDown("d") then
  65.     Carre_Rouge.x = Carre_Rouge.x - 4
  66.   end
  67.  
  68.   if love.keyboard.isDown("z") then
  69.    Carre_Rouge.y = Carre_Rouge.y - 4
  70.   end
  71.  
  72.   if love.keyboard.isDown("s") then
  73.     Carre_Rouge.y = Carre_Rouge.y + 4
  74.   end
  75.  
  76.  
  77. end
  78. function love.draw()
  79.  
  80.    
  81.  
  82.  
  83.      
  84.  love.graphics.draw(image1, Carre_Rouge.x, Carre_Rouge.y)
  85.  
  86.      
  87.  love.graphics.draw(image2, Carre_Bleu.x, Carre_Bleu.y)
  88.  
  89.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement