Hi there,
I know this question must have been asked a zillion times, but the search function didn't give me any useful advice on how to do this. So I'm asking AGAIN:
Is there a way to execute a loop (repeat, while, for etc.) inside an event? I need that for slope detection in a platformer since I want to avoid using too many detectors. I wrote the following algorithm in c/pseudo code to illustrate what I am planning to do:
Can this be done with mmf2? I don't care if it's dirty, as long as it's reliable and can be used for players and enemies as well. If you have any good ideas about this, please let me know.Code:Slope detection: I am using fast loops to move the player one pixel at a time. When the player overlaps with the background we have to check if there is a free position available that is no more than X pixels (three, for instance) above the current position, which _should_ be done with a loop: Example: ### #### # = Background ##### P = Player ##### P #######P ################################## Now, when the player moves one pixel to the left, the following code will be executed: ------------------------------------------------------ if (player overlaps with obstacle) { if (player is moving left) { int x = player.leftX; int backwards = +1; } elseif (player is moving right) { int x = player.rightx; int backwards = -1; } for (int i = 1; i <= 3; ++i) // repeat the following block three times and increase i by 1 each cycle: { if (getObjectAtPosition(x, player.lowerY + i) is not an obstacle) { player.Y += i; // slope found, move player up return true; } } //for // no slope, player goes back where he came from player.x += backwards; return false; } //if } //if
Thanks in advance,
lincore



Reply With Quote



