顯示具有 08160643_簡維辰 標籤的文章。 顯示所有文章
顯示具有 08160643_簡維辰 標籤的文章。 顯示所有文章

2022年1月17日 星期一

week19

 最終成果



import ddf.minim.*;

Minim minim;

AudioPlayer player,player2;




float big=0,x1,y1,vx1,vy1,x2,y2,vx2,vy2;


boolean Catflying=false,Dogflying=false;


int round=0,blood=0,blood1=0,condition;

PImage img,img2,img3,img4,img5,img6;


void setup(){


  size(500,300);

  img = loadImage("1.png");

  imageMode(CENTER);

  img2 = loadImage("2.png");

  imageMode(CENTER);

  img3 = loadImage("3.jpg");

  img4=loadImage("c.png");

  img5=loadImage("b.png");

  imageMode(CENTER);

  img6=loadImage("a.png");

  imageMode(CENTER);

  minim = new Minim(this); //設定好

  player = minim.loadFile("abc.mp3");//音效

  

  

  player.play();

}

boolean testywall1(float a,float b,float c){

  if(b<y1&&y1<c){

    if(x1<a&&a<x1+vx1) return true;

    if(x1+vx1< a&&a<x1) return true;

  }

  return false;  

}


boolean testywall2(float a,float b,float c){

  if(b<y2&&y2<c){

    if(x2<a&&a<x2+vx2) return true;

    if(x2+vx2< a&&a<x2) return true;

  }

  return false;  

}


boolean testxwall1(float a,float b,float c){

  if(b<x1&&x1<c){

    if(y1<a&&a<y1+vy1) return true;

    if(y1+vy1< a&&a<y1) return true;

  }

  return false;  

}

boolean testxwall2(float a,float b,float c){

  if(b<x2&&x2<c){

    if(y2<a&&a<y2+vy2) return true;

    if(y2+vy2< a&&a<y2) return true;

  }

  return false;  

}

void draw(){

  background(img3);

  image(  img,450,250,125,125);


  

  image(  img2,50,250,100,100);

  if(blood1==0){

    fill(255,0,0);rect(0,55,20,30);

    fill(255,0,0);rect(25,55,20,30);

    fill(255,0,0);rect(50,55,20,30);

  }

  if(blood1==1){

    fill(255,0,0);rect(0,55,20,30);

    fill(255,0,0);rect(25,55,20,30);

    fill(199,199,199);rect(50,55,20,30);

  }

  if(blood1==2){

    fill(255,0,0);rect(0,55,20,30);

    fill(199,199,199);rect(25,55,20,30);

    fill(199,199,199);rect(50,55,20,30);

  }

  if(blood1==3){

    fill(199,199,199);rect(0,55,20,30);

    fill(199,199,199);rect(25,55,20,30);

    fill(199,199,199);rect(50,55,20,30);

    condition=1;

  }

  if(blood==0){

    fill(255,0,0);rect(425,55,20,30);

    fill(255,0,0);rect(450,55,20,30);

    fill(255,0,0);rect(475,55,20,30);

  }

  if(blood==1){

    fill(199,199,199);rect(425,55,20,30);

    fill(255,0,0);rect(450,55,20,30);

    fill(255,0,0);rect(475,55,20,30);

  }

  if(blood==2){

    fill(199,199,199);rect(425,55,20,30);

    fill(199,199,199);rect(450,55,20,30);

    fill(255,0,0);rect(475,55,20,30);

  }

  if(blood==3){

    fill(199,199,199);rect(425,55,20,30);

    fill(199,199,199);rect(450,55,20,30);

    fill(199,199,199);rect(475,55,20,30);

    condition=2;

  }

  

  

  

  

  fill(0,255,0);rect(0,0,big,50);


  fill(128,128,128);rect(240,150,20,150);

  if(Catflying){

    if(testywall1(240,150,150+150)==true)Catflying=false;

    else if(testywall1(240+20,150,150+150)==true)Catflying=false;

    else if(testxwall1(150,240,240+20)==true)Catflying=false;

    else if(testxwall1(150+150,240,240+20)==true)Catflying=false;

  }

  if(Dogflying){

    if(testywall2(240,150,150+150)==true)Dogflying=false;

    else if(testywall2(240+20,150,150+150)==true)Dogflying=false;

    else if(testxwall2(150,240,240+20)==true)Dogflying=false;

    else if(testxwall2(150+150,240,240+20)==true)Dogflying=false;

    

  }

  if(condition==1){

    background(img4);

    image(img6,250,150,250,250);

  }

  if(condition==2){

    background(img4);

    image(img5,250,150,250,250);

  }

  fill(255,128,64);

  if(Catflying){

    if(testywall1(375,200,200+125)==true){

      Catflying=false;

      blood++;

    }

    else if(testywall1(375+125,200,200+125)==true){

      Catflying=false;

      blood++;

    }

    else if(testxwall1(200,375,375+125)==true){

      Catflying=false;

      blood++;

    }

    else if(testxwall1(200+125,375,375+125)==true){

      Catflying=false;

      blood++;

    }

  }

  if(Dogflying){

    if(testywall2(25,200,200+100)==true){

      Dogflying=false;

      blood1++;

    }

    else if(testywall2(25+100,200,200+100)==true){

      Dogflying=false;

      blood1++;

    }

    else if(testxwall2(200,25,25+100)==true){

      Dogflying=false;

      blood1++;

    }

    else if(testxwall2(200+100,25,25+100)==true){

      Dogflying=false;

      blood1++;

    }

  }

  if(mousePressed){

    big++;

  }

  if(Catflying){


    round=1;

    x1+=vx1;y1+=vy1;vy1+=0.98;

    

    fill(255,255,0);ellipse(x1,y1,30,30);

    

    

  }


  


  if(Dogflying){


     round=0;

     x2+=vx2;y2+=vy2;vy2+=0.98;

     

     fill(255,255,0);ellipse(x2,y2,30,30);

    

    

  }


 


}


