问题描述
潜伏了一段时间,第一次发帖:)
我目前正在为 uni 开发一个小游戏。我已经完成了大部分工作,但我遇到的“问题”是迷失在隧道视野中。我希望有人能够为我指明正确的方向。
我有一个程序(下面的代码)可以将苍蝇的图像打印到画布上。苍蝇拍跟随鼠标,当苍蝇在苍蝇拍的范围内并按下鼠标时,苍蝇会被击退。
我遇到的问题是程序仍将死蝇识别为具有碰撞检测功能,因此无论我单击活蝇的死蝇,仍会检测到碰撞并产生新的苍蝇。
任何帮助将不胜感激:) 谢谢!
PImage fly,flybye,swatter,swatted;
float[] fX,fY; // fly locations array
float[] swat; // fly swatted binary boolean array,1 = swatted,0 = not swatted
int score = 0; // increments when swatted.
void setup(){
size(800,400);
fX = new float[0];
fY = new float[0];
swat = new float[0];
fly = loadImage("fly.png");
flybye = loadImage("flybye.png");
swatter = loadImage("swatter.png");
swatted = loadImage("swatted.png");
fX = append(fX,random(1,800)); //first fly - random location
fY = append(fY,400));
swat = append(swat,0); // used as a boolean and matches to each individual fly,0 = fly not
swatted,1 = swatted.
}
void populate(){ // draw the flies in memory to the screen.
for(int i = 0; i < fX.length; i++){
if(swat[i] == 1){ // if swatted
flybye.resize(30,30);// resize the fly image and place based on fx/fy array values
image(flybye,fX[i],fY[i]);
} else { // not swatted
fly.resize(30,30);
image(fly,fY[i]);
}
}
}
void collisionDetect(){ //collision detection - detect collision between swatter and fly
for(int i = 0; i < swat.length; i++){ // bounding Box detection
if(dist(fX[i],fY[i],mouseX,mouseY) < 50){ // condition should look at location of mouse
and individual coordinates in fX and fY
swat[i] = 1; // swatted
fX = append(fX,800)); //new fly placed in random location when old fly dies.
fY = append(fY,400));
swat =append(swat,0); // new fly not swatted
score++; //increment score
}
}
}
void draw(){
background(255);
populate(); // draw flys to screen.
fill(0);
textSize(20);
text(score,5,20);// set a text size and location for the score.
if(mousepressed) { // image swap
collisionDetect();
image(swatted,mouseX - 30,mouseY - 30); //draw swatter image to around mouse locaiton - might want to play with this to get it to look right.
}else{
image(swatter,mouseY - 30); // if not pressed then alternative image.
}
}
解决方法
难道你不应该在碰撞检测中测试苍蝇是否被拍打:
$event->sheet->setCellValue($priceSummaryCell,'=SUM('.$priceSummaryCellFormula.')');
$styleFooterSummery = [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE,// BORDER_THICK BORDER_THIN
'color' => ['rgb' => '2f2f2f']
],]
];