Hello. I have an obstacle class which has three images, one being grass.png. This object will be used to make wall at the top and bottom of the world. A for() loop will be used. How do I make the for() loop?
for(<counter variable init>; <condition to continue>; <counting>) {
// loop code
}
for(int i=0; i<10; i++) { // i++ is the same as i = i + 1;
System.out.println(i);
}
// Inside of your world class
for(int i = <grassWidth> / 2; i < getWidth(); i += <grassWidth>) {
addObject(new Grass(), i, getHeight() - <grassHeight> / 2);
Grass topGrass = new Grass();
topGrass.turn(180);
addObject(topGrass, i, <grassHeight> / 2);
}