Week15
本周完成geometry dash的gameover的检测以及结束画面
1.gameover游戏结束侦测
利用上周碰撞侦测加入到生成陷阱的for回圈,使正方形碰到陷阱则gameover的boolean值为true
boolean gameOver=false;
for(int i=0;i<100;i++){
now=i;
if(collision()) gameOver=true;//如果碰到,则gameover的boolean值为true
triangle(badx[i]-bgx,310,badx[i]-25-bgx,350,badx[i]+25-bgx,350);
}
boolean collision(){
boolean b1=insideTriangle(150,usery);
boolean b2=insideTriangle(200,usery);
boolean b3=insideTriangle(200,usery+50);
boolean b4=insideTriangle(150,usery+50);
if(b1 || b2 || b3 || b4) return true;
else return false;
}
boolean insideTriangle(float x,float y){
float c1=cross(x,y,badx[now]-bgx,310,badx[now]-25-bgx,350);
float c2=cross(x,y,badx[now]-25-bgx,350,badx[now]+25-bgx,350);
float c3=cross(x,y,badx[now]+25-bgx,350,badx[now]-bgx,310);
if(c1>=0 && c2>=0 && c3>=0) return true;
else return false;
}
float cross(float xp,float yp,float x0,float y0,float x1,float y1){
return (xp-x0)*(y1-y0)-(yp-y0)*(x1-x0);
}
2.游戏结束以及分数画面
使用if判断gameover的true和false,用text打出分数
boolean gameOver=false;
void draw(){
if(gameOver==false){//没结束则运行
score=millis()/1000;
fill(0);
text("score: "+score,200,50);
}
else if(gameOver){//结束了跳出背景
background(0);
fill(255,0,0);
text("Goog luck next time!",100,100);
text("score: "+score,200,150);
}
| 游戏中计分 |
| 游戏结束界面 |
沒有留言:
張貼留言