Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在重新启动毫秒处理错误_Java_Processing_Restart - Fatal编程技术网

Java 正在重新启动毫秒处理错误

Java 正在重新启动毫秒处理错误,java,processing,restart,Java,Processing,Restart,这段代码有很大的问题。我在处理方面使用Java 我创建了一个游戏,用户必须引导角色远离对象 所有对象、健康系统和评分系统均基于mills() 游戏结束后,我们需要重置millis(),重置对象、分数和健康系统 我从朋友那里搜索了一些建议,以前也在这里问过一些问题,但这些建议差别很小。我想这是我看不见的东西 我真的很感激你的帮助,我只是把这个网站作为最后的手段,而不是当我感到懒惰的时候 //these are used to set the times which the games increa

这段代码有很大的问题。我在处理方面使用Java

我创建了一个游戏,用户必须引导角色远离对象

所有对象、健康系统和评分系统均基于mills()

游戏结束后,我们需要重置millis(),重置对象、分数和健康系统

我从朋友那里搜索了一些建议,以前也在这里问过一些问题,但这些建议差别很小。我想这是我看不见的东西

我真的很感激你的帮助,我只是把这个网站作为最后的手段,而不是当我感到懒惰的时候

//these are used to set the times which the 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 for 
int timeStamp = 5000;
int timer;
int timer2 = millis() - timer;
//always at zero 


//outputting score at the end of a game
int score;
int start;



//trying to get lives working
boolean lost = false;

//variable to 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");
            over = 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 we have image mode set to center for collisions 
    //we have to divide the height & width of the screen by 2 for hte image to fit
    image(bg, 200, 300);

     if (millis() >= start + delayOne)
     {

      image(bg1, 200, 300);
     }
      //CALL FUNCTIONALITY
      myObject.run();
      myObject.put_in_array(0);
      myObject1.run(); // this one is going top to 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
      for (int i=0; i < 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 @ at all times
        fill(255);
        text("Score: " + timer, 320, 20);
      } 


    //timer which will be score counter essentially
      timer = millis();
      //text(timer, 20, 20);

    //moving the man up the screen if button is pressed, if not he 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 for first objects that move into the 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 by -1 to make it 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 by -1 to make it 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 by -1 to make it 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 for gentleman that floats 

class gentleMan
{
  //GLOBAL VARIABLES
  float y = 400;
  float x = 400;
  float moveY;
  //PImage umbrella;
  PImage umbrella = loadImage("dafuq.png");
  PImage over = loadImage("over.png");



