2022年1月17日 星期一

期末作業完成week14

 期末作業完成:






Youtube連結:電流急急棒 - YouTube

程式碼:

PImage ball,maze,gem;

int[] rangeX = {0,125};

int[] rangeY = {480,235};


int ballposX = 30,ballposY = 215;

int offsetX = 0,offsetY = 0;


boolean is_over = false;

boolean is_win = false;


void setup()

{

  size(640,480);

  maze=loadImage("maze.png");

  ball=loadImage("ball.png");

  gem=loadImage("gem.png");

}

void draw()

{

  

  

  background(255);

  imageMode(CENTER); 

  image(maze,320,240);

  image(gem,590,415);

  image(ball,ballposX,ballposY);

  

  if(is_over && !is_win)

  {

    GameOver();

  }

  

  if(is_win)

  {

    Win();

  }

}


void mousePressed()

{

  offsetX = ballposX - mouseX;

  offsetY = ballposY - mouseY;

}


void mouseDragged()

{

  if(!is_over)

  {

    ballposX = offsetX + mouseX;

    ballposY = offsetY + mouseY;

  }

  

  detCollision();

  


}


void GameOver()

{

  textAlign(CENTER);

  textSize(100);

  fill(0);

  text("Game Over",320,240);

}


void Win()

{

  textAlign(CENTER);

  textSize(100);

  fill(0);

  text("Victory",320,240);

}


void detCollision()

{

   //左下

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY-13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY-13 > 235)

  {

    is_over = true;

  }

  

  //左上

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY-13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY-13 < 195)

  {

    is_over = true;

  }

  

  //右上

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY+13 < 395)

  {

    is_over = true;

  }

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  if(ballposX-13 > 515 && ballposX-13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  

  //中上

  if(ballposX+13 > 125 && ballposX+13 < 515 && ballposY-13 < 45)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 515 && ballposY-13 < 45)

  {

    is_over = true;

  }

  

  //中下

  if(ballposX+13 > 125 && ballposX+13 < 640 && ballposY+13 > 435)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 640 && ballposY-13 > 435)

  {

    is_over = true;

  }

  

  //左下2

  if(ballposX+13 > 125 && ballposX+13 < 275 && ballposY+13 > 285)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 275 && ballposY+13 > 285)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 275 && ballposY-13 > 285)

  {

    is_over = true;

  }

  

  //右下2

  if(ballposX+13 > 275 && ballposX+13 < 475 && ballposY+13 > 385)

  {

    is_over = true;

  }

  if(ballposX-13 > 275 && ballposX-13 < 475 && ballposY+13 > 385)

  {

    is_over = true;

  }

  if(ballposX-13 > 275 && ballposX-13 < 475 && ballposY-13 > 385)

  {

    is_over = true;

  }

  

  //右下2上面的

  if(ballposX+13 > 416 && ballposX+13 < 475 && ballposY-13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 416 && ballposX+13 < 475 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX-13 > 416 && ballposX-13 < 475 && ballposY+13 > 235)

  {

    is_over = true;

  }

  

  //中間

  if(ballposX+13 > 165 && ballposX+13 < 376 && ballposY-13 > 85 && ballposY-13 < 245)

  {

    is_over = true;

  }

  if(ballposX+13 > 165 && ballposX+13 < 376 && ballposY+13 > 85 && ballposY+13 < 245)

  {

    is_over = true;

  }

  if(ballposX-13 > 165 && ballposX-13 < 376 && ballposY+13 > 85 && ballposY+13 < 245)

  {

    is_over = true;

  }

  if(ballposX-13 > 165 && ballposX-13 < 376 && ballposY+13 > 85 && ballposY-13 < 245)

  {

    is_over = true;

  }

  

  //中間右

  if(ballposX+13 > 376 && ballposX+13 < 475 && ballposY-13 > 85 && ballposY-13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 376 && ballposX+13 < 475 && ballposY+13 > 85 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 376 && ballposX-13 < 475 && ballposY+13 > 85 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 376 && ballposX-13 < 475 && ballposY+13 > 85 && ballposY-13 < 195)

  {

    is_over = true;

  }

  

  //中間右下

  if(ballposX+13 > 315 && ballposX+13 < 376 && ballposY-13 > 245 && ballposY-13 < 345)

  {

    is_over = true;

  }

  if(ballposX+13 > 315 && ballposX+13 < 376 && ballposY+13 > 245 && ballposY+13 < 345)

  {

    is_over = true;

  }

  if(ballposX-13 > 315 && ballposX-13 < 376 && ballposY+13 > 245 && ballposY+13 < 345)

  {

    is_over = true;

  }

  if(ballposX-13 > 315 && ballposX-13 < 376 && ballposY+13 > 245 && ballposY-13 < 345)

  {

    is_over = true;

  }

  

  //寶石

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  }


沒有留言:

張貼留言