2023年11月2日 星期四

o.O week08

week08

08-1
牛頓力學 靜者恆靜 動者恆動


08-2

08-3 碰撞偵測


08-4
可控制馬力歐

08-5
能用左右鍵一步一步移動


08-6


08-7
碰到磚塊會反彈 會卡住

08-8
碰到反彈不會卡住

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,25);
  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;
}


08-9
可以站在磚塊上












沒有留言:

張貼留言