Right now this method goes through a list of GameObjects
(e.g. JetPack
, Platform
) with their respective x and y positions in a text file called level1.txt:
platform 840 280
platform 1130 280
coin 900 300
coin 950 300
coin 1000 300
coin 1000 400
jetpack 1090 400
platform 650 500
platform 500 400
platform 200 400
NEXT
platform 200 200
coin 250 300
coin 350 700
What currently happens is whenever my Player reaches the end of the screen, he goes back to the start (x = 0). When he does reach the end of the screen, I want all the objects BEFORE NEXT
to disappear and all the objects AFTER NEXT
to be drawn. I know why my algorithm doesn't work as it should but I'm unsure how to fix it. Can anyone have a look at it and tell me how I can modify it to do what I want it to? list
is a list of GameObjects in the text file btw.
public void loadLevel(String level) {
list.clear();
FileHandle file = Gdx.files.internal(level);
StringTokenizer tokens = new StringTokenizer(file.readString());
while (tokens.hasMoreTokens()) {
String type = tokens.nextToken();
if (type.equals("platform")) {
list.add(new Platform(Integer.parseInt(tokens.nextToken()),
Integer.parseInt(tokens.nextToken())));
}
else if (type.equals("coin")) {
list.add(new Coin(Integer.parseInt(tokens.nextToken()), Integer
.parseInt(tokens.nextToken())));
} else if (type.equals("flag")) {
list.add(new Flag(Integer.parseInt(tokens.nextToken()), Integer
.parseInt(tokens.nextToken())));
} else if (type.equals("jetpack")) {
list.add(new JetPack(Integer.parseInt(tokens.nextToken()),
Integer.parseInt(tokens.nextToken())));
} else if (type.equals("pipe")) {
list.add(new Pipe(Integer.parseInt(tokens.nextToken()), Integer
.parseInt(tokens.nextToken())));
} else if (type.equals("NEXT") && player.getxPos() > SCREEN_WIDTH) {
list.clear();
}
}
}
Any help is highly appreciated, many thanks in advance.