我正在做我的第一场比赛,我对c ++的掌握还不是很熟练,但是我取得了令人难以置信的进步。如何实现得分和/或游戏结束功能?
我已经尝试过制作一个变量来跟踪箭头和播放器的位置,但是没有用。代码如下所示:
void makeObstacles() {
int obstaclePlacement = random(1, 4); //so it can appear in 3 places on the screen
obstaclePlacement = map(obstaclePlacement, 1, 4, 50, 1); //map the placement of the obstacles to the correct positions
for (int i = 120; i != 1; i--) { //move the arrows across
arduboy.setCursor(10, 50);
if (arduboy.pressed(A_BUTTON)) { //control the player for the next 5 lines
arduboy.setCursor(10, 34);
}
if (arduboy.pressed(B_BUTTON)) {
arduboy.setCursor(10, 18);
}
if (arrowY == playerY && arrowX == playerX) {
arduboy.clear();
arduboy.print("Game over");
while (true) {}
}
arduboy.clear();
arduboy.print("*"); //print the player
arduboy.setCursor(i, obstaclePlacement); //move to where the arrow should be
arduboy.print("<---"); //print the arrow
//arduboy.print(obstaclePlacement); //used for debugging; shows the y coord of the arrow
delay(10); //slow down the arrow
arduboy.display(); //update screen
}
arduboy.setCursor(10, 50);
return true; //end function
}
除了我无法获得箭头或播放器的位置...
void makeObstacles() {
int obstaclePlacement = random(1, 4); //so it can appear in 3 places on the screen
obstaclePlacement = map(obstaclePlacement, 1, 4, 50, 1); //map the placement of the obstacles to the correct positions
for (int i = 120; i != 1; i--) { //move the arrows across
arduboy.setCursor(10, 50);
if (arduboy.pressed(A_BUTTON)) { //control the player for the next 5 lines
arduboy.setCursor(10, 34);
}
if (arduboy.pressed(B_BUTTON)) {
arduboy.setCursor(10, 18);
}
arduboy.clear();
arduboy.print("*"); //print the player
arduboy.setCursor(i, obstaclePlacement); //move to where the arrow should be
arduboy.print("<---"); //print the arrow
//arduboy.print(obstaclePlacement); //used for debugging; shows the y coord of the arrow
delay(10); //slow down the arrow
arduboy.display(); //update screen
}
arduboy.setCursor(10, 50);
return true; //end function
}
有人可以帮我吗?