1. image(joueur, vaisseau_X, vaisseau_Y, box_joueur.w, box_joueur.h); // in a class player
  2. image(ennemi, box1.x, box1.y, box1.w, box1.h); //in a class ennemy
  3. boolean collision()
  4. {
  5. int x1 = vaisseau_X;
  6. int y1 = vaisseau_Y;
  7. int h1 = box_joueur.h;//50
  8. int w1 = box_joueur.w;//100
  9. int x2 = box1.x;//800
  10. int y2 = box1.y;//250
  11. int h2 = box1.h;//100
  12. int w2 = box1.w;//100
  13. if ((x2 >= x1 + w1) || (x2 + w2 <= x1) || (y2 >= y1 + h1) || (y2 + h2 <= y1))
  14. {
  15. return false;
  16. } else {
  17. return true;
  18. }
  19. }
  20. if (player.collision())
  21. {
  22. } else
  23. {
  24. player.draw();
  25. }
  26. if (enemy.collision())
  27. {
  28. } else
  29. {
  30. enemy.draw();
  31. }