- Explosion explosion;
- ArrayList<Entity> entities = new ArrayList<Entity>();
- ArrayList<Entity> toRemove = new ArrayList<Entity>();
- void setup()
- {
- size(500, 500, P3D);
- frameRate(120);
- background(0);
- explosion = new Explosion();
- entities.add(new Joueur(100, 300));
- }
- void draw()
- {
- for (int i = entities.size()-1; i >= 0; i--)
- {
- Entity entity = entities.get(i);
- entity.display();
- entity.update();
- if (entity.x > 300 ) toRemove.add(entities.get(i));
- }
- for (Entity e : entities)
- {
- if (e.destroyed) toRemove.add(e);
- }
- for (Entity r : toRemove)
- {
- r.destroy();
- entities.remove(r);
- }
- explosion1.display();
- }
- abstract class Entity {
- float x, y, w, h;
- boolean ally, destroyed = false;
- Entity(float x, float y, boolean ally)
- {
- this.x = x;
- this.y = y;
- this.ally = ally;
- }
- void update()
- {
- }
- void display()
- {
- rect(x, y, 20, 20);
- }
- void touched()
- {
- }
- void destroy()
- {
- }
- }
- class Vaisseau extends Entity {
- int vie;
- double delay;
- double delayTir;
- Vaisseau(float x, float y, boolean player)
- {
- super(x, y, player);
- this.ally = player;
- delayTir = ally ? 10 : random(200, 250);
- delay = (ally ? delayTir : delayTir/2) * dTime ;
- }
- void update()
- {
- S4P.updateSprites(dTime);
- S4P.drawSprites();
- }
- void tir()
- {
- //...
- }
- void touched()
- {
- vie -= 1;
- if (vie <= 0) destroyed = true;
- }
- void destroy()
- {
- explosion1.start(x, y)
- }
- }
- class Joueur extends Vaisseau {
- int vitesse;
- Joueur(float x, float y)
- {
- super(x, y, true);
- vitesse = 5;
- vie = 1;
- }
- void update()
- {
- x ++;
- }
- }