顯示具有 Week15 標籤的文章。 顯示所有文章
顯示具有 Week15 標籤的文章。 顯示所有文章

2022年1月17日 星期一

black_Week15

 期末作品(完成)

1.遊戲畫面


2.程式碼

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;

  }

}

3.影片連結

https://youtu.be/7jWZpotG0no

我愛卯咪Week15

 

互動技術概論🎮


期末遊戲Day3(最後的成品啦🎉)

import processing.sound.*;
SoundFile soundfile;//音樂
PImage img,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15,img16,img17;//宣告圖片
int state=0,remainT=0,count=1800,count1=3000,count2=0,count3=0,x=200, y=300,win=0;//點擊的設定
void setup(){
  size(400,600);
  soundfile=new SoundFile(this,"panda.mp3");把音樂放進去
  soundfile.play();
  soundfile.loop();
  img=loadImage("egg.png");
  img1=loadImage("panda1.png");//讀入圖片
                            .
                            .
                            .
  img17=loadImage("panda17.png");
  imageMode(CENTER);
}
void draw(){
  count--;
  count1--;
  if(count==0) {state=1;count1=-1;}//設定點擊事件
  else if(count1==0) {state=3;count=-1;}
  else if(count==900) {state=0;}
  else if(count1==1500) state=2;
  if(win==5) state=10;

  if(count2==0)background(255);
  else background(#D6D4D4);
  //image( img, 0,0);
  image( img ,x,y);
  if(state==0){//餓了
    image( img1 ,x,y);
  }
  if(state==1){//餓死了
    image( img2 ,x,y);
  }
  if(state==2){//玩
    image( img3 ,x,y);
  }
  if(state==3){//無聊死了
    image( img4 ,x,y);
  }
  if(state==4){//吃
    remainT--;
    count3++;
    if(remainT>60){
      image( img5 ,x,y);
    }
    else{
      image( img6 ,x,y);
    }   
  }
  if(state==5){//吃死了
    remainT--;
    if(remainT>60){
      image( img7 ,x,y);
    }
    else{
      image( img8 ,x,y);
    }
  }
  if(state==6){//打球
    count3++;
    remainT--;
    if(remainT>60){
      image( img9 ,x,y);
    }
    else{
      image( img10 ,x,y);
    }
  }
  if(state==7){//吃球
    remainT--;
    if(remainT>60){
      image( img11 ,x,y);
    }
    else{
      image( img12 ,x,y);
    }
  }
  if(state==8){//洗澡
    remainT--;
    if(remainT>60){
      image( img13 ,x,y);
    }
    else{
      image( img14 ,x,y);
    }
  }
  if(state==9){//喝洗澡水
    remainT--;
    if(remainT>60){
      image( img15 ,x,y);
    }
    else{
      image( img16 ,x,y);
    }
  }
  if(state==10){//贏了
    image( img17 ,x,y);
  }
}
void mousePressed(){
  if(mouseX>=90&&mouseX<=160&&mouseX>=90){
    if(mouseY>10*50-25 && mouseY<10*50+50){
      if(count3>0){
        state=5;
        remainT=180;
        count=-1;
        count1=-1;
      }
      else if(state!=4&&state!=1&&state!=3&&state!=5&&state!=7){
        state=4;
        remainT=180;
        count=1800;
        win++;
      }
      else if(state==4){
        state=5;
        remainT=180;
        count=-1;
        count1=-1;
      }
    }
  }
  if(mouseX>=190&&mouseX<=240&&mouseX>=90){
     if(mouseY>10*50-25 && mouseY<10*50+50){
       if(state==0){
         state=7;
         remainT=180;
         count=-1;
         count1=-1;
       }
       else if(state!=1&&state!=3&&state!=5&&state!=7){
         count3++;
         state=6;
         remainT=180;
         count1=3000;
         count2++;
       }
     }
  }
  if(mouseX>=250&&mouseX<=340&&mouseX>=90){
     if(mouseY>10*50-25 && mouseY<10*50+50){
       if(state==0){
         state=9;
         remainT=180;
         count=-1;
         count1=-1;
       }
       else if(state!=1&&state!=3&&state!=5&&state!=7){
         state=8;
         remainT=180;
         count2=0;
         count3=0;
       }
     }
  }
  if(mouseX>0){
     if(mouseY>0 && mouseY<400){
       if(state==1||state==3||state==5||state==7||state==9){
         state=0;
         remainT=0;
         count=1800;
         count1=3000;
         count2=0;
         count3=0;
         x=200;
         y=300;
         win=0;
        }
     }
  }
}

成品

Jain's 互動技術概論筆記#Week15

小朋友下樓梯~終於結束了


import processing.sound.*;

SoundFile soundfile;

SoundFile scare;

PImage imgB;

PImage imgB2;

PImage imgt;

PImage imgp;

PImage imgpl;

PImage imgpr;

float []boardX=new float[9];

float []boardY=new float[9];

float []wallX1=new float[15];

float []wallY1=new float[15];

float []wallX2=new float[15];

float []wallY2=new float[15];

float px;

float py,vx=0, vy=0.2;

float pyn;

int score;

boolean left=false;//左

boolean right=false;//右

int landing=0;

int condition=0;

float rolling=0;

void setup(){

    size(720,540);

    fill(0,0,0);

    textSize(40);

    imgB=loadImage("b1.jpg");

    imgB2=loadImage("b2.png");

    imgt=loadImage("t.png");

    imgp=loadImage("p.png");

    px=random(30,400-40);

    py=random(55,100);

    soundfile=new SoundFile(this,"BGM.mp3");

    scare=new SoundFile(this,"小朋友下樓梯音效.mp3");

    score=0;

    for(int i=0;i<9;i++)

    {

      boardX[i]=random(30,450-14-200);

      boardY[i]=i*45+80;

    }

    for(int i=0;i<15;i++)

    {

      wallX1[i]=0;

      wallY1[i]=i*30+50;

    }

    for(int i=0;i<15;i++)

    {

      wallX2[i]=410;

      wallY2[i]=i*30+50;

    }

  soundfile.play();

  soundfile.loop();

}

void mousePressed() {

  

    if (mouseButton == LEFT&&mouseX>=500&&mouseX<=650&&mouseY>=250&&mouseY<=390){

      condition=1;

        score=0;

    }

   if(condition==1){

    if (mouseButton == LEFT&&mouseX>=500&&mouseX<=650&&mouseY>=400&&mouseY<=490){

      condition=0;

      }

    

  }

}

void keyPressed()

{

  if(keyCode==LEFT)

  { 

    px += -20;

  }

  if(keyCode==RIGHT)

  {

    px += 20; 

  }

}


void draw(){

  if(condition==0){

  background(225);

  rect(10,45,400,450);

  text("PLAY", 500,300);

  text("STOP", 500,400);


  

  }

  else if(condition==1){

    background(225);

    rect(10,45,400,450);

    text("PLAY", 500,300);

    text("STOP", 500,400);

    image(imgp,px-vx,py-vy);

    if(py-vy<495&&py-vy>30) { 

      score+=1;

      text("Score:"+score/60, 450,100);

    }

    else {

      scare.play();

      text("Score:"+score/60+"\n"+"GameOver", 450,100);

      condition=2;

      py=random(55,100);

      }

    for(int i=0;i<15;i++){

      image(imgB,wallX1[i],wallY1[i]-rolling);

      image(imgB,wallX2[i],wallY2[i]-rolling);

      if(wallY1[i]-rolling<45)

      {

        wallY1[i]+=450;

        wallY2[i]+=450;

      }

    }

    for(int i=0;i<9;i++){

      image(imgB2,boardX[i],boardY[i]+80-rolling);

      if(boardY[i]-rolling<0){

        boardX[i]=random(15,400-15-95);

        boardY[i]=boardY[i]+400;

        }  

      py += vy; 

      for(int k=0; k<9; k++)

      {

        if(boardX[k] < px && px < boardX[k]+95)

        {

          if(py<boardY[k]+80-rolling && py>boardY[k]+80-rolling-16)

          {

            landing=k;

            py=boardY[k]-26+80-rolling;

          }

        }

      }

      

    } 

  image(imgt,10,45);

  rolling+=1.1; 

  }

  else if(condition==2){

    background(225);

    rect(10,45,400,450);

    text("PLAY", 500,300);

    text("STOP", 500,400);

    text("Score:"+score/60+"\n"+"GameOver", 450,100);

  }

}

作業完成

 最後完成了作業

import processing.sound.*;

SoundFile soundfile1;

SoundFile soundfile2;

float [] bulletX=new float[99];

float [] bulletY=new float[99];

float [] bulletVX=new float[99];

float [] bulletVY=new float[99];

boolean die =false;

float x1=150,y1=400;

PImage imgBrick;

PImage imgBrick2;

PImage imgBullet;

PImage imgPlayer;

PImage imgBackground;

PImage imgC;

PImage imgGameover;


void setup(){

  size(300,500);

  soundfile1 = new SoundFile(this,"AnyConv.com__Pokemon.aiff");

  soundfile2 = new SoundFile(this,"wind03.aiff");

  soundfile1.play();

  soundfile1.loop();

  soundfile2.stop();

  imgBrick=loadImage("brick.jpg");

  imgBrick2=loadImage("2.jpg");

  imgBullet=loadImage("bullet.png");

  imgPlayer=loadImage("player.png");

  imgBackground=loadImage("111.png");

  imgC=loadImage("blo.jpg");

  imgGameover=loadImage("gameover.png");

  

  for(int i=0; i<99; i++){

    bulletX[i]=random(300); bulletY[i]=0; 

    //bulletX[i] = random(300);

    //bulletY[i] = random(300);

    float angle = random(60,120);//360度

    bulletVX[i] = cos( radians(angle) ); //random(-3,3);//子彈的速度差太多了, 不好

    bulletVY[i] = sin( radians(angle) );//random(-3,3);

  }

}

void draw(){

  image(imgBackground,20,30);

  image(imgC,0,0,300,35);//上面的白條

  for(int i=0;i<30;i++){//兩邊的槓槓

    image(imgBrick,0,0+i*15);

    image(imgBrick2,280,0+i*15);

  }

  for(int i=0; i<30; i++){

    image(imgBullet,bulletX[i], bulletY[i], 8, 8);

    bulletX[i] += bulletVX[i];

    bulletY[i] += bulletVY[i];

    if(bulletX[i]<25 || bulletY[i]<0 || bulletX[i]>275 || bulletY[i]>500){

      //bulletX[i] = random(300);//重新出現的子彈,不應該突然出現

      //bulletY[i] = random(300);//應該是從邊邊冒出來

        bulletX[i]=random(300); bulletY[i]=40; 

      float angle = random(60,120);//360度

      bulletVX[i] = cos( radians(angle) ); //random(-3,3);//子彈的速度差太多了, 不好

      bulletVY[i] = sin( radians(angle) );//random(-3,3);  

    }

    if(dist (x1,y1,bulletX[i],bulletY[i])<6){

        die=true;

    }

   if(die){

     image(imgGameover,0,0,300,500);

     soundfile1.stop();

     }

   else{

     image(imgPlayer,x1,y1,20,30);

     x1=mouseX-10;

     y1=mouseY-15;

   }

  }

}


整個程式花最多時間的地方應該是碰撞的部分

因為一開始講解碰撞的程式在自己嘗試的時候一職失敗

最後問老師的時候才知道了另外一種做法

  if(dist (x1,y1,bulletX[i],bulletY[i])<6)

學到了dist的用法

常闇的程式之路week 17

 我的作品也做得差不多了,這次做的作品是泡泡龍的小遊戲,雖然做了滿久的,但還是有些BUG存在。話不多說直接上程式碼吧ˊˇˋ


import ddf.minim.*;

Minim minim;

AudioPlayer BGM;

AudioPlayer GG;

AudioPlayer Hit;

PFont F;

float bx;//發射球之x座標

float by;//發射球之y座標

float bvx;//發射球之x方向速度

float bvy;//發射球之y方向速度

int bc = 0;//目前發射球之顏色

int []ec = new int [1000];//所有敵人顏色編號資料 *重要資料*

int bnext = 0;//下一顆發射球之顏色

int enemy[];//敵人數量,最多11行

float []ex = new float[1000];//所有敵人的x座標資料 *重要資料*

float []ey = new float[1000];//所有敵人的y座標資料 *重要資料*

//float []nx = new float [4];//發射球黏上敵人陣列後偵測上下左右敵人x座標 *重要資料*

//float []ny = new float [4];//發射球黏上敵人陣列後偵測上下左右敵人y座標 *重要資料*

boolean shoot = false;//觸發子彈發射

boolean appear;//觸發子彈繪製

float nearx = 10000;//距離發射求最近之敵人x座標 *重要資料*

float neary = 10000;//距離發射求最近之敵人y座標 *重要資料*

float near = 10000;//距離發射求最近之敵人歐幾理德距離 *重要資料*

int bulletsize = 50;//發射球之直徑參數 *重要資料*

int r = 50;//所有敵人之直徑參數 *重要資料*

int N = 0;//敵人總數

float []dx = new float[1000];//應該死掉的球x座標

float []dy = new float[1000];//應該死掉的球y座標

float []dc = new float[1000];//應該死掉的顏色標號

void setup(){

  size(550 ,600);

  minim=new Minim(this);

  BGM=minim.loadFile("Video Game Blockbuste.mp3",1024);

  BGM.play();

  BGM.loop();

  F = createFont("18thCentury" ,80);

  for(int i = 0 ;i <= 70 ;i++){

      ec[i] = int(random(1 ,5));//給予所有位址隨機1~5整數以作為上色標準,0為空格

  }

  for(int i = 1 ;i <= 7 ;i++){

    for(int j = 1 ;j <= 10 ;j++){

      N++;

      ex[N-1] = j * r;ey[N-1] = i * r;

    }

  }

  newbullet();

  bnext = int(random(1 ,5));

}


void draw(){

  background(#242DFF);

  fill(#FFB624);rect(100 ,100 ,350 ,350);

  for(int i = 0 ;i < N ;i++){

    if(ec[i] == 1) {fill(#FC8585);ellipse(ex[i] ,ey[i] ,r ,r);}//紅

    if(ec[i] == 2) {fill(#FAFA86);ellipse(ex[i] ,ey[i] ,r ,r);}//黃

    if(ec[i] == 3) {fill(#86FA9C);ellipse(ex[i] ,ey[i] ,r ,r);}//綠

    if(ec[i] == 4) {fill(#8696FA);ellipse(ex[i] ,ey[i] ,r ,r);}//藍

    if(dist(bx ,by ,ex[i] ,ey[i]) < r){

      shoot = false;

      appear = false;

      N++;

      near = (dist(nearx * r ,neary * r ,bx ,by));

      for(int k = 1 ;k <= 10 ;k++){

        for(int l = 1 ;l <= 11 ;l++){

          if(dist(l * r ,k * r ,bx ,by) < near){

            nearx = l;

            neary = k;

            near = dist(nearx * r ,neary * r ,bx ,by);

            ex[N-1] = nearx * r;

            ey[N-1] = neary * r;

            ec[N-1] = bc;

            dx[N-1] = ex[N-1];

            dy[N-1] = ey[N-1];

            dc[N-1] = ec[N-1];

            S_Hit();

            if(ey[N-1] == 10 * r) {gameover();}

          }  

        }

      }

      for(int a = N-2 ;a >= 0 ;a--){

        if(ec[a] == dc[N-1] && dist(dx[N-1] ,dy[N-1] ,ex[a] ,ey[a]) <= 1.4*r){

          println(ex[N-1] ,ey[N-1] ,ec[N-1]);

          //ec[a] = 0;

          ex[N-1] = 1000;

          ey[N-1] = 1000;

          dx[N-1] = ex[a];

          dy[N-1] = ey[a];

          ex[a] = 1000;

          ey[a] = 1000;

        }

      }

      for(int a = 0 ;a <= N-2 ;a++){

        if(ec[a] == dc[N-1] && dist(dx[N-1] ,dy[N-1] ,ex[a] ,ey[a]) <= 1.4*r){

          println(ex[a] ,ey[a] ,ec[a]);

          //ec[a] = 0;

          ex[N-1] = 1000;

          ey[N-1] = 1000;

          dx[N-1] = ex[a];

          dy[N-1] = ey[a];

          //dc[N-1] = ec[a];

          ex[a] = 1000;

          ey[a] = 1000;

        }

      }

      newbullet();

    }

    if(ey[N-1] == 10 * r) {

      gameover();

      appear = false;

      bnext = 0;

      M_Stop();

      break;

    }

  }

  if(bnext == 1) {fill(#FC8585);ellipse(275,575 ,bulletsize ,bulletsize);}

  if(bnext == 2) {fill(#FAFA86);ellipse(275,575 ,bulletsize ,bulletsize);}

  if(bnext == 3) {fill(#86FA9C);ellipse(275,575 ,bulletsize ,bulletsize);}

  if(bnext == 4) {fill(#8696FA);ellipse(275,575 ,bulletsize ,bulletsize);}

  

  if(appear){

    if(bc == 1) {fill(#FC8585);ellipse(bx,by ,bulletsize ,bulletsize);}

    if(bc == 2) {fill(#FAFA86);ellipse(bx,by ,bulletsize ,bulletsize);}

    if(bc == 3) {fill(#86FA9C);ellipse(bx,by ,bulletsize ,bulletsize);}

    if(bc == 4) {fill(#8696FA);ellipse(bx,by ,bulletsize ,bulletsize);}

    if(shoot){

      bx+=bvx;

      by+=bvy;

      if(bx >= width-(bulletsize/2) || bx <= bulletsize/2) {bvx=-(bvx);S_Hit();}

      

      if(by >= height-(bulletsize/2) || by <= bulletsize/2) {bvy=-(bvy);S_Hit();}

    }

  }

}

void newbullet(){

  bx=275;

  by=575;

}


void gameover(){

  background(255);

  fill(0);

  textFont(F);

  text("GAME OVER" ,100 ,300);

  minim=new Minim(this);

  GG=minim.loadFile("Sad Trombone.mp3",1024);

  GG.play();

}


void nextbullet(){

  bnext = int(random(1 ,5));

}

void M_Stop()

{

  BGM.close();

  minim.stop();

  super.stop();

}

void S_Hit(){

  minim=new Minim(this);

  Hit=minim.loadFile("Pop sound effect.mp3",1024);

  Hit.play();

}

void mousePressed(){

  appear=true;

  shoot=true;

  bc = bnext;

  float dx=mouseX-275, dy=mouseY-575;

  float len=sqrt(dx*dx + dy*dy);

  bvx = dx*10/len;

  bvy = dy*10/len;

  nextbullet();

}

這是遊戲的外觀:

大致上就是這樣,雖然該消的球似乎沒辦法每次都完整消光,音樂到後期好像也會有點問題,但遊戲性還是沒啥大問題,我應該還會用點時間把這部分完善,就這樣囉ˊˇˋ




2022年1月16日 星期日

嗨壓阿 Week15

 期末作品

import processing.sound.*;
SoundFile soundfile;
PImage img,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15,img16,img17;
int state=0,remainT=0,count=1800,count1=3000,count2=0,count3=0,x=200, y=300,win=0;
void setup(){
  size(400,600);
  soundfile=new SoundFile(this,"panda.mp3");
  soundfile.play();
  soundfile.loop();
  img=loadImage("egg.png");
  img1=loadImage("panda1.png");
  img2=loadImage("panda2.png");
  img3=loadImage("panda3.png");
  img4=loadImage("panda4.png");
  img5=loadImage("panda5.png");
  img6=loadImage("panda6.png");
  img7=loadImage("panda7.png");
  img8=loadImage("panda8.png");
  img9=loadImage("panda9.png");
  img10=loadImage("panda10.png");
  img11=loadImage("panda11.png");
  img12=loadImage("panda12.png");
  img13=loadImage("panda13.png");
  img14=loadImage("panda14.png");
  img15=loadImage("panda15.png");
  img16=loadImage("panda16.png");
  img17=loadImage("panda17.png");
  imageMode(CENTER);
}
void draw(){
  count--;
  count1--;
  if(count==0) {state=1;count1=-1;}
  else if(count1==0) {state=3;count=-1;}
  else if(count==900) {state=0;}
  else if(count1==1500) state=2;
  if(win==5) state=10;
  if(count2==0)background(255);
  else background(#D6D4D4);
  //image( img, 0,0);
  image( img ,x,y);
  if(state==0){//餓了
    image( img1 ,x,y);
  }
  if(state==1){//餓死了
    image( img2 ,x,y);
  }
  if(state==2){//玩
    image( img3 ,x,y);
  }
  if(state==3){//無聊死了
    image( img4 ,x,y);
  }
  if(state==4){//吃
    remainT--;
    count3++;
    if(remainT>60){
      image( img5 ,x,y);
    }
    else{
      image( img6 ,x,y);
    }   
  }
  if(state==5){//吃死了
    remainT--;
    if(remainT>60){
      image( img7 ,x,y);
    }
    else{
      image( img8 ,x,y);
    }
  }
  if(state==6){//打球
    count3++;
    remainT--;
    if(remainT>60){
      image( img9 ,x,y);
    }
    else{
      image( img10 ,x,y);
    }
  }
  if(state==7){//吃球
    remainT--;
    if(remainT>60){
      image( img11 ,x,y);
    }
    else{
      image( img12 ,x,y);
    }
  }
  if(state==8){//洗澡
    remainT--;
    if(remainT>60){
      image( img13 ,x,y);
    }
    else{
      image( img14 ,x,y);
    }
  }
  if(state==9){//喝洗澡水
    remainT--;
    if(remainT>60){
      image( img15 ,x,y);
    }
    else{
      image( img16 ,x,y);
    }
  }
  if(state==10){//贏了
    image( img17 ,x,y);
  }
}
void mousePressed(){
  if(mouseX>=90&&mouseX<=160&&mouseX>=90){
    if(mouseY>10*50-25 && mouseY<10*50+50){
      if(count3>0){
        state=5;
        remainT=180;
        count=-1;
        count1=-1;
      }
      else if(state!=4&&state!=1&&state!=3&&state!=5&&state!=7){
        state=4;
        remainT=180;
        count=1800;
        win++;
      }
      else if(state==4){
        state=5;
        remainT=180;
        count=-1;
        count1=-1;
      }
    }
  }
  if(mouseX>=190&&mouseX<=240&&mouseX>=90){
     if(mouseY>10*50-25 && mouseY<10*50+50){
       if(state==0){
         state=7;
         remainT=180;
         count=-1;
         count1=-1;
       }
       else if(state!=1&&state!=3&&state!=5&&state!=7){
         count3++;
         state=6;
         remainT=180;
         count1=3000;
         count2++;
       }
     }
  }
  if(mouseX>=250&&mouseX<=340&&mouseX>=90){
     if(mouseY>10*50-25 && mouseY<10*50+50){
       if(state==0){
         state=9;
         remainT=180;
         count=-1;
         count1=-1;
       }
       else if(state!=1&&state!=3&&state!=5&&state!=7){
         state=8;
         remainT=180;
         count2=0;
         count3=0;
       }
     }
  }
  if(mouseX>0){
     if(mouseY>0 && mouseY<400){
       if(state==1||state==3||state==5||state==7||state==9){
         state=0;
         remainT=0;
         count=1800;
         count1=3000;
         count2=0;
         count3=0;
         x=200;
         y=300;
         win=0;
        }
     }
  }
}

攻略
1.餓--餓死
2.餓--吃球--死
3.餓--喝水--死

1.餓--吃--再吃--吐死(太飽

1.餓--吃--無聊--無聊死

1.餓--吃--無聊--玩--吃--吐死(中毒

1.餓--吃--無聊--玩--洗澡--吃--無聊--玩--洗澡--吃(要餵5次

死了點熊頭重來


2022年1月3日 星期一

我與天文社與漢堡排_week15

 220103 week15

                                                                                                                                          💛🔔

期末作業的下半場

加入人物圖案

👉程式碼(主要更改部分為豆沙粉色   )
PShape obj;
PImage img;
PImage img2;
PImage img3;
void setup(){
  size(600,500,P3D);///場景為3D
  obj=loadShape("hand1.obj");
  camera(0,-70,120,0,0,0,0,1,0);
  img=loadImage("vs.png");
  img2=loadImage("me.png");
  img3=loadImage("no.png");
}

float boardX,boardY;
float x=0,y=0,z=0;
float vx=0,vy=0,vz=-0.2;

void draw(){
  lights();//打光
  background(112,146,190);
  fill(34,177,76);//綠色
  box(100,5,120);//綠色球桌
  
  pushMatrix();
  translate(0,-10,0);
  fill(255,0,0);//紅色
  box(98,20,5);//紅色網子
  popMatrix();

  pushMatrix();
  translate(-40,35,50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

  pushMatrix();
  translate(40,35,50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

  pushMatrix();

  translate(-40,35,-50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

 

  pushMatrix();
  translate(40,35,-50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();
  lights();
  fill(255);//球的顏色
  float dx=(mouseX-width/2.0)/8.0-10 ,dy=(mouseY-height*0.9)/5.0+100;
   
  
  
  pushMatrix();
    translate(x,y,z);
    lights();noStroke();sphere(5);
  popMatrix();
  //dx=mouseX-width/2;//mouseX; 
  //dy=mouseY-height/2;
  pushMatrix();
    //translate(boardX,-10,boardY);
    translate(dx,-10,dy);
    rotate(radians(180));
    shape(obj,0,0);
    stroke(0);//line(-50,0,+50,0);
  popMatrix();
  if(z<dy && z+vz>dy && dx-50<x && x<dx+50){
    stroke(255,0,0);
    vy=-vy;
  }else stroke(0);
  
  x+=vx; y+=vy; z+=vz;
  vy+=0.98;
  if(y>400){
    vy=-vy;
  }
  if(z<-20) vz=-vz;
  
  image(img,-70,-60,width/20,height/20);
  image(img2,45,-60,width/20,height/20);
  image(img3,60,-50,width/30,height/30);
}


己方的部分

己方的糯米糰子
對方的部分



宣傳圖的部分



對方自動偵測球的位置
👉程式碼
float pcX=150,pcVX=0;
void setup(){
  size(300,400);
}
void draw(){
  background(255);
  pcVX=(mouseX-pcX);
  if(pcVX>0 && pcVX>2)pcVX=2;
  if(pcVX<0 && pcVX<-2)pcVX=-2;
  pcX=pcX+pcVX;
  ellipse(pcX,50,30,30);
  ellipse(mouseX,mouseY,20,20);
}

    
 放入對手球拍
👉程式碼(主要更改部分為豆沙粉色   )
PShape obj;
PShape obj2;
PImage img;
PImage img2;
PImage img3;
void setup(){
  size(600,500,P3D);///場景為3D
  obj=loadShape("hand1.obj");
  obj2=loadShape("hand2.obj");
  camera(0,-70,120,0,0,0,0,1,0);
  img=loadImage("vs.png");
  img2=loadImage("me.png");
  img3=loadImage("no.png");
}

float boardX,boardY;
float x=0,y=0,z=0;
float vx=0,vy=0,vz=-0.2;

void draw(){
  lights();//打光
  background(112,146,190);
  fill(34,177,76);//綠色
  box(100,5,120);//綠色球桌
  
  pushMatrix();
  translate(0,-10,0);
  fill(255,0,0);//紅色
  box(98,20,5);//紅色網子
  popMatrix();

  pushMatrix();
  translate(-40,35,50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

  pushMatrix();
  translate(40,35,50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

  pushMatrix();

  translate(-40,35,-50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

 

  pushMatrix();
  translate(40,35,-50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();
  lights();
  fill(255);//球的顏色
  float dx=(mouseX-width/2.0)/8.0-10 ,dy=(mouseY-height*0.9)/5.0+100;
   

  
  pushMatrix();
    translate(x,y,z);
    lights();noStroke();sphere(5);
  popMatrix();
  //dx=mouseX-width/2;//mouseX; 
  //dy=mouseY-height/2;

  pushMatrix();//正電paipai
    //translate(boardX,-10,boardY);
    translate(dx,-10,dy);
    rotate(radians(180));
    shape(obj,0,0);
    stroke(0);//line(-50,0,+50,0);
  popMatrix();
  
  pushMatrix();//負電paipai
    //translate(boardX,-10,boardY);
    translate(10,-10,-50);
    rotate(radians(180));
    shape(obj2,0,0);
    stroke(0);//line(-50,0,+50,0);
  popMatrix();
  
  if(z<dy && z+vz>dy && dx-50<x && x<dx+50){
    stroke(255,0,0);
    vy=-vy;
  }else stroke(0);
  
  x+=vx; y+=vy; z+=vz;
  vy+=0.98;
  if(y>2){
    vy=-vy;
  }
  if(z<-20) vz=-vz;
  
  
  image(img,-70,-60,width/20,height/20);
  image(img2,45,-60,width/20,height/20);
  image(img3,60,-50,width/30,height/30);
}

桌球對打
👉程式碼(主要更改部分為豆沙粉色   )
PShape obj;
PShape obj2;
PImage img;
PImage img2;
PImage img3;
void setup(){
  size(600,500,P3D);///場景為3D
  obj=loadShape("hand1.obj");
  obj2=loadShape("hand2.obj");
  camera(0,-70,120,0,0,0,0,1,0);
  img=loadImage("vs.png");
  img2=loadImage("me.png");
  img3=loadImage("no.png");
}

float x=0,y=-25,z=0;//y為球上下高度
float vx=0,vy=0,vz=+0.2;///vz為前後

void draw(){
  lights();//打光
  background(112,146,190);
  fill(34,177,76);//綠色
  box(100,5,120);//綠色球桌
  
  pushMatrix();
  translate(0,-10,0);
  fill(255,0,0);//紅色
  box(98,20,5);//紅色網子
  popMatrix();

  pushMatrix();
  translate(-40,35,50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

  pushMatrix();
  translate(40,35,50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

  pushMatrix();

  translate(-40,35,-50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();

 

  pushMatrix();
  translate(40,35,-50);
  fill(#502C0F);//桌腳的顏色
  box(10,70,10);//咖色桌腳
  popMatrix();
  lights();
  fill(255);//球的顏色
  float dx=(mouseX-width/2.5)/8.0-10 ,dy=(mouseY-height*0.9)/5.0+100;
   
  
  
  pushMatrix();
    translate(x,y,z);
    lights();noStroke();sphere(3);
  popMatrix();
  pushMatrix();//正電paipai
    //translate(boardX,-10,boardY);
    translate(dx,-20,dy);//球拍高度//-20等於z軸
    //box(10);
    rotate(radians(180));
    shape(obj,0,0);
    stroke(0);
  popMatrix();
    
  
  pushMatrix();//負電paipai
    translate(0,-20,-60);
    rotate(radians(180));
    shape(obj2,0,0);
    stroke(0);//line(-50,0,+50,0);
  popMatrix();
  
  //if(z<dy && z+vz>dy && dx-50<x && x<dx+50 ){
  if( dist( x,y,z, dx, -20, dy)<10 ){
    //background(255,0,0);
    vz = -vz;
  }//else stroke(0);
  
  x+=vx; 
  y+=vy; //上下
  z+=vz;//前後
  vy+=0.98;
  //if(y>-10){
    //vy=-vy;
  //}
  if(y>-10) vy=-vy*0.9;
  if(x<0) vx=-vx;///反彈!
  
  
  if(z<-20) vz=-vz;///對方的回彈
  
  
  image(img,-70,-60,width/20,height/20);
  image(img2,45,-60,width/20,height/20);
  image(img3,60,-50,width/30,height/30);
  
}

程式碼可以參考2020程式設計2B-孤獨月宮的花園💁第七週-主題三:彈跳
https://2020cceb.blogspot.com/2020/04/blog-post_10.html


那麼這週先停在這裡
這週未完
1:對方球拍未能跟著球移動

下次進度安排

1:對手球拍自動偵測到球且跟著移動
2:讓球合乎反彈方向前進
3:其他進階功能


如果喜歡我的部落格的話
請幫我按右上角的愛心(根本按不下去)

也可以按右上角的小鈴鐺(這也按不下去)
才不會錯過我的更新哦!😉