2023年10月26日 星期四

LAD Week07

萬聖節遊戲

解決畫線後線條不會消失問題
背景會覆蓋畫面、鬼移動(軌跡)


同時解決軌跡問題及畫線問題

加入:
 for(int i=pt.size()-1;i>=0;i--){
    pt.remove(i); 
  }
始放開時線條消失
畫出正常的線

辨識畫線,畫橫線變紅色
直線變成藍色

滑鼠往右下時變成綠色,即可畫V


ArrayList<PVector>pt=new ArrayList<PVector>();
void setup(){
  size(400,400);
  background(255);
}

float ghostX=400,ghostY=20;
void mouseDragged(){//按下滑鼠在拖曳
   pt.add(new PVector(mouseX,mouseY));
}
void draw(){
  background(255);
  strokeWeight(1);
  stroke(0);ellipse(200,200,15,15);
  stroke(0);ellipse(ghostX,ghostY,15,15);
  strokeWeight(4);
  float dpx=0,dpy=0;
  int rightdown=0;
  for(int i=0;i<pt.size()-1;i++){
    PVector p=pt.get(i),p2=pt.get(i+1);
    dpx+=abs(p2.x-p.x);
    dpy+=abs(p2.y-p.y);
    if(p2.x-p.x>0&&p2.y-p.y>0)rightdown++;
  }
  if(dpx>100&&dpy<40)stroke(255,0,0);
  else if(dpx<40&&dpy>100)stroke(0,0,255);
  else if(rightdown>30)stroke(0,255,0);
  else stroke(0);
  for(int i=0;i<pt.size()-1;i++){
    PVector p=pt.get(i),p2=pt.get(i+1);
    line(p.x,p.y,p2.x,p2.y);
  }

  float dx=200-ghostX,dy=200-ghostY,len=sqrt(dx*dx+dy*dy);
  ghostX+=dx/len/3;
  ghostY+=dy/len/3;
}
void mouseReleased(){
  for(int i=pt.size()-1;i>=0;i--){
    pt.remove(i); 
  }
}
修改綠色線條,解決加速度畫不出來問題

右上

修正,使^不成立(黃色)



沒有留言:

張貼留言