2023年11月2日 星期四

部落格week08

 

第一堂課

  • 開新檔案輸入程式碼,叫出往右下的點


void setup(){
  size(400,400);
}
float x=200,y=200,vx=1,vy=1;
void draw(){
  ellipse(x,y,10,10);
  x+=vx;
  y+=vy;
}

  • 開新檔案輸入程式碼使得點是拋物線 


void setup(){
  size(400,400);
}
float x=50,y=250,vx=2,vy=-20;
void draw(){
  ellipse(x,y,10,10);
  x+=vx;
  y+=vy;
  vy+=0.98;
}
  • 新增檔案輸入程式碼使得點到一定高度會固定Y並彈跳


void setup(){
  size(400,400);
}
float x=50,y=250,vx=2,vy=-20;
void draw(){
  ellipse(x,y,10,10);
  x+=vx;
  y+=vy;
  vy+=0.98;
  if(y>350){
    y=350;
    vy=-vy*0.5;
    vx=vx*0.8;
  }
  ellipse(x,y,10,10);
}

第二堂課

  • 開新檔案輸入程式碼讓馬力歐有X軸

void setup(){
  size(400,400);
}
float marioX=50,marioY=250,vx=0,vy=0;
void draw(){
  background(108,137,255);
  marioX+=vx;
  fill(255,0,0);ellipse(marioX,marioY,15,20);
  fill(229,119,42);rect(0,260,400,150);
}
void keyPressed(){
  if(keyCode==RIGHT)vx=2;
  if(keyCode==LEFT)vx=-2;
}
void keyReleased(){
  if(keyCode==LEFT||keyCode==LEFT)vx=0;
}

  • 開新檔案輸入程式碼讓馬力歐有Y軸

 

void setup(){
  size(400,400);
}
float marioX,marioY=250,vx=2,vy=-20;
void draw(){
  background(108,137,255);
  marioX+=vx;
  marioY+=vy;
  fill(255,0,0);ellipse(marioX,marioY,15,20);
  fill(229,119,42);rect(0,260,400,150);
}
void keyPressed(){
  if(keyCode==RIGHT) vx=2;
  if(keyCode==LEFT) vx=-2;
  if(keyCode==UP) vy=-20;
}
void keyReleased(){
  if(keyCode==LEFT||keyCode==RIGHT)vx=0;
}


  • 新增檔案輸入程式碼讓馬力歐可以往上飛 


void setup(){
  size(400,400);
}
float marioX,marioY=250,vx=2,vy=-20;
void draw(){
  background(108,137,255);
  marioX+=vx;
  if(flying){
  marioY+=vy;
  vy+=0.98;
  if(marioY>=250){
    marioY=250;
    flying=false;
  }
  }
  fill(255,0,0);ellipse(marioX,marioY,15,20);
  fill(229,119,42);rect(0,260,400,150);
}
boolean flying=false;
void keyPressed(){
  if(keyCode==RIGHT) vx=2;
  if(keyCode==LEFT) vx=-2;
  if(keyCode==UP) {
  vy=-20;
  flying=true;
}
}
void keyReleased(){
  if(keyCode==LEFT||keyCode==RIGHT)vx=0;
}
  • 修改程式碼讓馬力歐不能連跳
void setup(){
  size(400,400);
}
float marioX,marioY=250,vx=2,vy=-20;
void draw(){
  background(108,137,255);
  marioX+=vx;
  if(flying){
  marioY+=vy;
  vy+=0.98;
  if(marioY>=250){
    marioY=250;
    flying=false;
  }
  }
  fill(255,0,0);ellipse(marioX,marioY,15,20);
  fill(229,119,42);rect(0,260,400,150);
}
boolean flying=false;
void keyPressed(){
  if(keyCode==RIGHT) vx=2;
  if(keyCode==LEFT) vx=-2;
  if(keyCode==UP&&flying==false) {
  vy=-20;
  flying=true;
}
}
void keyReleased(){
  if(keyCode==LEFT||keyCode==RIGHT)vx=0;
}

  • 新增檔案輸入程式碼使得馬力歐碰到磚塊會卡住 