void mouseReleased(){




  if(round==0){




     x1=50;y1=250;


     float angle1=atan2(x1-250,y1-50);


     vx1 = cos(angle1)*big/5;vy1=sin(angle1)*big/5;


     Catflying=true;


     Dogflying=false;

     

  }






  if(round==1){


     x2=450;y2=250;


     float angle2=atan2(x2-250,y2-450);


     vx2 = cos(angle2)*big/5;vy2=-sin(angle2)*big/5;


     Dogflying=true;


     Catflying=false;


  }


  big=0;


}

2022年1月3日 星期一

week17

 今天的進度

import ddf.minim.*;

Minim minim;

AudioPlayer player,player2;




float big=0,x1,y1,vx1,vy1,x2,y2,vx2,vy2;


boolean Catflying=false,Dogflying=false;


int round=0,blood=0,blood1=0,condition;

PImage img,img2,img3,img4,img5,img6;


void setup(){


  size(500,300);

  img = loadImage("1.png");

  imageMode(CENTER);

  img2 = loadImage("2.png");

  imageMode(CENTER);

  img3 = loadImage("3.jpg");

  img4=loadImage("c.png");

  img5=loadImage("b.png");

  imageMode(CENTER);

  img6=loadImage("a.png");

  imageMode(CENTER);

  minim = new Minim(this); //設定好

  player = minim.loadFile("abc.mp3");//音效

  

  

  player.play();

}

boolean testywall1(float a,float b,float c){

  if(b<y1&&y1<c){

    if(x1<a&&a<x1+vx1) return true;

    if(x1+vx1< a&&a<x1) return true;

  }

  return false;  

}


boolean testywall2(float a,float b,float c){

  if(b<y2&&y2<c){

    if(x2<a&&a<x2+vx2) return true;

    if(x2+vx2< a&&a<x2) return true;

  }

  return false;  

}


boolean testxwall1(float a,float b,float c){

  if(b<x1&&x1<c){

    if(y1<a&&a<y1+vy1) return true;

    if(y1+vy1< a&&a<y1) return true;

  }

  return false;  

}

boolean testxwall2(float a,float b,float c){

  if(b<x2&&x2<c){

    if(y2<a&&a<y2+vy2) return true;

    if(y2+vy2< a&&a<y2) return true;

  }

  return false;  

}

