Loading...
Logo
Processing Forum
I have a almost finished Space Invaders Game. But when the game starts, it thinks that Game Over has Occurred. 
I'm getting no error code. Also any slight tweek's are welcomed if they are noted.
If you can help, thank you very much.
Sorry about the Long code, but Invader1Bullet class is basically repeated in the corresponding numbers.

Code:
Copy code
  1. SpaceShip spaceship;
  2. bullet bullet;

  3. Invader invader1;
  4. Invader invader2;
  5. Invader invader3;
  6. Invader invader4;
  7. Invader invader5;
  8. Invader invader6;
  9. Invader invader7;
  10. Invader invader8;

  11. Inv1Bullet inv1bullet;
  12. Inv2Bullet inv2bullet;
  13. Inv3Bullet inv3bullet;
  14. Inv4Bullet inv4bullet;
  15. Inv5Bullet inv5bullet;
  16. Inv6Bullet inv6bullet;
  17. Inv7Bullet inv7bullet;
  18. Inv8Bullet inv8bullet;

  19. boolean gameplay = false;
  20. int startingTime;

  21. void setup () {
  22.   size (1000,600);
  23.   smooth ();
  24.   
  25.   //Create SpaceShip & Bullet
  26.   spaceship = new SpaceShip ();
  27.   bullet = new bullet ();
  28.   
  29.   //Create 8 Invaders
  30.   invader1 = new Invader (65,100);
  31.   invader2 = new Invader (165,100);
  32.   invader3 = new Invader (265,100);
  33.   invader4 = new Invader (365,100);
  34.   invader5 = new Invader (65,190);
  35.   invader6 = new Invader (165,190);
  36.   invader7 = new Invader (265,190);
  37.   invader8 = new Invader (365,190);
  38.   
  39.   //Create 8 Bullets for Invaders
  40.   inv1bullet = new Inv1Bullet (65,100);
  41.   inv2bullet = new Inv2Bullet (165,100);
  42.   inv3bullet = new Inv3Bullet (265,100);
  43.   inv4bullet = new Inv4Bullet (365,100);
  44.   inv5bullet = new Inv5Bullet (65,190);
  45.   inv6bullet = new Inv6Bullet (165,190);
  46.   inv7bullet = new Inv7Bullet (265,190);
  47.   inv8bullet = new Inv8Bullet (365,190);
  48.   
  49.   //Start Timer at 0sec
  50.   startingTime = millis ();
  51. }

  52. void draw () {
  53.   game ();
  54. }
  55. void game () {
  56.   
  57.   //Variables to randomly fire Invader Bullet
  58.   float t = random (0,400);
  59.   float r = random (0,400);
  60.   
  61.   //Set background to Black
  62.   background (0);
  63.   
  64.   //Clock or Timer
  65.   int m = millis () - startingTime;
  66.   int seconds = m /1000;
  67.   
  68.   //Display information if Game hasn't been Lost
  69.   if (spaceship.GameOver == false); {
  70.     loadFont ("ArialMT-16.vlw");
  71.     fill (255);
  72.     textAlign (LEFT);
  73.     text ("Invaders From Space (c)2011 - Paul Marvell",20,20);
  74.     text ("Time:",935,20);
  75.     text (seconds,970,20);
  76.     text (spaceship.ShipHP,960,580);
  77.   }
  78.   
  79.   //Draw White title underline
  80.   stroke (255);
  81.   line (0,30,width+1,30);
  82.   
  83.   //Draw Shields
  84.   noStroke ();
  85.   fill (0,255,0);
  86.   rectMode (CENTER);
  87.   rect (140,500,width/10,height/20);
  88.   rect (380,500,width/10,height/20);
  89.   rect (620,500,width/10,height/20);
  90.   rect (860,500,width/10,height/20);
  91.   
  92.   //Display Spaceship
  93.   spaceship.display ();
  94.     //GameOver
  95.   if (spaceship.ShipHP <= 0) {
  96.     spaceship.GameOver = true;
  97.   }
  98.   if (spaceship.GameOver = true) {
  99.     spaceship.lose ();
  100.   }
  101.     //Winning Game
  102.   if (spaceship.InvCount <= 0) {
  103.     if (spaceship.ShipHP > 0) {
  104.       spaceship.win ();
  105.     }
  106.   }
  107.   
  108.   //Bullet Displayed and able to Move
  109.   if (spaceship.GameOver == false) {
  110.     bullet.display ();
  111.     bullet.move ();
  112.   }
  113.   
  114.   //Invader Displayed and able to Move
  115.   invader1.display ();
  116.   invader1.move ();
  117.   invader2.display ();
  118.   invader2.move ();
  119.   invader3.display ();
  120.   invader3.move ();
  121.   invader4.display ();
  122.   invader4.move ();
  123.   invader5.display ();
  124.   invader5.move ();
  125.   invader6.display ();
  126.   invader6.move ();
  127.   invader7.display ();
  128.   invader7.move ();
  129.   invader8.display ();
  130.   invader8.move ();
  131.   
  132.   //Invader Bullets
  133.   if (invader1.InvHP > 0) {
  134.     inv1bullet.display ();
  135.     inv1bullet.move ();
  136.     inv1bullet.fire ();
  137.   }
  138.   if (invader2.InvHP > 0) {
  139.     inv2bullet.display ();
  140.     inv2bullet.move ();
  141.     inv2bullet.fire ();
  142.   }
  143.   if (invader3.InvHP > 0) {
  144.     inv3bullet.display ();
  145.     inv3bullet.move ();
  146.     inv3bullet.fire ();
  147.   }
  148.   if (invader4.InvHP > 0) {
  149.     inv4bullet.display ();
  150.     inv4bullet.move ();
  151.     inv4bullet.fire ();
  152.   }
  153.   if (invader5.InvHP > 0) {
  154.     inv5bullet.display ();
  155.     inv5bullet.move ();
  156.     inv5bullet.fire ();
  157.   }
  158.   if (invader6.InvHP > 0) {
  159.     inv6bullet.display ();
  160.     inv6bullet.move ();
  161.     inv6bullet.fire ();
  162.   }
  163.   if (invader7.InvHP > 0) {
  164.     inv7bullet.display ();
  165.     inv7bullet.move ();
  166.     inv7bullet.fire ();
  167.   }
  168.   if (invader8.InvHP > 0) {
  169.     inv8bullet.display ();
  170.     inv8bullet.move ();
  171.     inv8bullet.fire ();
  172.   }
  173.   
  174.   //Bullet hits Invaders - Lose 1HP (destroyed)
  175.   if (invader1.intersect (bullet)) {
  176.     invader1.HP ();
  177.   }
  178.   if (invader2.intersect (bullet)) {
  179.     invader2.HP ();
  180.   }
  181.   if (invader3.intersect (bullet)) {
  182.     invader3.HP ();
  183.   }
  184.   if (invader4.intersect (bullet)) {
  185.     invader4.HP ();
  186.   }
  187.   if (invader5.intersect (bullet)) {
  188.     invader5.HP ();
  189.   }
  190.   if (invader6.intersect (bullet)) {
  191.     invader6.HP ();
  192.   }
  193.   if (invader7.intersect (bullet)) {
  194.     invader7.HP ();
  195.   }
  196.   if (invader8.intersect (bullet)) {
  197.     invader8.HP ();
  198.   }
  199. //Invader Bullet hits Spaceship - Lose 1HP
  200.   if (inv1bullet.intersect (spaceship)) {
  201.     spaceship.HP ();
  202.     inv1bullet.bulletFired = false;
  203.     inv1bullet.bulletHit = true;
  204.   }
  205.   if (inv2bullet.intersect (spaceship)) {
  206.     spaceship.HP ();
  207.     inv2bullet.bulletFired = false;
  208.     inv2bullet.bulletHit = true;
  209.   }
  210.   if (inv3bullet.intersect (spaceship)) {
  211.     spaceship.HP ();
  212.     inv3bullet.bulletFired = false;
  213.     inv3bullet.bulletHit = true;
  214.   }
  215.   if (inv4bullet.intersect (spaceship)) {
  216.     spaceship.HP ();
  217.     inv4bullet.bulletFired = false;
  218.     inv4bullet.bulletHit = true;
  219.   }
  220.   if (inv5bullet.intersect (spaceship)) {
  221.     spaceship.HP ();
  222.     inv5bullet.bulletFired = false;
  223.     inv5bullet.bulletHit = true;
  224.   }
  225.   if (inv6bullet.intersect (spaceship)) {
  226.     spaceship.HP ();
  227.     inv6bullet.bulletFired = false;
  228.     inv6bullet.bulletHit = true;
  229.   }
  230.   if (inv7bullet.intersect (spaceship)) {
  231.     spaceship.HP ();
  232.     inv7bullet.bulletFired = false;
  233.     inv7bullet.bulletHit = true;
  234.   }
  235.   if (inv8bullet.intersect (spaceship)) {
  236.     spaceship.HP ();
  237.     inv8bullet.bulletFired = false;
  238.     inv8bullet.bulletHit = true;
  239.   }
  240. }

  241. //Bullet fired on Mouse Press
  242. void mousePressed () {
  243.   if ((bullet.bulletHit == true) && (bullet.bulletFired == false)); {
  244.     bullet.bulletFired = true;
  245.     bullet.bulletHit = false;
  246.   }
  247. }

  248. //create Invader class
  249. class Invader {
  250.   
  251.   //Invader Variables
  252.   float InvXpos;
  253.   float InvYpos;
  254.   float InvXspd;
  255.   float InvYspd;
  256.   int InvHP;
  257.   float InvXconst;
  258.   float InvXconstRev;
  259.   int lastMillis = 0;
  260.   boolean InvGameOver = false;
  261.   boolean InvDead = false;
  262.   float InvBulletX;
  263.   float InvBulletY;
  264.   int InvBulletLength = 10;
  265.   int InvBulletSpd = 40;
  266.   
  267.   //Invader Constructor
  268.   Invader (float _xpos,float _ypos) {
  269.     InvXpos = _xpos;
  270.     InvYpos = _ypos;
  271.     InvHP = 1;
  272.     InvXspd = 4;
  273.     InvXconst = _xpos +120; //change 65 to see difference
  274.     InvXconstRev = _xpos -120; //think its to stop InvBullets going too far in X direction
  275.   }
  276.   
  277.   //Invader
  278.   void display () {
  279.     if (InvHP > 0) {
  280.       fill (0,0,255);
  281.       noStroke ();
  282.       smooth ();
  283.       ellipse (InvXpos,InvYpos,50,50);
  284.     }
  285.   }
  286.   
  287.   //Invader hit by Bullet
  288.   boolean intersect (bullet a) {
  289.     float distance = dist (InvXpos,InvYpos,bullet.bulletX,bullet.bulletY-bullet.bulletLength /2);
  290.     if (distance < 10) {
  291.       return true;
  292.     } else {
  293.       return false;
  294.     }
  295.   }
  296.   void HP () {
  297.     if (InvHP > 0) {
  298.       InvHP = InvHP -1;
  299.       spaceship.InvCount = spaceship.InvCount -1;
  300.       bullet.bulletFired = false;
  301.       bullet.bulletHit = true;
  302.     } else {
  303.       InvDead = true;
  304.     }
  305.   }
  306.   
  307.   //Invader Movement - side to side and then move down
  308.   void move () {
  309.     if (spaceship.GameOver == false) {
  310.       InvXpos = InvXpos + InvXspd;
  311.       if (InvXpos > InvXconst) InvXspd = InvXspd *-1;
  312.       if (InvXpos < InvXconstRev) InvXspd = InvXspd *-1;
  313.       if (millis () > lastMillis + 20000) {
  314.         lastMillis = millis ();
  315.         InvYpos = InvYpos +50;
  316.         InvXspd = InvXspd *1.25;
  317.       }
  318.     }
  319.     
  320.     //When Invaders reach Shields, Game Over
  321.     if (InvYpos > 475) spaceship.GameOver = true;
  322.   }
  323. }

  324. //create Invader Bullet 1 class
  325. class Inv1Bullet {
  326.   
  327.   //Invader Bullet Variables
  328.   float InvBulletX;
  329.   float InvBulletY;
  330.   int InvBulletLength = 10;
  331.   int InvBulletSpd = 40;
  332.   float InvBulletXspd;
  333.   float InvBulletYspd;
  334.   float InvBulletXconst;
  335.   float InvBulletXconstRev;
  336.   int lastMillis = 0;
  337.   boolean bulletFired;
  338.   boolean bulletHit;
  339.   float r = random (100,5000);
  340.   
  341.   //Invader 1 Bullet constuctor
  342.   Inv1Bullet (float _xpos, float _ypos) {
  343.     bulletFired = false;
  344.     bulletHit = true;
  345.     InvBulletX = _xpos;
  346.     InvBulletY = _ypos + InvBulletLength/2;
  347.     InvBulletXspd = 2;
  348.     InvBulletXconst = _xpos +50;
  349.     InvBulletXconstRev = _xpos -50;
  350.   }
  351.   
  352.   //Invader 1 Bullet
  353.   void display () {
  354.     if ((spaceship.GameOver == false) && (invader1.InvDead == false)) {
  355.       if (bulletFired == false) {
  356.         InvBulletX = invader1.InvXpos;
  357.         InvBulletY = invader1.InvYpos;
  358.         fill (0,0,255);
  359.       }
  360.       if (bulletFired == true) {
  361.         fill (255,166,0);
  362.       }
  363.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  364.       strokeWeight (3);
  365.     }
  366.   }
  367.   
  368.   //Invader 1 Bullet Hits Spaceship
  369.   boolean intersect (SpaceShip a) {
  370.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  371.     if (distance2 <20){
  372.       return true;
  373.     } else {
  374.       return false;
  375.     }
  376.   }
  377.   
  378.   //Invader 1 Bullet Movement
  379.   void move () {
  380.     if (spaceship.GameOver == false) {
  381.       InvBulletX = InvBulletX + InvBulletXspd;
  382.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  383.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  384.       if (millis () > lastMillis + 20000) {
  385.         lastMillis = millis ();
  386.         InvBulletY = InvBulletY +50;
  387.         InvBulletXspd = InvBulletXspd *1.25;
  388.       }
  389.       if ((bulletHit == true) && (bulletFired == false)); {
  390.         if (millis () > r) {
  391.           lastMillis = millis ();
  392.           bulletFired = true;
  393.           bulletHit = false;
  394.           float t = random (5000,10000);
  395.           r = r+t;
  396.         }
  397.       }
  398.     }
  399.   }
  400.   
  401.   //Invader 1 Bullet Random Firing
  402.   void fire () {
  403.     if (bulletFired == true) {
  404.       InvBulletY = InvBulletY +20;
  405.     }
  406.     if (InvBulletY > height) {
  407.       bulletFired = false;
  408.       bulletHit = true;
  409.     }
  410.     if (InvBulletY > 475) {
  411.       if (InvBulletX > 90) {
  412.         if(InvBulletX < 190) {
  413.           bulletFired = false;
  414.           bulletHit = true;
  415.         }
  416.       }
  417.       if (InvBulletX > 330) {
  418.         if(InvBulletX < 430) {
  419.           bulletFired = false;
  420.           bulletHit = true;
  421.         }
  422.       }
  423.       if (InvBulletX > 570) {
  424.         if(InvBulletX < 670) {
  425.           bulletFired = false;
  426.           bulletHit = true;
  427.         }
  428.       }
  429.       if (InvBulletX > 810) {
  430.         if(InvBulletX < 910) {
  431.           bulletFired = false;
  432.           bulletHit = true;
  433.         }
  434.       }
  435.     }
  436.   }
  437. }

  438. //create SpaceShip class
  439. class SpaceShip {
  440.   
  441.   //Spaceship Variables
  442.   float ShipXpos;
  443.   float ShipYpos;
  444.   int ShipHP;
  445.   int InvCount;
  446.   boolean win = false;
  447.   boolean loose = false;
  448.   boolean GameOver = false;
  449.   boolean Dead = false;
  450.   
  451.   //SpaceShip Constructor
  452.   SpaceShip () {
  453.     ShipHP = 5;
  454.     InvCount = 8;
  455.   }
  456.   
  457.   //Spaceship
  458.   void display () {
  459.     if (ShipHP > 0) {
  460.       fill (255,0,0);
  461.       smooth();
  462.       if (GameOver == false) {
  463.         noStroke ();
  464.         triangle(ShipXpos,ShipYpos-25,ShipXpos-40,ShipYpos,ShipXpos+40,ShipYpos);
  465.         float ShipXpos = constrain (mouseX,40,560);
  466.         float ShipYpos = constrain (mouseY,575,575);
  467.       }
  468.     }
  469.   }
  470.   
  471.   //SpaceShip hit by Invader Bullet
  472.   void HP () {
  473.     if (ShipHP > 0) {
  474.       ShipHP = ShipHP -1;
  475.     }
  476.     if (ShipHP < 1) {
  477.       GameOver = true;
  478.     }
  479.   }
  480.   
  481.   //Game Won
  482.   void win () {
  483.     win = true;
  484.     gameplay = false;
  485.     loadFont ("ArialMT-16.vlw");
  486.     fill (255);
  487.     textAlign (CENTER);
  488.     text ("Well Done, You have Destroyed All Invaders",width/2,height/2);
  489.   }
  490.   
  491.   //Game Lost
  492.   void lose () {
  493.     gameplay = false;
  494.     
  495.     loadFont ("ArialMT-16.vlw");
  496.     fill (255);
  497.     textAlign (CENTER);
  498.     text ("GAME OVER",width/2,width/2);
  499.   }
  500. }
  501. //create bullet class
  502. class bullet {
  503.   
  504.   //bullet variables
  505.   float bulletX;
  506.   float bulletY;
  507.   int bulletSpd;
  508.   boolean bulletFired;
  509.   boolean bulletHit;
  510.   int bulletLength;
  511.   float xpos;
  512.   float ypos;
  513.   
  514.   //bullet constructor
  515.   bullet () {
  516.     bulletFired = false;
  517.     bulletHit = true;
  518.     bulletLength = 10;
  519.     bulletSpd = 0;
  520.   }
  521.   
  522.   //Bullet
  523.   void display () {
  524.     if (spaceship.GameOver == false) {
  525.       line (bulletX,bulletY,bulletX,bulletY-bulletLength);
  526.       fill (255,0,0);
  527.       strokeWeight (3);
  528.       
  529.       if (bulletFired == false) {
  530.         bulletX = constrain (mouseX,40,560);
  531.         bulletY = constrain (mouseY,575,575);
  532.       }
  533.     }
  534.   }
  535.   
  536.   //Bullet Movement
  537.   void move () {
  538.     if (bulletFired == true) {
  539.       bulletY = bulletY -20;
  540.     }
  541.     if (bulletY <= 30) {
  542.       bulletFired = false;
  543.       bulletHit = true;
  544.     }
  545.     if (bulletY < 525){
  546.       if (bulletX > 90) {
  547.         if (bulletX < 190) {
  548.           bulletFired = false;
  549.           bulletHit = true;
  550.         }
  551.       }
  552.       if (bulletX > 330) {
  553.         if (bulletX < 430) {
  554.           bulletFired = false;
  555.           bulletHit = true;
  556.         }
  557.       }
  558.       if (bulletX > 670) {
  559.         if (bulletX < 770) {
  560.           bulletFired = false;
  561.           bulletHit = true;
  562.         }
  563.       }
  564.       if (bulletX > 810) {
  565.         if (bulletX < 910) {
  566.           bulletFired = false;
  567.           bulletHit = true;
  568.         }
  569.       }
  570.     }
  571.   }
  572. }