void setup(){
  size(400,400);
}
float marioX,marioY=250,vx=2,vy=-20;
void draw(){
  background(108,137,255);
  marioX+=vx;
  if(flying){
  marioY+=vy;
  vy+=0.98;
  if(marioY>=250){
    marioY=250;
    flying=false;
  }
  }
  fill(255,0,0);ellipse(marioX,marioY,15,20);
  fill(229,119,42);rect(0,260,400,150);
  fill(229,119,42);rect(200,150,20,20);
  if(hitBox(200,150,20,20)){
    vy=0;
    marioY=150+20;
  }
}
boolean hitBox(int x,int y,int w,int h){
if(x<marioX && marioX<x+w && y<marioY && marioY<y+h)return true;
else return false;
}
boolean flying=false;
void keyPressed(){
  if(keyCode==RIGHT) vx=2;
  if(keyCode==LEFT) vx=-2;
  if(keyCode==UP&&flying==false) {
  vy=-20;
  flying=true;
}
}
void keyReleased(){
  if(keyCode==LEFT||keyCode==RIGHT)vx=0;
}

第三堂課

  • 開新檔案輸入程式碼使得看起來更自然

void setup(){
  size(400,400);
}
float marioX,marioY=250,vx=2,vy=-20;
void draw(){
  background(108,137,255);
  marioX+=vx;
  if(flying){
  marioY+=vy;
  vy+=0.98;
  if(marioY>=250){
    marioY=250;
    flying=false;
  }
  }
  fill(255,0,0);ellipse(marioX,marioY,15,10);
  fill(229,119,42);rect(0,260,400,150);
  fill(229,119,42);rect(200,150,20,20);
  if(hitBox(200,150,20,20)){
  if(vy>0){
    marioY=150-10;
    flying=false;
  }else{
    vy=0;
    marioY=150+20+10;
   }
  }
}
boolean hitBox(int x,int y,int w,int h){
if(x-7<marioX && marioX<x+w+7 && y-10<marioY && marioY<y+h+10)return true;
else return false;
}
boolean flying=false;
void keyPressed(){
  if(keyCode==RIGHT) vx=2;
  if(keyCode==LEFT) vx=-2;
  if(keyCode==UP&&flying==false) {
  vy=-20;
  flying=true;
}
}
void keyReleased(){
  if(keyCode==LEFT||keyCode==RIGHT)vx=0;
}

  • 開新檔案修改程式碼讓馬力歐在方塊上站住並且離開方塊會掉下來 


void setup(){
  size(400,400);
}
float marioX=50,marioY=250,vx=0,vy=0;
void draw(){
  background(108,137,255);
  marioX+=vx;
  if(flying){
    marioY+=vy;
    vy+=0.98;
    if(marioY>=250){
      marioY=250;
      flying=false;
    }
 }
  fill(255,0,0);    ellipse(marioX,marioY,15,20);
  fill(229,119,42); rect(0,260,400,150);
  fill(229,119,42); rect(200,150,20,20);
  if(hitbox(200,150,20,20)){
     if(vy>0){
       marioY=150-10;
       flying=false;
       stand_box=true;
     }else{
       vy=0;
       marioY=150+20+10;
     }
  }
  if(stand_box==true  &&  flying==false  &&  leavebox(200,150,20,20)){
    stand_box=false;
    flying=true;
    vy=0;
  }
}
boolean leavebox(int x,int y,int w,int h){
   if(x-7>marioX || marioX>x+w+7 )  return true;
   else return false;
}
boolean  hitbox(int x,int y,int w,int h){
  if(x-7<marioX &&  marioX<x+w+7  &&  y-10<marioY  &&  marioY<y+h+10)  return true;
   else return false;
}
boolean  flying=false,stand_box=false;
void keyPressed(){
  if(keyCode==RIGHT)  vx=2;
  if(keyCode==LEFT)  vx=-2;
  if(keyCode==UP&&flying==false){
    vy=-20;
    flying=true;
  }
}
void  keyReleased(){
   if(keyCode==RIGHT||keyCode==LEFT) vx=0;
}

  • 開新檔案輸入程式碼使得能藉由迴圈自動產出磚頭 


沒有留言:

張貼留言