void draw(){

  background(img3);

  image(  img,450,250,125,125);


  

  image(  img2,50,250,100,100);

  if(blood1==0){

    fill(255,0,0);rect(0,55,20,30);

    fill(255,0,0);rect(25,55,20,30);

    fill(255,0,0);rect(50,55,20,30);

  }

  if(blood1==1){

    fill(255,0,0);rect(0,55,20,30);

    fill(255,0,0);rect(25,55,20,30);

    fill(199,199,199);rect(50,55,20,30);

  }

  if(blood1==2){

    fill(255,0,0);rect(0,55,20,30);

    fill(199,199,199);rect(25,55,20,30);

    fill(199,199,199);rect(50,55,20,30);

  }

  if(blood1==3){

    fill(199,199,199);rect(0,55,20,30);

    fill(199,199,199);rect(25,55,20,30);

    fill(199,199,199);rect(50,55,20,30);

    condition=1;

  }

  if(blood==0){

    fill(255,0,0);rect(425,55,20,30);

    fill(255,0,0);rect(450,55,20,30);

    fill(255,0,0);rect(475,55,20,30);

  }

  if(blood==1){

    fill(199,199,199);rect(425,55,20,30);

    fill(255,0,0);rect(450,55,20,30);

    fill(255,0,0);rect(475,55,20,30);

  }

  if(blood==2){

    fill(199,199,199);rect(425,55,20,30);

    fill(199,199,199);rect(450,55,20,30);

    fill(255,0,0);rect(475,55,20,30);

  }

  if(blood==3){

    fill(199,199,199);rect(425,55,20,30);

    fill(199,199,199);rect(450,55,20,30);

    fill(199,199,199);rect(475,55,20,30);

    condition=2;

  }

  

  

  

  

  fill(0,255,0);rect(0,0,big,50);


  fill(128,128,128);rect(240,150,20,150);

  if(Catflying){

    if(testywall1(240,150,150+150)==true)Catflying=false;

    else if(testywall1(240+20,150,150+150)==true)Catflying=false;

    else if(testxwall1(150,240,240+20)==true)Catflying=false;

    else if(testxwall1(150+150,240,240+20)==true)Catflying=false;

  }

  if(Dogflying){

    if(testywall2(240,150,150+150)==true)Dogflying=false;

    else if(testywall2(240+20,150,150+150)==true)Dogflying=false;

    else if(testxwall2(150,240,240+20)==true)Dogflying=false;

    else if(testxwall2(150+150,240,240+20)==true)Dogflying=false;

    

  }

  if(condition==1){

    background(img4);

    image(img6,250,150,250,250);

  }

  if(condition==2){

    background(img4);

    image(img5,250,150,250,250);

  }

  fill(255,128,64);

  if(Catflying){

    if(testywall1(375,200,200+125)==true){

      Catflying=false;

      blood++;

    }

    else if(testywall1(375+125,200,200+125)==true){

      Catflying=false;

      blood++;

    }

    else if(testxwall1(200,375,375+125)==true){

      Catflying=false;

      blood++;

    }

    else if(testxwall1(200+125,375,375+125)==true){

      Catflying=false;

      blood++;

    }

  }

  if(Dogflying){

    if(testywall2(25,200,200+100)==true){

      Dogflying=false;

      blood1++;

    }

    else if(testywall2(25+100,200,200+100)==true){

      Dogflying=false;

      blood1++;

    }

    else if(testxwall2(200,25,25+100)==true){

      Dogflying=false;

      blood1++;

    }

    else if(testxwall2(200+100,25,25+100)==true){

      Dogflying=false;

      blood1++;

    }

  }

  if(mousePressed){

    big++;

  }

  if(Catflying){


    round=1;

    x1+=vx1;y1+=vy1;vy1+=0.98;

    

    fill(255,255,0);ellipse(x1,y1,30,30);

    

    

  }


  


  if(Dogflying){


     round=0;

     x2+=vx2;y2+=vy2;vy2+=0.98;

     

     fill(255,255,0);ellipse(x2,y2,30,30);

    

    

  }


 


}


void mouseReleased(){




  if(round==0){




     x1=50;y1=250;


     float angle1=atan2(x1-250,y1-50);


     vx1 = cos(angle1)*big/5;vy1=sin(angle1)*big/5;


     Catflying=true;


     Dogflying=false;

     

  }






  if(round==1){


     x2=450;y2=250;


     float angle2=atan2(x2-250,y2-450);


     vx2 = cos(angle2)*big/5;vy2=-sin(angle2)*big/5;


     Dogflying=true;


     Catflying=false;


  }


  big=0;


}

