Introduction
Ok, I've worked on this platformer in 2 days now,
and thought it was nice to have as a foss script.
If you thinking on using this script it would be nice if
take alook at the script and try to understand it!
How does it work?
This is a unbugable (i hope, i have had many betatesters)
platform engine that only support right square platforms.
its smooth and it got a nice slide effect when walking.
and you can have as many platforms you want.
How do I use it?
Make a caracther, it needs no instance name.
Covert it to a Movieclip, and all the script is going inside this MC.
Now you must just make as many platforms as you need,
and this is important, to get the platformers to work you must
name them: p1, p2, p3, p4, p5..etc... And in the very start of the code you will
see a variable that says: var platforms:Number = 1; change the number to
how many platforms you have.
So, where's the code?
onClipEvent (load) {
var platforms:Number = 1;
var fall:Number = 0;
var gravity:Number = 15;
var speed:Number = 0;
var maxSpeed:Number = 8;
var jump:Boolean = true;
var jumpSpeed:Number = 0;
var jumpHeight:Number = 8;
}
onClipEvent (enterFrame) {
_y += fall;
if (fall<gravity) {
fall++;
} else {
fall = gravity;
}
_x += speed;
if (Key.isDown(key.RIGHT)) {
if (speed<maxSpeed) {
speed++;
}
} else if (Key.isDown(key.LEFT)) {
if (speed>-maxSpeed) {
speed--;
}
} else {
if (speed<0) {
speed++;
} else if (speed>0) {
speed--;
}
}
if (Key.isDown(key.UP) && !jump && fall<3) {
jump = true;
}
if (jump) {
if (jumpSpeed>0) {
_y -= jumpSpeed;
jumpSpeed -= 0.5;
fall = 0;
} else {
jump = false;
}
} else {
jumpSpeed = 0;
jumpSpeed = jumpHeight;
}
for (i=1; i<=platforms; i++) {
if (hitTest(_root["p"+i])) {
if (_x<_root["p"+i]._x-_width+speed || _x>_root["p"+i]._x+_root["p"+i]._width+spe
ed) {
if (_x<_root["p"+i]._x-_width+speed) {
_x = _root["p"+i]._x-_width;
speed = 0;
}
if (_x>_root["p"+i]._x+_root["p"+i]._width+sp
eed) {
_x = _root["p"+i]._x+_root["p"+i]._width;
speed = 0;
}
} else {
if (_y<_root["p"+i]._y-_height+fall || _y>_root["p"+i]._y+_root["p"+i]._height+fa
ll) {
if (_y<_root["p"+i]._y-_height+fall) {
_y = _root["p"+i]._y-_height;
jump = false;
fall = 0;
}
} else if (_y>_root["p"+i]._y+_root["p"+i]._height-j
umpSpeed) {
if (!jump) {
fall = jumpSpeed;
} else {
_y = _root["p"+i]._y+_root["p"+i]._height;
fall = 2;
}
jumpSpeed = 0;
jump = false;
} else {
if (_x<_root["p"+i]._x-_width+(_root["p"+i]._
width/2)) {
_x = _root["p"+i]._x-_width;
} else {
_x = _root["p"+i]._x+_root["p"+i]._width;
}
}
}
}
}
}
WARNING
There is gonna be some errors in the script because of
the auto format here on NG BBS. So if you want fully code, you
can get it from here: FULL SCRIPT!
Can we see an example
Sure, right here: PLATFORM EXAMPLE!
Questions?
Just post them here, if you are wondering about how
anything in the script works.