我试图在处理过程中以2d侧面滚动视频游戏显示我的分数。问题是我的分数取决于Framecount,在角色死亡后我想在屏幕上显示放大的分数。我的程序工作方式是在碰撞发生后,计数器被设置为特定的数字(100),每个循环计数器将减少,一旦它达到一定数量,程序将重新启动。我的想法是在碰撞和程序重启之间显示分数。我的问题是,由于程序仍在运行,分数将继续增加。关于如何解决这个问题的任何想法?我尝试暂停绘制循环,但由于游戏不会再次恢复,因此无法正常工作。非常感谢你的帮助。
这是我的分数课程:
public class Score {
private PFont font;
private int x, y;
private PImage img;
//constructor
public Score ( int x, int y, PFont font) {
this.x = x;
this.y = y;
this.font = font;
}
public void draw () {
Scorevar = frameCount/20;
textFont(font);
fill (0);
//textAlign(CENTER);
textMode(MODEL);
text("Score = "+ Scorevar, x, y);
}
}
这是我的主循环的一部分,涉及得分
void draw() {
background (255);
chari.draw();
//collision and collison image
if ( collide_count == 0 ) {
chari.draw();
}
else {
image( collide, chari.x+130, chari.y+100 );
collide_count--;
}
if ( collide_count > 5 && collide_count < 80) {
score2.draw();
}
if ( collide_count == 5) {
frameCount = 0;
setup();
}
blockfield.draw();
score1.draw();
}
碰撞代码:
public void update(float cY, float cW) {
for ( int i =frameCount/200; i >0; i--) {
//for (int i =frameCount/400; i >0; i--) {
//moves blocks right to left
block[i].x -=(frameCount/200);
//spawns block when they leave the screen
if (block[i].x < -Blockpic.width) {
block[i].setX( random(width, width*2));
block[i].setY( random (height));
//println(block[i].x + " " + block[i].y);
}
if (block[i].x < 130) {
if(block[i].y > cY && block[i].y < (cY+cW)){
//println(collide_count + " with");
collide_count = 100;
}
}
}
}
答案 0 :(得分:1)
只需将得分值保存到单独的变量中。然后使用该变量设置死亡屏幕的分数。
答案 1 :(得分:0)
我引入了一个名为finished的新布尔值,默认情况下设置为false,在碰撞期间设置为true。
if (block[i].x < 130) {
if(block[i].y > cY && block[i].y < (cY+cW) && !finished){
//println(collide_count + " with");
collide_count = 80;
finished = true;
currentCount = frameCount/20;
}
在collison中我设置了currentCount = Framecount并在完成时打印得分== true。
public void draw () {
Scorevar = frameCount/20;
textFont(font);
fill (0);
//textAlign(CENTER);
textMode(MODEL);
if ( finished == true) {
text("Score = "+ currentCount, x, y);
}
else {
text("Score = "+ Scorevar, x, y);
}
}
再次感谢!