2021年12月27日 星期一

week16

今天進度: 

float big=0,x1,y1,vx1,vy1,x2,y2,vx2,vy2;


boolean Catflying=false,Dogflying=false,Cathit=false,Doghit=false;


int round=0;

PImage img,img2,img3;


void setup(){


  size(500,300);

  img = loadImage("1.png");

  imageMode(CENTER);

  img2 = loadImage("2.png");

  imageMode(CENTER);

  img3 = loadImage("3.jpg");

}


void draw(){


  background(img3);

  image(  img,450,250,125,125);

  image(  img2,50,250,100,100);

  

  fill(255,0,0);rect(0,55,20,30);

  fill(255,0,0);rect(25,55,20,30);

  fill(255,0,0);rect(50,55,20,30);

  fill(255,0,0);rect(425,55,20,30);

  fill(255,0,0);rect(450,55,20,30);

  fill(255,0,0);rect(475,55,20,30);

  fill(0,255,0);rect(0,0,big,50);


  fill(128,128,128);rect(240,150,20,150);

  fill(255,128,64);


  if(mousePressed){


    big++;


  }


  if(Catflying){


     round=1;


     x1+=vx1;y1+=vy1;vy1+=0.98;


     if(Collision1()) fill(255,0);


     else ellipse(x1,y1,30,30);

     if(hitCollision1()) fill(255,0);

     else ellipse(x1,y1,30,30);

  }


  


  if(Dogflying){


     round=0;


     x2+=vx2;y2+=vy2;vy2+=0.98;


     if(Collision2()) fill(255,0);


     else ellipse(x2,y2,30,30);


  }


 


}

boolean hitCollision1(){

  if(x1>450 && x1<500 && y1>250)return true;

  else return false;

}

boolean Collision1(){

  

  if(x1>240 && y1>150 &&x1<260  )return true;


  else return false;


}


boolean Collision2(){

  

  

  if(x2<260 && y2>150 &&x2>240  )return true;


  else return false;


}


void mouseReleased(){




  if(round==0){




     x1=50;y1=250;


     float angle1=atan2(x1-250,y1-50);


     vx1 = cos(angle1)*big/5;vy1=sin(angle1)*big/5;


     Catflying=true;


     Dogflying=false;


  }






  if(round==1){


     x2=450;y2=250;


     float angle2=atan2(x2-250,y2-450);


     vx2 = cos(angle2)*big/5;vy2=-sin(angle2)*big/5;


     Dogflying=true;


     Catflying=false;


  }


  big=0;


}

下次進度:打完碰撞偵測!

2021年12月20日 星期一

week 15

 貓狗大戰

程式碼:

float big=0,x,y,vx,vy;

boolean flying=false;

void setup(){

  size(500,300);

}

void draw(){

  background(255);

  fill(255,0,0);rect(0,0,big,50);

  line(200,200,mouseX,mouseY);

  if(mousePressed)big++;

  if(flying){

    x+=vx;y+=vy;vy+=0.98;

    ellipse(x,y,30,30);

  }

}

void mouseReleased(){

  flying=true;

  x=200;y=200;

  float angle=atan2(200-mouseY,200-mouseX);

  vx = cos(angle)*big/2;vy=sin(angle)*big/2;

  big=0;

}

目前進度:

float big=0,x1,y1,vx1,vy1,x2,y2,vx2,vy2;

boolean Catflying=false,Dogflying=false;

int round=0;

void setup(){

  size(500,300);

}

void draw(){

  background(255);

  fill(0,255,0);rect(0,0,big,50);

  fill(255,0,0);rect(240,150,20,150);

  if(mousePressed){

    big++;

  }

  if(Catflying){

     round=1;

     x1+=vx1;y1+=vy1;vy1+=0.98;

     if(Collision1()) fill(255);

     else ellipse(x1,y1,30,30);

  }

  

  if(Dogflying){

     round=0;

     x2+=vx2;y2+=vy2;vy2+=0.98;

     if(Collision2()) fill(255);

     else ellipse(x2,y2,30,30);

  }

 

}

boolean Collision1(){

  if(x1>240  && y1>150   )return true;

  else return false;

}

boolean Collision2(){

  if(x2<260 && y2>150   )return true;

  else return false;

}

