Get a picture to display for 1000 milliseconds
              in 
             Programming Questions 
              •  
              2 years ago    
            
 
           
             I'm making a game and would like the picture of "character" exploding to show on the screen for 1 second. So I created a separate function for explosion. Right now, there is an error with "wait", and I'm not sure how to fix it. Any help would be appreciated.
             
            
            
             PFont fontA;
            
            
             PImage astroid;
            
            
             PImage ship;
            
            
             PImage GameOver;
            
            
             PImage stars;
            
            
             PImage explosion;
            
            
             boolean shoot = false;
            
            
             boolean characterDeadUpdating = false;
            
            
             int tDeath = (millis());
            
            
             int p;
            
            
             int randx()
            
            
             {
            
            
               return int(random(600));
            
            
             }
            
            
             int[] sphereXCoords = { 
            
            
               randx(), randx(), randx(), randx(), randx()
            
            
               };
            
            
             int[] sphereYCoords = { 
            
            
               0, 0, 0, 0, 0
            
            
             };
            
            
             void setup()
            
            
             {
            
            
               size(600, 620);
            
            
               astroid = loadImage("character.png");
            
            
               ship = loadImage("x-wing.png");
            
            
               GameOver= loadImage("Game_Over_Screen.png");
            
            
               stars = loadImage ("stars.png");
            
            
               explosion = loadImage ("characterScared.png");
            
            
             }
            
            
             void draw()
            
            
             {
            
            
               background(stars);
            
            
               fill(color(0, 255, 0));
            
            
               stroke(color(0, 0, 0));
            
            
               triangle( mouseX-8, 580, mouseX+8, 580, mouseX, 565);
            
            
               fill(color(0, 0, 255));
            
            
               stroke(color(0, 0, 255));
            
            
               if (shoot==true)
            
            
               {
            
            
                 sphereKiller(mouseX);
            
            
                 shoot = false;
            
            
               }
            
            
               sphereDropper();
            
            
               gameEnder();
            
            
             }
            
            
             void mousePressed()
            
            
             {
            
            
               shoot = true;
            
            
             }
            
            
             void sphereDropper()
            
            
             {  
            
            
               stroke(255);
            
            
               for (int i=0; i<5; i++)
            
            
               {
            
            
                 /*
            
            
                 ellipse(sphereXCoords[i], sphereYCoords[i]++, 
            
            
                  sphereDiameter, sphereDiameter);
            
            
                  */
            
            
                 image(astroid, sphereXCoords[i], sphereYCoords[i]++, 80, 90);
            
            
               }
            
            
             }
            
            
             void sphereKiller(int shotX)
            
            
             {
            
            
               boolean hit = false;
            
            
               for (int i = 0; i < 5; i++)
            
            
               {
            
            
                 if ((shotX >= (sphereXCoords[i]-90/2)) && 
            
            
                   (shotX <= (sphereXCoords[i]+90/2)))
            
            
                 {
            
            
                   hit = true;
            
            
                   line(mouseX, 565, mouseX, sphereYCoords[i]);
            
            
                   characterDeadUpdating = true;
            
            
                   tDeath = millis();
            
            
                   explosion(tDeath);
            
            
                   i = p;
            
            
                 }
            
            
                 else
            
            
                   characterDeadUpdating = false;
            
            
               }
            
            
             }
            
            
             void explosion(int tDeath)
            
            
             {
            
            
               if (characterDeadUpdating == true && (System.currentTimeMillis() - tDeath < 1000) );
            
            
               {
            
            
                 image(explosion, sphereXCoords[p], sphereYCoords[p], 
            
            
                 80, 90);
            
            
                 sphereXCoords[p] = randx();
            
            
                 sphereYCoords[p] = 0;
            
            
                 wait(1000);
            
            
                 return;
            
            
               }
            
            
               if (characterDeadUpdating == false)
            
            
               {
            
            
                 line(mouseX, 565, mouseX, 0);
            
            
               }
            
            
             }
            
            
             void gameEnder()
            
            
             {
            
            
               for (int i=0; i< 5; i++)
            
            
               {
            
            
                 if (sphereYCoords[i]==600)
            
            
                 {
            
            
                   fill(color(255, 0, 0));
            
            
                   background(GameOver);
            
            
                   noLoop();
            
            
                 }
            
            
               }
            
            
             }
            
             
              
              1  
            
 
            