1. PImage bulletIm, playerIm;
  2. class Entity {
  3. int x, y, w, h;
  4. PImage im;
  5. boolean ally;
  6. Entity(int x, int y, PImage im, boolean ally) {
  7. this.x = x;
  8. this.y = y;
  9. this.w = im.width;
  10. this.h = im.height;
  11. this.im = im;
  12. this.ally = ally;
  13. }
  14. boolean isCollinding(Entity e) {
  15. return !(x+w<e.x || x>e.x+e.w || y+h<e.y || y>e.y+e.h);
  16. }
  17. void update() {
  18. }
  19. void render() {
  20. image(im, x, y)
  21. }
  22. void destroy() { //sera exécuté lorsque l'objet sera détruit
  23. }
  24. }
  25. class Vaisseau extends Entity {
  26. int delay;
  27. Vaiseau(int x, int y, PImage im, boolean player) {
  28. super(x, y, im);
  29. this.ally = player;
  30. }
  31. void update() {
  32. delay ++;
  33. }
  34. void tir() {
  35. if(delay < 10)
  36. return;
  37. delay = 0;
  38. bullets.add(new Bullet(x+(ally ? w : -bulletIm.width), y+h/2-bulletIm.height));
  39. }
  40. }