void mouseReleased(){


  if(round==0){


     x1=50;y1=250;

     float angle1=atan2(x1-250,y1-50);

     vx1 = cos(angle1)*big/3;vy1=sin(angle1)*big/3;

     Catflying=true;

     Dogflying=false;

  }



  if(round==1){

     x2=450;y2=250;

     float angle2=atan2(x2-250,y2-450);

     vx2 = cos(angle2)*big/3;vy2=-sin(angle2)*big/3;

     Dogflying=true;

     Catflying=false;

  }

  big=0;

}

左右可以互丟球,下次要做完碰到球就消失!

2021年12月6日 星期一

week09


 一開始先點名,之後向各位確認期末題目,再來一個一個示範



俄羅斯方塊



一二三木頭人



小朋友下樓梯


小雞過馬路



弓箭傳說





2021年11月29日 星期一

week08

 第一堂

填寫期中問卷,想好期末作品主題,示範小人跑步與彈奏鋼琴

小人跑步示範網址https://openprocessing.org/sketch/911326




PImage img;

void setup(){

size(500,500);

img=loadImage("img.jpg");

imageMode(CENTER);

}

int a=0, b=0, x=250, y=250;

void draw(){

background(255);

//image( img, 0,0);

image(  img.get(141*a, 211*b, 141,211), x,y);

if(frameCount%30==0) a = (a+1)%4;

}

void keyPressed(){

if(keyCode==RIGHT){ b=3; x++; }

if(keyCode==LEFT) { b=2; x--; }

if(keyCode==UP) { b=1; y--; }

if(keyCode==DOWN){ b=0; y++; }

}


第二節




討論期末主題,我們要做貓狗大戰


第三節




觀看Geometry Dash大概怎麼做(跟貪食蛇差不多)


期末規劃


遊戲畫面




需要物件

2個角色(一般樣子、被打到樣子、沒被打到偷笑樣子、小擦傷樣子、半血受傷樣子、翻東西樣子)、血量條、不同武器、裝武器的東西、背景、時間倒數、續氣條

道具功能

Double Attack:攻擊二次
Power Throw:超大骨頭攻擊(超痛)
Stink Bomb:炸彈攻擊
Power Up:回復HP

2021年11月22日 星期一

week07

 第一節




float x=250,y=0,vx=0,vy=3;
void setup(){
  size(500,600);
}
void draw(){
  background(255);
  ellipse(x,y,50,50);
  y=y+vy;
}





float x=250,y=0,vx=0,vy=3;
float x2=150,y2=50,vx2=0,vy2=2;
void setup(){
  size(500,600);
}
void draw(){
  background(255);
  ellipse(x,y,50,50);
  ellipse(x2,y2,50,50);
  y=y+vy;  //vy是速度
  y2=y2+vy2;  //vy2是速度
}




float []x={250,150,350,300};
float []y={0,50,80,100};
float []vx={0,0,0,0};
float []vy={3,2,2.5,4};
void setup(){
  size(500,600);
}
void draw(){
  background(255);
  for(int i=0;i<4;i++){
    ellipse(x[i],y[i],50,50);
    y[i]=y[i]+vy[i];//vy是速度
  }
}




float []x={250,150,350,300};
float []y={0,50,80,100};
float []vx={0,0,0,0};
float []vy={3,2,2.5,4};
void setup(){
  size(500,600);
}
void draw(){
  background(255);
  for(int i=0;i<4;i++){
    ellipse(x[i],y[i],50,50);
    y[i]=y[i]+vy[i];//vy是速度
    if(y[i]>600) vy[i] = -vy[i];//撞到下方
    if(y[i]<0) vy[i] = -vy[i];//接到上方

  }
}

第二節



//mouse碰到球可以得分
float []x={250,150,350,300};
float []y={0,50,80,100};
float []vx={0,0,0,0};
float []vy={3,2,2.5,4};
void setup(){
  size(500,600);
}
void draw(){
  background(255);
  for(int i=0;i<4;i++){
    fill(255,255,0);ellipse(x[i],y[i],50,50);
    if(dist(mouseX,mouseY,x[i],y[i])<=50){
      continue;
    }
    y[i]=y[i]+vy[i];//vy是速度
    if(y[i]>600) vy[i] = -vy[i];//撞到下方
    if(y[i]<0) vy[i] = -vy[i];//接到上方

  }
  fill(255,0,0); ellipse(mouseX,mouseY,50,50);
}





