如何在游戏中实施得分系统? (arduboy)

时间:2019-07-20 07:22:14

标签: c++ arduino

我正在做我的第一场比赛,我对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

}

有人可以帮我吗?

0 个答案:

没有答案