I have a Pong game with a level editor (as long as you have the source code) where you can put walls where you want. There are also walls that only balls hit by the player can pass through, walls that only balls hit by the Cpu can pass through, and invisible walls. I'm trying to add in moving walls, and so far, my idea is this:
A character 'm' signifies a moving wall, and '-'s represent the path it will move on.
'm's ID is 4, a '-'s ID is 5.
The method to move the walls is:
public void moveMovingWalls()
{
for (int j=0; j<StaticPong.NUMBEROFLINES; j++) {
for (int i=0; i<StaticPong.NUMBEROFCOLUMNS; i++) {
if (elementArray[j][i] != null && elementArray[j][i].getID() == 4) {
Path element = new Path(Color.gray, 5);
elementArray[j][i] = element;
if (j+1<StaticPong.NUMBEROFLINES && elementArray[j+1][i] != null && elementArray[j+1][i].getID() == 5) {
MWalls element2 = new MWalls(Color.yellow, 4);
elementArray[j+1][i] = element2;
}
else if (j>0 && elementArray[j-1][i] != null && elementArray[j-1][i].getID() == 5) {
MWalls element2 = new MWalls(Color.yellow, 4);
elementArray[j-1][i] = element2;
}
else if (i+1<StaticPong.NUMBEROFCOLUMNS && elementArray[j][i+1] != null && elementArray[j][i+1].getID() == 5) {
MWalls element2 = new MWalls(Color.yellow, 4);
elementArray[j][i+1] = element2;
}
else if (i>0 && elementArray[j][i-1] != null && elementArray[j][i-1].getID() == 5) {
MWalls element2 = new MWalls(Color.yellow, 4);
elementArray[j][i-1] = element2;
}
}
}
}
}
I want it to move the 'm' along the path in a clockwise fashion, and only move each moving wall one space each time.
This works in that it looks for a 'm' and then scans around the 'm' for '-'s and then moves the 'm' to the dash if it finds one. The problem here is that after the 'm' is moved, then if the 'm' was moved right or down the loop will hit it again and move it again, so it will be moved more than once.
For example (':'s are empty):
m--
-:-
-:-
---
Then the m would be move down to the second dash because the loop would move it to the bottom then recognize the dash above it and move it back up. After that it wouldn't move again - it would keep going down then back up.
So does anybody have help with this? I was thinking boolean flags like maybe a "hasMoved" to keep it from moving more than once, but the problem with that is then you would only be allowed one moving wall on the map.
>_<.