float []x={250,150,350,300};
float []y={0,50,80,100};
float []vx={0,0,0,0};
float []vy={3,2,2.5,4};
boolean [] dead={false,false,false,false};//false 0,truc 1
void setup()
{
  size(500,600);
}
void draw()
{
  background(255);
  for(int i=0;i<4;i++)
  {
    fill(255,255,0);ellipse(x[i],y[i],50,50);
    if(dist(mouseX,mouseY,x[i],y[i])<=50)
    {
      dead[i]=true;//剛剛是暫停 現在是碰到就死
    }
    if(dead[i]==true)continue;//如果死了 就要再換下一個了

    y[i]=y[i]+vy[i];
    if(y[i]>600) vy[i]=-vy[i];
    if(y[i]<0) vy[i]=-vy[i];
  }
  fill(255,0,0); ellipse(mouseX,mouseY,50,50);
}


第三節








boolean down;
void setup(){
  size(500,300);
}
void draw(){
  if(mousePressed) down=true;
  else down=false;
  print(down);
  if(down)background(255,0,0);
  else background(0,255,0);
}




//mouse碰到球可以得分
float []x;
float []y;
float []vy;
boolean [] dead;
int N=20;
void setup(){
  size(500,600);
  x=new float[N];
  y=new float[N];
  vy=new float[N];
  dead=new boolean[N];
  for(int i=0;i<N;i++){
    x[i]=random(500);
    y[i]=random(100,200);
    vy[i]=random(3,4);
    dead[i]=false;
  }
}
void draw(){
  background(255);
  for(int i=0;i<N;i++){
    if(dist(mouseX,mouseY,x[i],y[i])<=50){
      dead[i]=true;
    }
    if(dead[i]==true)continue;
    fill(255,255,0);ellipse(x[i],y[i],50,50);
    y[i]=y[i]+vy[i];//vy是速度
    if(y[i]>600) vy[i] = -vy[i];//撞到下方
    if(y[i]<0) vy[i] = -vy[i];//接到上方

  }
  fill(255,0,0); ellipse(mouseX,mouseY,50,50);
}


第四節




class Ball{
  float x,y,vx,vy;
  boolean dead;
  Ball(){
    x=random(500);
    y=random(100,200);
    vy=random(3,4);
    dead=false;
  }
  void draw(){
    if(dead==true)return;
    ellipse(x,y,50,50);
    if(dist(mouseX,mouseY,x,y)<50){
      dead=true;
    }
    y=y+vy;
    if(y>500)vy=-vy;
    if(y<0)vy=-vy;
  }
} 
Ball [] balls;
void setup(){
  size(500,500);
  balls=new Ball[20];
  for(int i=0;i<20;i++){
    balls[i]=new Ball();
  }
}
void draw(){
  background(255);
  for(int i=0;i<20;i++){
    balls[i].draw();
  }
}




//球會四處移動
class Ball{
  float x,y,vx,vy;
  boolean dead;
  Ball(){
    x=random(500);
    y=random(500);
    vy=random(-4,4);
    vx=random(-4,4);
    dead=false;
  }
  void draw(){
    if(dead==true)return;
    ellipse(x,y,50,50);
    if(dist(mouseX,mouseY,x,y)<50){
      dead=true;
    }
    x=x-vx;
    y=y-vy;
    if(y>500||y<0)vy=-vy;
    if(x>500||x<0)vx=-vx;
  }
} 
Ball [] balls;
void setup(){
  size(500,500);
  balls=new Ball[20];
  for(int i=0;i<20;i++){
    balls[i]=new Ball();
  }
}
void draw(){
  background(255);
  for(int i=0;i<20;i++){
    balls[i].draw();
  }
}




//加上vy+=0.98; 重力加速度
//用Reborn做出像彈幕遊戲的效果
//只要滑鼠碰到紅色點點就Gameover了