  //CONSTRCUTOR --- PIECES OF INFO PROVDE TO 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 by -1 to make it 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 by -1 to make it 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 by -1 to make it 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()
   {


   }
//这些用于设置游戏增加难度的时间
//int时间延迟=30000;
一等于2000;
int=5000;
整数三=80000;
int delayFour=90000;
整数显示=2000;
//碰撞
float[]xpos=新的float[6];
浮动[]ypos=新浮动[6];
//计时器计算每场比赛持续多长时间
int时间戳=5000;
整数定时器;
int timer2=millis()-定时器;
//始终为零
//在游戏结束时输出分数
智力得分;
int启动;
//努力让生活运转起来
布尔丢失=假;
//评分时存储和输出大风力的变量
int Gale=0;
//变长矩形
浮子rX=350.0;
浮点x1=20;
浮动y1=20;
浮点数w1=100;
浮动h1=30;
//声明对象JELLY类
果冻肌体;
果冻肌对象1;
果冻肌对象2;
果冻肌对象3;
//绅士阶层
绅士我的绅士;
//棒棒糖类
棒棒糖;
棒棒糖;
//皮梅兹
装载机;
皮马杰bg;
皮马杰嗯,;
PImage bg1;
插销螺栓;
皮梅杰结束;
无效设置()
{
bg=loadImage(“backy1.png”);
bg1=loadImage(“backy.png”);
over=loadImage(“over.png”);
PFont L=loadFont(“龙虾1.3-48.vlw”);
文本字体(L,16);
尺寸(400600);
光滑的();
//begin=millis();
图像模式(中心);
//初始化
myObject=新果冻(320500);
myObject1=新果冻(150200);
//myObject2=新果冻(550500);
//myObject3=新果冻(300100);
我的绅士=新绅士(200300);
//myObject.run();
//myObject1.run();
//myObject2.run();
myCow=新棒棒糖(400250);
myCow1=新棒棒糖(150350);
计时器=毫秒();
}
作废提款()
{
开始=0;
//因为我们将“图像模式”设置为“碰撞中心”
//我们必须将屏幕的高度和宽度除以2,这样图像才合适
图像(bg,200300);
如果(毫秒()>=开始+延迟一)
{
图像(BG1200300);
}
//呼叫功能
myObject.run();
myObject.将_放入_数组(0);
myObject1.run();//这个将从上到下
myObject1.将_放入_数组(1);
//myObject2.run();
//myObject2.将_放入_数组(2);
//myObject3.run();
//myObject3.将_放入_数组(3);
myCow.run();
将_放入_数组(4);
myCow1.run();
myCow1.将_放入_数组(5);
我的绅士,快跑;
//健康酒吧
填充(16122116);
仰泳();
rect(10,24,rX,10);
如果(rX(myguester.y-58)和&ypos[i]<(myguester.y+58))
{
//文本(“碰撞”,200300);
螺栓=载荷图像(“bolt.png”);
图像(博尔特、xpos[i]、YPO[i]);
rX=rX-1;
}
//始终在屏幕@上输出分数
填充(255);
文本(“分数:+计时器,320,20);
} 
//基本上是记分计数器的计时器
计时器=毫秒();
//文本(计时器,20,20);
//如果按下按钮,则将该人向上移动屏幕,否则他将向下悬浮
如果(按键)
{
我的绅士.y-=我的绅士.moveY;
MyGenister.moveY+=0.4;
}
其他的
{
mygentlest.y+=mygentlest.moveY;
MyGenister.moveY+=0.2;
}
填充(255);
案文(“健康”,20、20);
如果(鼠标按下)
{
if(timer2>时间戳)
{
println(“tit”);
y=身高/2;
loop();
} 
}
}
//为移动到屏幕中的第一个对象初始化
等级果冻
{
//全局变量
浮动x=0;
浮动y=0;
浮动速度x=1.8;
浮动速度=1.8;
浮动速度x2=2.1;
浮动速度2=2.1;
浮动速度x3=2.2;
浮动速度3=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”);
//建造师
果冻(浮动x,浮动y)
{
x=x;
y=_y;
}
//功能
无效运行()
{
显示();
move();
反弹();
图像(部队,330,550);
如果(毫秒()>=开始+延迟一)
{
显示();
moveFast();
bounceFast();
图像(大风,280,560);
大风=1级;
如果(开始+延迟一次+显示>=millis())
{
图像(新闻,200300);
}
}
如果(毫秒()>=start+delayTwo)
{
显示();
移动得更快();
bounceFaster();
imag
public class Millis
{
    long start;
    public Millis() { this.reset(); }
    public void reset() { this.start = System.currentTimeMillis(); }
    public long getMillis() { return System.currentTimeMillis() - start; }
}
Millis timer = new Millis();
class Timer {



int savedTime; // When Timer started
  int totalTime; // How long Timer should last

  Timer(int tempTotalTime) {
    totalTime = tempTotalTime;
  }

  // Starting the timer
  void start() {
    // When the timer starts it stores the current time in milliseconds.
    savedTime = millis(); 
  }

  // The function isFinished() returns true if 5,000 ms have passed. 
  // The work of the timer is farmed out to this method.


  boolean isFinished() { 
    // Check how much time has passed
    int passedTime = millis()- savedTime;
    if (passedTime > totalTime) {
      return true;
    } else {
      return false;
    }
   }




 }//end class
 firstTimer = new Timer(50000);
if (firstTimer.isFinished()) {
    //do sopemthing
    //then restart timer
    firstTimer.start();
  }
  else
  {
   // do soemthing else for the rest of the time....
  }