그래서 캐릭터를 움직일 수있는 게임을 만들었고 그 캐릭터와 라인을 통과시켜야하지만 1 문제가 있습니다. 첫 번째 줄이 내 화면의 아래쪽에 도달하면 점수가 계산되기 시작합니다. 내 캐릭터가 줄 간격을 지날 때 점수가 +1이되도록 만들려고합니다. 어떻게해야합니까? EDIT : 또한 마지막 줄이 바닥에 도달했을 때 점수가 계산됩니다!+ 점수 시스템을 만들고 싶습니다
if (obstacles.get(obstacles.size()-1).getRectangle().top >= Constants.SCREEN_HEIGHT){
int xStart = (int) (Math.random()*(Constants.SCREEN_WIDTH- playerGap));
obstacles.add(0, new Obstacle(obstacleHeight, color, xStart, obstacles.get(0).getRectangle().top - obstacleHeight - obstacleGap, playerGap));
obstacles.remove(obstacles.size()-1);
score++;
}
}
public void draw(Canvas canvas){
for(Obstacle ob : obstacles)
ob.draw(canvas);
Paint paint = new Paint();
paint.setTextSize(100);
paint.setColor(Color.GREEN);
canvas.drawText("" + score, 50, 100 + paint.descent()- paint.descent(), paint);
EDIT :
int currY = -5*Constants.SCREEN_HEIGHT/4, rect;
while(currY < 0){
int xStart = (int) (Math.random()*(Constants.SCREEN_WIDTH- playerGap));
obstacles.add(new Obstacle(obstacleHeight, color, xStart, currY, playerGap));
currY += obstacleHeight + obstacleGap;
}
if (obstacles.get(obstacles.size() - 1).getRectangle().top >= currY) {
score++;
}
EDIT2 :
private void populateObatacles(){
int currY = -5*Constants.SCREEN_HEIGHT/4;
while(currY < 0){
int xStart = (int) (Math.random()*(Constants.SCREEN_WIDTH- playerGap));
obstacles.add(new Obstacle(obstacleHeight, color, xStart, currY, playerGap));
currY += obstacleHeight + obstacleGap;
}
}
EDIT3 :
if (obstacles.get(lastLineScored-1).getRectangle().top >= currY) {
score++;
lastLineScored--;
}
if (obstacles.get(obstacles.size()-1).getRectangle().top >= Constants.SCREEN_HEIGHT){
int xStart = (int) (Math.random()*(Constants.SCREEN_WIDTH- playerGap));
obstacles.add(0, new Obstacle(obstacleHeight, color, xStart, obstacles.get(0).getRectangle().top - obstacleHeight - obstacleGap, playerGap));
obstacles.remove(obstacles.size()-1);
lastLineScored++;
}
}
}
public void draw(Canvas canvas){
for(Obstacle ob : obstacles)
ob.draw(canvas);
Paint paint = new Paint();
paint.setTextSize(100);
paint.setColor(Color.GREEN);
canvas.drawText("" + score , 50, 100 + paint.descent()- paint.descent(), paint);
EDIT4 : 장해 관리자 http://pastebin.com/6E77QtHj O bstacle http://pastebin.com/p33mPrat
이 게시물을 편집했습니다. 그게 Y 좌표 야? –
@nilsllucans - 문자의 Y 좌표이면 yes입니다. 그러나 마지막 줄만 테스트하기 때문에 내 대답은 잘못되었습니다. (내 대답은 당신이 "lines"을 언급했을 때'obstacles' 배열의 요소와 같은 것이라고 가정합니다.) –
@nilsllucans - 버그를 수정하기 위해 답을 업데이트했습니다. –