//Step03-2 用 class物件
class Ball{//我們發明 Ball物件
  float x, y, vx, vy;
  boolean dead;
  Ball(){//建構 同名的東西
    reborn();
  }
  void reborn(){
    x = random(500);
    y = random(500);
    vy = random(-2,2);
    vx = random(-2,2);
    dead = false;//沒有死掉
  }
  void draw(){
    if(dead==true) return;
    fill(255,0,0); ellipse(x,y, 5,5);
    if( dist(mouseX,mouseY,x,y)<5 ){
      dead=true;
      gameOver=true;
    }
    x = x + vx*1;//速度*時間=距離
    y = y + vy*1;
    if(y>500 || y<0) reborn();
    if(x>500 || x<0) reborn();
  }
}
Ball [] balls;
void setup(){
  size(500,500);
  balls = new Ball[99];
  for(int i=0; i<99; i++){
    balls[i] = new Ball();
  }
}
boolean gameOver=false;
void draw(){
  background(0);
  for(int i=0; i<99; i++){
    balls[i].draw();
  }
  if(gameOver) background(255,0,0);  
}















2021年11月15日 星期一

week06

 第一節



size(600,600);
fill(255,0,0);
textSize(80);
text("Hello",50,50);




void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  text("Hello",50,100);
}




void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  text("Time:"+frameCount,50,100);
}




void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  text("Time:"+frameCount/60,50,100);
  text("millis():"+millis()/1000,50,200);
}




void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  text(hour()+":"+minute()+":"+second(),50,100);
  text("millis():"+millis()/1000,50,200);
}


第二節




PFont myFont;
void setup(){  
  size(500,500);
  myFont = createFont("標楷體",100);
  textFont(myFont);
  text("中文",100,100);
}




PFont font1,font2;
void setup(){  
  size(500,500);
  font1 = createFont("標楷體",100);
  textFont(font1);
  font2 = createFont("微軟正黑體 Bold",100);
}
void draw(){
  background(0);
  text("中文",100,100);
  if(mousePressed) textFont(font2);
  else textFont(font1);
}


第三堂





void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(255);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text(hh+":"+mm+":"+ss,50,100);

}




void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(#075BB2);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text("現在:"+hh+":"+mm+":"+ss,50,100);
  text("下課:15:40:00",50,200);
  
  int now = hour()*60*60 + minute()*60+second();
  int next = 15*60*60+40*60+0;
  int remain = next-now;
  text("剩下:"+remain,50,300);
}




void setup(){  
  size(600,600);
  fill(255,0,0);
  textSize(80);
}
void draw(){
  background(#075BB2);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text("現在:"+hh+":"+mm+":"+ss,50,100);
  text("下課:15:40:00",50,200);
  
  int now = hour()*60*60 + minute()*60+second();
  int next = 15*60*60+40*60+0;
  int remain = next-now;
  text("剩下:"+remain,50,300);
  hh = nf(remain/60/60,2);
  mm = nf(remain/60%60,2);
  ss = nf(remain%60,2);
  text("剩下:"+hh+":"+mm+":"+ss,50,400);
}



第四堂




PImage [] img = new PImage[10];
void setup(){
  size(1120,450);
  for(int i=0;i<10;i++)img[i]=loadImage(i+".png");
}
void draw(){
  for(int i=0;i<10;i++){
    int x=(i%5)*224,y=int(i/5)*225;
    image(img[i],x,y);
  }
}




PImage [] img = new PImage[10];
PFont font;
void setup(){  
  size(1120,450);
  for(int i=0;i<10;i++) img[i] = loadImage(i+".png");
  fill(255);
  font = createFont("標楷體",80);
  textFont(font);
}
void draw(){
  background(#075BB2);
  String hh=nf(hour(),2);
  String mm=nf(minute(),2);
  String ss=nf(second(),2);
  text("現在:"+hh+":"+mm+":"+ss,50,100);
  text("下課:15:40:00",50,200);
  
  int now = hour()*60*60 + minute()*60+second();
  int next = 16*60*60+40*60+0;
  int remain = next-now;
  if(remain<0)remain += 24*60*60;
  text("剩下:"+remain,50,300);
  hh = nf(remain/60/60%60,2);
  mm = nf(remain/60%60,2);
  ss = nf(remain%60,2);
  text("剩下:"+hh+":"+mm+":"+ss,50,400);
  int x=800;
  while(remain>0){
    int n = remain%10;
    remain = remain%10;
    image(img[n],x,100,100,100);
    x-=100;
  }
}