//--------------------------------------------- class Shot { float shotX, shotY, velX, velY; int age; Trail trail; boolean ignore; Shot nextShot; //next object in a linked list //--------------------------------------------- Shot(float x, float y, float vx, float vy, int inage){ ignore = false; age = inage; shotX = x; shotY = y; velX = vx; velY = vy; trail = new Trail(8,1,255,0,0); } //--------------------------------------------- void addShot(float x, float y, float vx, float vy, int inage){ if(nextShot!=null){ nextShot.addShot( x, y, vx, vy, inage); } else { nextShot = new Shot(x, y, vx, vy, inage); } } //--------------------------------------------- void update(){ //Updates the shot's position if(!ignore && age==0) explode(); if(!ignore){ age--; if( dist(enemy.x,enemy.y,shotX,shotY) < 17){ enemy.kill(); explode(); } shotX = shotX+velX; shotY = shotY+velY; trail.update(shotX, shotY); visualize(); } //Updates the rest of the shots in the linked list if(nextShot!=null){ nextShot.update(); // Removes redundant objects if(nextShot.ignore) nextShot = nextShot.nextShot; } } //--------------------------------------------- void explode(){ ignore = true; explosion.addBlast(shotX,shotY); if( dist(enemy.x,enemy.y,shotX,shotY) < 30) enemy.kill(); } //--------------------------------------------- void visualize(){ //Draws the shot stroke(255,0,0); point(shotX, shotY); } }