Yay!I've finaly made a platformer engine using while commands.You can make walls+slopes+curved slopes+celings....what else?
So i decided to share it with u guys:
First, draw your character.Make his width about 50 px and his height about 50 px (optional)
Now copy and paste this code into the character:
onClipEvent (load) {
speed = 10;
grav = 0;
jump = 20;
jumph = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x = _x-speed;
}
if (Key.isDown(Key.RIGHT)) {
_x = _x+speed;
}
if (Key.isDown(Key.UP)) {
jumph = true;
}
_y = _y+grav;
if (!_root.ground.hitTest(_x, _y, true)) {
grav = grav+2;
} else {
}
if (jumph) {
_y = _y-jump;
}
while (_root.ground.hitTest(_x, _y+18, true)) {
_y--;
grav = 0;
jumph = false;
}
while (_root.ground.hitTest(_x, _y-18, true)) {
_y++;
jumph = false;
}
while (_root.ground.hitTest(_x+18, _y-18, true)) {
_x--;
}
while (_root.ground.hitTest(_x-18, _y-18, true)) {
_x++;
}
}
Now draw your platforms on the main stage(BTW, you can draw walls,celings,slopes and curved slopes too!).Select all of your platforms(yes,ALL)
and convert them in ONE BIG MOVIE CLIP.Copy and paste this code into that movieclip:
onClipEvent (load) {
_name = "ground";
}
Now test your game.Its should work fine.BTW, if your slope is too steep, your character will slide down!
Here a DEMO SWF:
http://denvish.net/ulf/020707/47270_Platforme r_engine.php
Hope this helped!