Replies(3)

Copy code
  1. //create Invader Bullet 1 class
  2. class Inv2Bullet {
  3.   
  4.   //Invader Bullet Variables
  5.   float InvBulletX;
  6.   float InvBulletY;
  7.   int InvBulletLength = 10;
  8.   int InvBulletSpd = 40;
  9.   float InvBulletXspd;
  10.   float InvBulletYspd;
  11.   float InvBulletXconst;
  12.   float InvBulletXconstRev;
  13.   int lastMillis = 0;
  14.   boolean bulletFired;
  15.   boolean bulletHit;
  16.   float r = random (100,5000);
  17.   
  18.   //Invader 2 Bullet constuctor
  19.   Inv2Bullet (float _xpos, float _ypos) {
  20.     bulletFired = false;
  21.     bulletHit = true;
  22.     InvBulletX = _xpos;
  23.     InvBulletY = _ypos + InvBulletLength/2;
  24.     InvBulletXspd = 2;
  25.     InvBulletXconst = _xpos +50;
  26.     InvBulletXconstRev = _xpos -50;
  27.   }
  28.   
  29.   //Invader 2 Bullet
  30.   void display () {
  31.     if ((spaceship.GameOver == false) && (invader1.InvDead == false)) {
  32.       if (bulletFired == false) {
  33.         InvBulletX = invader1.InvXpos;
  34.         InvBulletY = invader1.InvYpos;
  35.         fill (0,0,255);
  36.       }
  37.       if (bulletFired == true) {
  38.         fill (255,166,0);
  39.       }
  40.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  41.       strokeWeight (3);
  42.     }
  43.   }

  44.   //Invader 2 Bullet Hits Spaceship
  45.   boolean intersect (SpaceShip a) {
  46.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  47.     if (distance2 <20){
  48.       return true;
  49.     } else {
  50.       return false;
  51.     }
  52.   }
  53.   
  54.   //Invader 2 Bullet Movement
  55.   void move () {
  56.     if (spaceship.GameOver == false) {
  57.       InvBulletX = InvBulletX + InvBulletXspd;
  58.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  59.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  60.       if (millis () > lastMillis + 20000) {
  61.         lastMillis = millis ();
  62.         InvBulletY = InvBulletY +50;
  63.         InvBulletXspd = InvBulletXspd *1.25;
  64.       }
  65.       if ((bulletHit == true) && (bulletFired == false)); {
  66.         if (millis () > r) {
  67.           lastMillis = millis ();
  68.           bulletFired = true;
  69.           bulletHit = false;
  70.           float t = random (5000,10000);
  71.           r = r+t;
  72.         }
  73.       }
  74.     }
  75.   }
  76.   
  77.   //Invader 2 Bullet Random Firing
  78.   void fire () {
  79.     if (bulletFired == true) {
  80.       InvBulletY = InvBulletY +20;
  81.     }
  82.     if (InvBulletY > height) {
  83.       bulletFired = false;
  84.       bulletHit = true;
  85.     }
  86.     if (InvBulletY > 475) {
  87.       if (InvBulletX > 90) {
  88.         if(InvBulletX < 190) {
  89.           bulletFired = false;
  90.           bulletHit = true;
  91.         }
  92.       }
  93.       if (InvBulletX > 330) {
  94.         if(InvBulletX < 430) {
  95.           bulletFired = false;
  96.           bulletHit = true;
  97.         }
  98.       }
  99.       if (InvBulletX > 570) {
  100.         if(InvBulletX < 670) {
  101.           bulletFired = false;
  102.           bulletHit = true;
  103.         }
  104.       }
  105.       if (InvBulletX > 810) {
  106.         if(InvBulletX < 910) {
  107.           bulletFired = false;
  108.           bulletHit = true;
  109.         }
  110.       }
  111.     }
  112.   }
  113. }

  114. //create Invader Bullet 1 class
  115. class Inv3Bullet {
  116.   
  117.   //Invader Bullet Variables
  118.   float InvBulletX;
  119.   float InvBulletY;
  120.   int InvBulletLength = 10;
  121.   int InvBulletSpd = 40;
  122.   float InvBulletXspd;
  123.   float InvBulletYspd;
  124.   float InvBulletXconst;
  125.   float InvBulletXconstRev;
  126.   int lastMillis = 0;
  127.   boolean bulletFired;
  128.   boolean bulletHit;
  129.   float r = random (100,5000);
  130.   
  131.   //Invader 3 Bullet constuctor
  132.   Inv3Bullet (float _xpos, float _ypos) {
  133.     bulletFired = false;
  134.     bulletHit = true;
  135.     InvBulletX = _xpos;
  136.     InvBulletY = _ypos + InvBulletLength/2;
  137.     InvBulletXspd = 2;
  138.     InvBulletXconst = _xpos +50;
  139.     InvBulletXconstRev = _xpos -50;
  140.   }
  141.   
  142.   //Invader 3 Bullet
  143.   void display () {
  144.     if ((spaceship.GameOver == false) && (invader3.InvDead == false)) {
  145.       if (bulletFired == false) {
  146.         InvBulletX = invader3.InvXpos;
  147.         InvBulletY = invader3.InvYpos;
  148.         fill (0,0,255);
  149.       }
  150.       if (bulletFired == true) {
  151.         fill (255,166,0);
  152.       }
  153.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  154.       strokeWeight (3);
  155.     }
  156.   }
  157.   
  158.   //Invader 3 Bullet Hits Spaceship
  159.   boolean intersect (SpaceShip a) {
  160.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  161.     if (distance2 <20){
  162.       return true;
  163.     } else {
  164.       return false;
  165.     }
  166.   }
  167.   
  168.   //Invader 3 Bullet Movement
  169.   void move () {
  170.     if (spaceship.GameOver == false) {
  171.       InvBulletX = InvBulletX + InvBulletXspd;
  172.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  173.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  174.       if (millis () > lastMillis + 20000) {
  175.         lastMillis = millis ();
  176.         InvBulletY = InvBulletY +50;
  177.         InvBulletXspd = InvBulletXspd *1.25;
  178.       }
  179.       if ((bulletHit == true) && (bulletFired == false)); {
  180.         if (millis () > r) {
  181.           lastMillis = millis ();
  182.           bulletFired = true;
  183.           bulletHit = false;
  184.           float t = random (5000,10000);
  185.           r = r+t;
  186.         }
  187.       }
  188.     }
  189.   }
  190.   
  191.   //Invader 3 Bullet Random Firing
  192.   void fire () {
  193.     if (bulletFired == true) {
  194.       InvBulletY = InvBulletY +20;
  195.     }
  196.     if (InvBulletY > height) {
  197.       bulletFired = false;
  198.       bulletHit = true;
  199.     }
  200.     if (InvBulletY > 475) {
  201.       if (InvBulletX > 90) {
  202.         if(InvBulletX < 190) {
  203.           bulletFired = false;
  204.           bulletHit = true;
  205.         }
  206.       }
  207.       if (InvBulletX > 330) {
  208.         if(InvBulletX < 430) {
  209.           bulletFired = false;
  210.           bulletHit = true;
  211.         }
  212.       }
  213.       if (InvBulletX > 570) {
  214.         if(InvBulletX < 670) {
  215.           bulletFired = false;
  216.           bulletHit = true;
  217.         }
  218.       }
  219.       if (InvBulletX > 810) {
  220.         if(InvBulletX < 910) {
  221.           bulletFired = false;
  222.           bulletHit = true;
  223.         }
  224.       }
  225.     }
  226.   }
  227. }

  228. //create Invader Bullet 1 class
  229. class Inv4Bullet {
  230.   
  231.   //Invader Bullet Variables
  232.   float InvBulletX;
  233.   float InvBulletY;
  234.   int InvBulletLength = 10;
  235.   int InvBulletSpd = 40;
  236.   float InvBulletXspd;
  237.   float InvBulletYspd;
  238.   float InvBulletXconst;
  239.   float InvBulletXconstRev;
  240.   int lastMillis = 0;
  241.   boolean bulletFired;
  242.   boolean bulletHit;
  243.   float r = random (100,5000);
  244.   
  245.   //Invader 4 Bullet constuctor
  246.   Inv4Bullet (float _xpos, float _ypos) {
  247.     bulletFired = false;
  248.     bulletHit = true;
  249.     InvBulletX = _xpos;
  250.     InvBulletY = _ypos + InvBulletLength/2;
  251.     InvBulletXspd = 2;
  252.     InvBulletXconst = _xpos +50;
  253.     InvBulletXconstRev = _xpos -50;
  254.   }
  255.   
  256.   //Invader 4 Bullet
  257.   void display () {
  258.     if ((spaceship.GameOver == false) && (invader4.InvDead == false)) {
  259.       if (bulletFired == false) {
  260.         InvBulletX = invader4.InvXpos;
  261.         InvBulletY = invader4.InvYpos;
  262.         fill (0,0,255);
  263.       }
  264.       if (bulletFired == true) {
  265.         fill (255,166,0);
  266.       }
  267.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  268.       strokeWeight (3);
  269.     }
  270.   }
  271.   
  272.   //Invader 4 Bullet Hits Spaceship
  273.   boolean intersect (SpaceShip a) {
  274.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  275.     if (distance2 <20){
  276.       return true;
  277.     } else {
  278.       return false;
  279.     }
  280.   }
  281.   
  282.   //Invader 4 Bullet Movement
  283.   void move () {
  284.     if (spaceship.GameOver == false) {
  285.       InvBulletX = InvBulletX + InvBulletXspd;
  286.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  287.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  288.       if (millis () > lastMillis + 20000) {
  289.         lastMillis = millis ();
  290.         InvBulletY = InvBulletY +50;
  291.         InvBulletXspd = InvBulletXspd *1.25;
  292.       }
  293.       if ((bulletHit == true) && (bulletFired == false)); {
  294.         if (millis () > r) {
  295.           lastMillis = millis ();
  296.           bulletFired = true;
  297.           bulletHit = false;
  298.           float t = random (5000,10000);
  299.           r = r+t;
  300.         }
  301.       }
  302.     }
  303.   }
  304.   
  305.   //Invader 4 Bullet Random Firing
  306.   void fire () {
  307.     if (bulletFired == true) {
  308.       InvBulletY = InvBulletY +20;
  309.     }
  310.     if (InvBulletY > height) {
  311.       bulletFired = false;
  312.       bulletHit = true;
  313.     }
  314.     if (InvBulletY > 475) {
  315.       if (InvBulletX > 90) {
  316.         if(InvBulletX < 190) {
  317.           bulletFired = false;
  318.           bulletHit = true;
  319.         }
  320.       }
  321.       if (InvBulletX > 330) {
  322.         if(InvBulletX < 430) {
  323.           bulletFired = false;
  324.           bulletHit = true;
  325.         }
  326.       }
  327.       if (InvBulletX > 570) {
  328.         if(InvBulletX < 670) {
  329.           bulletFired = false;
  330.           bulletHit = true;
  331.         }
  332.       }
  333.       if (InvBulletX > 810) {
  334.         if(InvBulletX < 910) {
  335.           bulletFired = false;
  336.           bulletHit = true;
  337.         }
  338.       }
  339.     }
  340.   }
  341. }

  342. //create Invader Bullet 1 class
  343. class Inv5Bullet {
  344.   
  345.   //Invader Bullet Variables
  346.   float InvBulletX;
  347.   float InvBulletY;
  348.   int InvBulletLength = 10;
  349.   int InvBulletSpd = 40;
  350.   float InvBulletXspd;
  351.   float InvBulletYspd;
  352.   float InvBulletXconst;
  353.   float InvBulletXconstRev;
  354.   int lastMillis = 0;
  355.   boolean bulletFired;
  356.   boolean bulletHit;
  357.   float r = random (100,5000);
  358.   
  359.   //Invader 5 Bullet constuctor
  360.   Inv5Bullet (float _xpos, float _ypos) {
  361.     bulletFired = false;
  362.     bulletHit = true;
  363.     InvBulletX = _xpos;
  364.     InvBulletY = _ypos + InvBulletLength/2;
  365.     InvBulletXspd = 2;
  366.     InvBulletXconst = _xpos +50;
  367.     InvBulletXconstRev = _xpos -50;
  368.   }
  369.   
  370.   //Invader 5 Bullet
  371.   void display () {
  372.     if ((spaceship.GameOver == false) && (invader5.InvDead == false)) {
  373.       if (bulletFired == false) {
  374.         InvBulletX = invader5.InvXpos;
  375.         InvBulletY = invader5.InvYpos;
  376.         fill (0,0,255);
  377.       }
  378.       if (bulletFired == true) {
  379.         fill (255,166,0);
  380.       }
  381.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  382.       strokeWeight (3);
  383.     }
  384.   }
  385.   
  386.   //Invader 5 Bullet Hits Spaceship
  387.   boolean intersect (SpaceShip a) {
  388.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  389.     if (distance2 <20){
  390.       return true;
  391.     } else {
  392.       return false;
  393.     }
  394.   }
  395.   
  396.   //Invader 5 Bullet Movement
  397.   void move () {
  398.     if (spaceship.GameOver == false) {
  399.       InvBulletX = InvBulletX + InvBulletXspd;
  400.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  401.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  402.       if (millis () > lastMillis + 20000) {
  403.         lastMillis = millis ();
  404.         InvBulletY = InvBulletY +50;
  405.         InvBulletXspd = InvBulletXspd *1.25;
  406.       }
  407.       if ((bulletHit == true) && (bulletFired == false)); {
  408.         if (millis () > r) {
  409.           lastMillis = millis ();
  410.           bulletFired = true;
  411.           bulletHit = false;
  412.           float t = random (5000,10000);
  413.           r = r+t;
  414.         }
  415.       }
  416.     }
  417.   }
  418.   
  419.   //Invader 5 Bullet Random Firing
  420.   void fire () {
  421.     if (bulletFired == true) {
  422.       InvBulletY = InvBulletY +20;
  423.     }
  424.     if (InvBulletY > height) {
  425.       bulletFired = false;
  426.       bulletHit = true;
  427.     }
  428.     if (InvBulletY > 475) {
  429.       if (InvBulletX > 90) {
  430.         if(InvBulletX < 190) {
  431.           bulletFired = false;
  432.           bulletHit = true;
  433.         }
  434.       }
  435.       if (InvBulletX > 330) {
  436.         if(InvBulletX < 430) {
  437.           bulletFired = false;
  438.           bulletHit = true;
  439.         }
  440.       }
  441.       if (InvBulletX > 570) {
  442.         if(InvBulletX < 670) {
  443.           bulletFired = false;
  444.           bulletHit = true;
  445.         }
  446.       }
  447.       if (InvBulletX > 810) {
  448.         if(InvBulletX < 910) {
  449.           bulletFired = false;
  450.           bulletHit = true;
  451.         }
  452.       }
  453.     }
  454.   }
  455. }

  456. //create Invader Bullet 1 class
  457. class Inv6Bullet {
  458.   
  459.   //Invader Bullet Variables
  460.   float InvBulletX;
  461.   float InvBulletY;
  462.   int InvBulletLength = 10;
  463.   int InvBulletSpd = 40;
  464.   float InvBulletXspd;
  465.   float InvBulletYspd;
  466.   float InvBulletXconst;
  467.   float InvBulletXconstRev;
  468.   int lastMillis = 0;
  469.   boolean bulletFired;
  470.   boolean bulletHit;
  471.   float r = random (100,5000);
  472.   
  473.   //Invader 6 Bullet constuctor
  474.   Inv6Bullet (float _xpos, float _ypos) {
  475.     bulletFired = false;
  476.     bulletHit = true;
  477.     InvBulletX = _xpos;
  478.     InvBulletY = _ypos + InvBulletLength/2;
  479.     InvBulletXspd = 2;
  480.     InvBulletXconst = _xpos +50;
  481.     InvBulletXconstRev = _xpos -50;
  482.   }
  483.   
  484.   //Invader 6 Bullet
  485.   void display () {
  486.     if ((spaceship.GameOver == false) && (invader6.InvDead == false)) {
  487.       if (bulletFired == false) {
  488.         InvBulletX = invader6.InvXpos;
  489.         InvBulletY = invader6.InvYpos;
  490.         fill (0,0,255);
  491.       }
  492.       if (bulletFired == true) {
  493.         fill (255,166,0);
  494.       }
  495.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  496.       strokeWeight (3);
  497.     }
  498.   }
  499.   
  500.   //Invader 6 Bullet Hits Spaceship
  501.   boolean intersect (SpaceShip a) {
  502.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  503.     if (distance2 <20){
  504.       return true;
  505.     } else {
  506.       return false;
  507.     }
  508.   }
  509.   
  510.   //Invader 6 Bullet Movement
  511.   void move () {
  512.     if (spaceship.GameOver == false) {
  513.       InvBulletX = InvBulletX + InvBulletXspd;
  514.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  515.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  516.       if (millis () > lastMillis + 20000) {
  517.         lastMillis = millis ();
  518.         InvBulletY = InvBulletY +50;
  519.         InvBulletXspd = InvBulletXspd *1.25;
  520.       }
  521.       if ((bulletHit == true) && (bulletFired == false)); {
  522.         if (millis () > r) {
  523.           lastMillis = millis ();
  524.           bulletFired = true;
  525.           bulletHit = false;
  526.           float t = random (5000,10000);
  527.           r = r+t;
  528.         }
  529.       }
  530.     }
  531.   }
  532.   
  533.   //Invader 6 Bullet Random Firing
  534.   void fire () {
  535.     if (bulletFired == true) {
  536.       InvBulletY = InvBulletY +20;
  537.     }
  538.     if (InvBulletY > height) {
  539.       bulletFired = false;
  540.       bulletHit = true;
  541.     }
  542.     if (InvBulletY > 475) {
  543.       if (InvBulletX > 90) {
  544.         if(InvBulletX < 190) {
  545.           bulletFired = false;
  546.           bulletHit = true;
  547.         }
  548.       }
  549.       if (InvBulletX > 330) {
  550.         if(InvBulletX < 430) {
  551.           bulletFired = false;
  552.           bulletHit = true;
  553.         }
  554.       }
  555.       if (InvBulletX > 570) {
  556.         if(InvBulletX < 670) {
  557.           bulletFired = false;
  558.           bulletHit = true;
  559.         }
  560.       }
  561.       if (InvBulletX > 810) {
  562.         if(InvBulletX < 910) {
  563.           bulletFired = false;
  564.           bulletHit = true;
  565.         }
  566.       }
  567.     }
  568.   }
  569. }

  570. //create Invader Bullet 1 class
  571. class Inv7Bullet {
  572.   
  573.   //Invader Bullet Variables
  574.   float InvBulletX;
  575.   float InvBulletY;
  576.   int InvBulletLength = 10;
  577.   int InvBulletSpd = 40;
  578.   float InvBulletXspd;
  579.   float InvBulletYspd;
  580.   float InvBulletXconst;
  581.   float InvBulletXconstRev;
  582.   int lastMillis = 0;
  583.   boolean bulletFired;
  584.   boolean bulletHit;
  585.   float r = random (100,5000);
  586.   
  587.   //Invader 7 Bullet constuctor
  588.   Inv7Bullet (float _xpos, float _ypos) {
  589.     bulletFired = false;
  590.     bulletHit = true;
  591.     InvBulletX = _xpos;
  592.     InvBulletY = _ypos + InvBulletLength/2;
  593.     InvBulletXspd = 2;
  594.     InvBulletXconst = _xpos +50;
  595.     InvBulletXconstRev = _xpos -50;
  596.   }
  597.   
  598.   //Invader 7 Bullet
  599.   void display () {
  600.     if ((spaceship.GameOver == false) && (invader7.InvDead == false)) {
  601.       if (bulletFired == false) {
  602.         InvBulletX = invader7.InvXpos;
  603.         InvBulletY = invader7.InvYpos;
  604.         fill (0,0,255);
  605.       }
  606.       if (bulletFired == true) {
  607.         fill (255,166,0);
  608.       }
  609.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  610.       strokeWeight (3);
  611.     }
  612.   }
  613.   
  614.   //Invader 7 Bullet Hits Spaceship
  615.   boolean intersect (SpaceShip a) {
  616.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  617.     if (distance2 <20){
  618.       return true;
  619.     } else {
  620.       return false;
  621.     }
  622.   }
  623.   
  624.   //Invader 7 Bullet Movement
  625.   void move () {
  626.     if (spaceship.GameOver == false) {
  627.       InvBulletX = InvBulletX + InvBulletXspd;
  628.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  629.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  630.       if (millis () > lastMillis + 20000) {
  631.         lastMillis = millis ();
  632.         InvBulletY = InvBulletY +50;
  633.         InvBulletXspd = InvBulletXspd *1.25;
  634.       }
  635.       if ((bulletHit == true) && (bulletFired == false)); {
  636.         if (millis () > r) {
  637.           lastMillis = millis ();
  638.           bulletFired = true;
  639.           bulletHit = false;
  640.           float t = random (5000,10000);
  641.           r = r+t;
  642.         }
  643.       }
  644.     }
  645.   }
  646.   
  647.   //Invader 7 Bullet Random Firing
  648.   void fire () {
  649.     if (bulletFired == true) {
  650.       InvBulletY = InvBulletY +20;
  651.     }
  652.     if (InvBulletY > height) {
  653.       bulletFired = false;
  654.       bulletHit = true;
  655.     }
  656.     if (InvBulletY > 475) {
  657.       if (InvBulletX > 90) {
  658.         if(InvBulletX < 190) {
  659.           bulletFired = false;
  660.           bulletHit = true;
  661.         }
  662.       }
  663.       if (InvBulletX > 330) {
  664.         if(InvBulletX < 430) {
  665.           bulletFired = false;
  666.           bulletHit = true;
  667.         }
  668.       }
  669.       if (InvBulletX > 570) {
  670.         if(InvBulletX < 670) {
  671.           bulletFired = false;
  672.           bulletHit = true;
  673.         }
  674.       }
  675.       if (InvBulletX > 810) {
  676.         if(InvBulletX < 910) {
  677.           bulletFired = false;
  678.           bulletHit = true;
  679.         }
  680.       }
  681.     }
  682.   }
  683. }
  684. //create Invader Bullet 1 class
  685. class Inv8Bullet {
  686.   
  687.   //Invader Bullet Variables
  688.   float InvBulletX;
  689.   float InvBulletY;
  690.   int InvBulletLength = 10;
  691.   int InvBulletSpd = 40;
  692.   float InvBulletXspd;
  693.   float InvBulletYspd;
  694.   float InvBulletXconst;
  695.   float InvBulletXconstRev;
  696.   int lastMillis = 0;
  697.   boolean bulletFired;
  698.   boolean bulletHit;
  699.   float r = random (100,5000);
  700.   
  701.   //Invader 8 Bullet constuctor
  702.   Inv8Bullet (float _xpos, float _ypos) {
  703.     bulletFired = false;
  704.     bulletHit = true;
  705.     InvBulletX = _xpos;
  706.     InvBulletY = _ypos + InvBulletLength/2;
  707.     InvBulletXspd = 2;
  708.     InvBulletXconst = _xpos +50;
  709.     InvBulletXconstRev = _xpos -50;
  710.   }
  711.   
  712.   //Invader 8 Bullet
  713.   void display () {
  714.     if ((spaceship.GameOver == false) && (invader8.InvDead == false)) {
  715.       if (bulletFired == false) {
  716.         InvBulletX = invader8.InvXpos;
  717.         InvBulletY = invader8.InvYpos;
  718.         fill (0,0,255);
  719.       }
  720.       if (bulletFired == true) {
  721.         fill (255,166,0);
  722.       }
  723.       line (InvBulletX,InvBulletY,InvBulletX,InvBulletY + InvBulletLength);
  724.       strokeWeight (3);
  725.     }
  726.   }
  727.   
  728.   //Invader 8 Bullet Hits Spaceship
  729.   boolean intersect (SpaceShip a) {
  730.     float distance2 = dist (constrain (mouseX,40,560),constrain (mouseY,575,575),InvBulletX,InvBulletY);
  731.     if (distance2 <20){
  732.       return true;
  733.     } else {
  734.       return false;
  735.     }
  736.   }
  737.   
  738.   //Invader 8 Bullet Movement
  739.   void move () {
  740.     if (spaceship.GameOver == false) {
  741.       InvBulletX = InvBulletX + InvBulletXspd;
  742.       if (InvBulletX > InvBulletXconst) InvBulletXspd = InvBulletXspd *-1;
  743.       if (InvBulletX < InvBulletXconstRev) InvBulletXspd = InvBulletXspd *-1;
  744.       if (millis () > lastMillis + 20000) {
  745.         lastMillis = millis ();
  746.         InvBulletY = InvBulletY +50;
  747.         InvBulletXspd = InvBulletXspd *1.25;
  748.       }
  749.       if ((bulletHit == true) && (bulletFired == false)); {
  750.         if (millis () > r) {
  751.           lastMillis = millis ();
  752.           bulletFired = true;
  753.           bulletHit = false;
  754.           float t = random (5000,10000);
  755.           r = r+t;
  756.         }
  757.       }
  758.     }
  759.   }
  760.   
  761.   //Invader 8 Bullet Random Firing
  762.   void fire () {
  763.     if (bulletFired == true) {
  764.       InvBulletY = InvBulletY +20;
  765.     }
  766.     if (InvBulletY > height) {
  767.       bulletFired = false;
  768.       bulletHit = true;
  769.     }
  770.     if (InvBulletY > 475) {
  771.       if (InvBulletX > 90) {
  772.         if(InvBulletX < 190) {
  773.           bulletFired = false;
  774.           bulletHit = true;
  775.         }
  776.       }
  777.       if (InvBulletX > 330) {
  778.         if(InvBulletX < 430) {
  779.           bulletFired = false;
  780.           bulletHit = true;
  781.         }
  782.       }
  783.       if (InvBulletX > 570) {
  784.         if(InvBulletX < 670) {
  785.           bulletFired = false;
  786.           bulletHit = true;
  787.         }
  788.       }
  789.       if (InvBulletX > 810) {
  790.         if(InvBulletX < 910) {
  791.           bulletFired = false;
  792.           bulletHit = true;
  793.         }
  794.       }
  795.     }
  796.   }
  797. }
Strange... You use classes but ignore the usage of arrays. And what is the point of making duplicates of a class? It is negation of the principles of OO programming, and the DRY (don't repeat yourself) rule.
By addressing these issues, you might have a more manageable code, and errors might be easier to catch (honestly, I don't feel like analyzing such code...).
The code that I offered in this thread cleaned it up a bit.. http://forum.processing.org/topic/expecting-eof-found-class
Not sure where the two meet though..