At 6/15/08 01:20 AM, LuxGamer wrote:
Ive been trying to write something like this forever!!! Can you PM me the code???... lol i know that sounds like im going to copy your work but im not i just wanna study it xP
A simple platformer script, like that, is really easy to make.
Here, I'll share you a code I wrote right now in about 5-6 minutes, yeah it's that easy.
Draw your character, convert to MovieClip, place the registration point (the plus mark) at the bottom, in the middle of his feet. Instance name it: p
Draw your ground and walls and all that shiz, convert to MovieClip. Instance name it: g
Now put this on the frame's ActionScript:
// By GuyWithHisComp - Do NOT remove this line or your head will a splode!
var speed = 6;
var jumpSpeed = 11;
var fallRate = 0.5;
p.onEnterFrame = updatePlayer;
var yspd = 0;
var hitGround = 0;
function updatePlayer ():Void
{
this._x += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT)) * speed;
this._y += yspd += fallRate;
var hitGround = false;
while (g.hitTest(this._x, this._y, true))
{
this._y -= .1;
yspd = 0;
hitGround = 10;
}
while (g.hitTest(this._x, this._y-this._height, true))
{
this._y += .1;
yspd = 1;
}
while (g.hitTest(this._x-(this._width/2), this._y-(this._height/2), true)) this._x += .1;
while (g.hitTest(this._x+(this._width/2), this._y-(this._height/2), true)) this._x -= .1;
if (hitGround-->0 && Key.isDown(Key.UP)) yspd = -jumpSpeed;
_x += (-this._x-_x+275)/4;
_y += (-this._y-_y+200)/4;
}
Couldn't be easier, so little code.