java - Restarting millis in processing error -


having massive problem piece of code. i'm working java in processing.

i've created game users must guide character away objects.

all objects, health system , score system based on mills().

once game ends need reset millis(), resetting objects, score , health system.

i have searched implemented advice friends , asked questions on here advice differs slightly. i'm assuming it's can't see.

i appreciate this, ever use site last resort not when i'm feeling lazy.

//these used set times games increases difficulty  //int timedelay = 30000;   int delayone = 2000; int delaytwo = 5000; int delaythree = 80000; int delayfour = 90000; int display = 2000;  //for collisions float[] xpos = new float[6]; float[] ypos = new float[6];   //timer counts how many millis() each game lasts  int timestamp = 5000; int timer; int timer2 = millis() - timer; //always @ 0    //outputting score @ end of game int score; int start;    //trying lives working boolean lost = false;  //variable store & output gale force when giving score  int gale = 0;  //changing length rectangle float rx = 350.0;  float x1 = 20; float y1 = 20; float w1 = 100; float h1 = 30;  //declare objects jelly class jelly myobject; jelly myobject1; jelly myobject2; jelly myobject3;  //gentleman class gentleman mygentleman;  //lolly class lolly mycow; lolly mycow1;  //pimages pimage loader; pimage bg; pimage uh; pimage bg1; pimage bolt; pimage over;   void setup() {             bg=loadimage("backy1.png");             bg1 = loadimage("backy.png");             on = loadimage("over.png");                pfont l = loadfont("lobster1.3-48.vlw");             textfont( l, 16);              size(400, 600);             smooth();             //begin = millis();              imagemode(center);              //initialise             myobject = new jelly(320, 500);             myobject1 = new jelly(150, 200);            // myobject2 = new jelly(550, 500);             //myobject3 = new jelly(300, 100);              mygentleman = new gentleman(200, 300);             //myobject.run();             //myobject1.run();             //myobject2.run();              mycow = new lolly(400, 250);             mycow1 = new lolly(150, 350);              timer = millis(); }  void draw() {        start = 0;      //because have image mode set center collisions      //we have divide height & width of screen 2 hte image fit     image(bg, 200, 300);       if (millis() >= start + delayone)      {        image(bg1, 200, 300);      }       //call functionality       myobject.run();       myobject.put_in_array(0);       myobject1.run(); // 1 going top bottom       myobject1.put_in_array(1);      // myobject2.run();       //myobject2.put_in_array(2);      // myobject3.run();       //myobject3.put_in_array(3);        mycow.run();       mycow.put_in_array(4);       mycow1.run();       mycow1.put_in_array(5);         mygentleman.run();          //health bar       fill(161, 221, 16);       nostroke();       rect(10, 24, rx, 10);         if(rx <= 100)       {         fill(221, 59, 16);         rect(10, 24, rx, 10);       }        else        if(rx <= 200)       {         fill(221, 137, 16);         rect(10, 24, rx, 10);       }         if(rx == 5.0)       {          lost = true;          noloop();          // lives = lives - 1;          image(over, width/2, height/3);          fill(255);          text("your score is: " + timer, width/2.7, height/2);          text("gale force is; " + gale, width/2.7, height/1.8);          score = timer;       }      //for loop detecting collisions between mygentleman & objects       (int i=0; < 6; i++) {          if (xpos[i] > 150 && xpos[i] < 250 && ypos[i] > (mygentleman.y-58) && ypos[i] < (mygentleman.y+58))         {          // text("collision", 200, 300);           bolt = loadimage("bolt.png");           image(bolt, xpos[i], ypos[i]);            rx = rx - 1;          }          //outputting score on screen @ @ times         fill(255);         text("score: " + timer, 320, 20);       }        //timer score counter       timer = millis();       //text(timer, 20, 20);      //moving man screen if button pressed, if not levitates downward        if (keypressed)       {         mygentleman.y -= mygentleman.movey;          mygentleman.movey += 0.4;       }       else       {         mygentleman.y += mygentleman.movey;          mygentleman.movey += 0.2;       }        fill(255);       text("health", 20, 20);    if(mousepressed)   {   if(timer2 > timestamp)   {   println("tit");   mygentleman.y = height/2;   loop();   }    }      }  //class first objects move screen  class jelly {                     //global variables                     float x = 0;                     float y = 0;                     float speedx = 1.8;                     float speedy = 1.8;                     float speedx2 = 2.1;                     float speedy2 = 2.1;                     float speedx3 = 2.2;                     float speedy3 = 2.2;                     pimage jelly = loadimage("jelly.png");                     pimage hat = loadimage("hat.png");                     pimage gale = loadimage("g1.png");                     pimage force = loadimage("force.png");                     pimage news = loadimage("news.png");                        //constructor                     jelly(float _x, float _y)                     {                       x = _x;                       y = _y;                     }                       //functions                     void run()                     {                       display();                       move();                       bounce();                       image(force, 330, 550);                          if (millis() >= start + delayone)                       {                         display();                         movefast();                         bouncefast();                         image(gale, 280, 560);                         gale = 1;                          if (start + delayone + display >= millis())                         {                         image(news, 200, 300);                         }                       }                        if (millis() >= start +delaytwo)                       {                         display();                         movefaster();                         bouncefaster();                         image(gale, 310, 560);                         gale = 2;                           if (start + delaytwo + display >= millis())                         {                         image(news, 200, 300);                         }                         }                       }                        void bounce()                       {                         if ( x > width)                          {                           speedx = speedx * -1; //multiply -1 make bounce                         }                          if ( x < 0)                         {                           speedx = speedx * -1;                         }                          if ( y > height)                         {                           speedy = speedy * -1;                         }                          if ( y < 0)                         {                           speedy = speedy * -1;                         }                       }                        void bouncefast()                       {                         if ( x > width)                          {                           speedx2 = speedx2 * -1; //multiply -1 make bounce                         }                          if ( x < 0)                         {                           speedx2 = speedx2 * -1;                         }                          if ( y > height)                         {                           speedy2 = speedy2 * -1;                         }                          if ( y < 0)                         {                           speedy2 = speedy2 * -1;                         }                       }                        void bouncefaster()                       {                         if ( x > width)                          {                           speedx3 = speedx3 * -1; //multiply -1 make bounce                         }                          if ( x < 0)                         {                           speedx3 = speedx3 * -1;                         }                          if ( y > height)                         {                           speedy3 = speedy3 * -1;                         }                          if ( y < 0)                         {                           speedy3 = speedy3 * -1;                         }                       }                          void move()                       {                         x = x + speedx;                         y = y + speedy;                       }                        void movefast()                       {                         x = x + speedx2;                         y = y + speedy2;                       }                        void movefaster()                       {                         x = x + speedx3;                         y = y + speedy3;                       }                        void put_in_array(int a)                       {                          xpos[a] = x;                         ypos[a] = y;                       }                          void display()                       {                         image(hat, x, y);                       } }   //class gentleman floats   class gentleman {   //global variables   float y = 400;   float x = 400;   float movey;   //pimage umbrella;   pimage umbrella = loadimage("dafuq.png");   pimage on = loadimage("over.png");      //constrcutor --- pieces of info provde build class -- intiialize varibale   gentleman(float _x, float _y)   {     y = _y;     x = _x;     movey = 2;   }    //functions   void run()   {     display();     keyreleased();     bounce();     // collision();   }     void display()    {      image(umbrella, x, y);   }     void keyreleased()   {      mygentleman.movey    = 4;   }    void bounce()   {     if ( y < 0)     {       y = 0;     }        if (y > height)   {      //score = millis();      lost = true;      noloop();     // lives = lives - 1;      image(over, width/2, height/3);      text("your score is: " + timer, width/2.7, height/2);      text("gale force is; " + gale, width/2.7, height/1.8);      }    } }  class lolly {   //global variables   float x = 0;   float y = 0;   float speedx = 2;   float speedy = 2;   float speedx1 = 2.1;   float speedy1 = 2.1;   float speedx2 = 2.3;   float speedy2 = 2.3;   pimage cow = loadimage("cow.png");      //constructor   lolly(float _x, float _y)   {     x = _x;     y = _y;   }     //functions   void run()   {       // display();     //move();     //bounce();      if (millis() >= start + delaythree)     {       display();       movefast();       bouncefast();     }      if (millis() >= start +delayfour)     {       display();       movefaster();       bouncefaster();     }   }    void put_in_array(int a)   {      xpos[a] = x;     ypos[a] = y;   }       void bounce()   {     if ( x > width)      {       speedx = speedx * -1; //multiply -1 make bounce     }      if ( x < 0)     {       speedx = speedx * -1;     }      if ( y > height)     {       speedy = speedy * -1;     }      if ( y < 0)     {       speedy = speedy * -1;     }   }    void bouncefast()   {     if ( x > width)      {       speedx1 = speedx1 * -1; //multiply -1 make bounce     }      if ( x < 0)     {       speedx1 = speedx1 * -1;     }      if ( y > height)     {       speedy1 = speedy1 * -1;     }      if ( y < 0)     {       speedy1 = speedy1 * -1;     }   }    void bouncefaster()   {     if ( x > width)      {       speedx2 = speedx2 * -1; //multiply -1 make bounce     }      if ( x < 0)     {       speedx2 = speedx2 * -1;     }      if ( y > height)     {       speedy2 = speedy2 * -1;     }      if ( y < 0)     {       speedy2 = speedy2 * -1;     }   }      void move()   {     x = x + speedx;     y = y + speedy;   }    void movefast()   {     x = x + speedx1;     y = y + speedy1;   }    void movefaster()   {     x = x + speedx2;     y = y + speedy2;   }     void display()   {     image(cow, x, y);   } }//end of cow class      void mousepressed()    {      } 

your question not @ clear, sounds should able wrap system.currenttimemillis() in object maintains starting point , returns offset. like

public class millis {     long start;     public millis() { this.reset(); }     public void reset() { this.start = system.currenttimemillis(); }     public long getmillis() { return system.currenttimemillis() - start; } } 

you create instance of class @ startup

millis timer = new millis(); 

then call reset() set 0 @ beginning of each game. everywhere in code have millis() have timer.getmillis()


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -