1. Explosion explosion;
  2. ArrayList<Entity> entities = new ArrayList<Entity>();
  3. ArrayList<Entity> toRemove = new ArrayList<Entity>();
  4. void setup()
  5. {
  6. size(500, 500, P3D);
  7. frameRate(120);
  8. background(0);
  9. explosion = new Explosion();
  10. entities.add(new Joueur(100, 300));
  11. }
  12. void draw()
  13. {
  14. for (int i = entities.size()-1; i >= 0; i--)
  15. {
  16. Entity entity = entities.get(i);
  17. entity.display();
  18. entity.update();
  19. if (entity.x > 300 ) toRemove.add(entities.get(i));
  20. }
  21. for (Entity e : entities)
  22. {
  23. if (e.destroyed) toRemove.add(e);
  24. }
  25. for (Entity r : toRemove)
  26. {
  27. r.destroy();
  28. entities.remove(r);
  29. }
  30. explosion1.display();
  31. }
  32. abstract class Entity {
  33. float x, y, w, h;
  34. boolean ally, destroyed = false;
  35. Entity(float x, float y, boolean ally)
  36. {
  37. this.x = x;
  38. this.y = y;
  39. this.ally = ally;
  40. }
  41. void update()
  42. {
  43. }
  44. void display()
  45. {
  46. rect(x, y, 20, 20);
  47. }
  48. void touched()
  49. {
  50. }
  51. void destroy()
  52. {
  53. }
  54. }
  55. class Vaisseau extends Entity {
  56. int vie;
  57. double delay;
  58. double delayTir;
  59. Vaisseau(float x, float y, boolean player)
  60. {
  61. super(x, y, player);
  62. this.ally = player;
  63. delayTir = ally ? 10 : random(200, 250);
  64. delay = (ally ? delayTir : delayTir/2) * dTime ;
  65. }
  66. void update()
  67. {
  68. S4P.updateSprites(dTime);
  69. S4P.drawSprites();
  70. }
  71. void tir()
  72. {
  73. //...
  74. }
  75. void touched()
  76. {
  77. vie -= 1;
  78. if (vie <= 0) destroyed = true;
  79. }
  80. void destroy()
  81. {
  82. explosion1.start(x, y)
  83. }
  84. }
  85. class Joueur extends Vaisseau {
  86. int vitesse;
  87. Joueur(float x, float y)
  88. {
  89. super(x, y, true);
  90. vitesse = 5;
  91. vie = 1;
  92. }
  93. void update()
  94. {
  95. x ++;
  96. }
  97. }