Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Platformer code; help?
Topic Started: Oct 24 2004, 11:44 PM (280 Views)
Nodron Simpleton
Member Avatar
Original Brackenwoodian
can someone help me with the basic code of a platformer?
Offline Profile Quote Post Goto Top
 
BonzaiRob
Member Avatar
The Demon Plasterer
this is about as basic as it gets... here we have a movieclip, the contollable character, named Rob. There needs to be a movieclip labelled ground for the jump script to work properly. Now, here's the code to put in the movieclip called rob:
Code:
 
onClipEvent (keyUp) {
tellTarget ("_root.rob") {
gotoAndStop(1);
}
}

onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
 this.gotoAndStop(4)
}
}



onClipEvent (enterFrame) {
if (Key.isDown(Key.CONTROL)) {
 this.gotoAndStop(5)
}
}

onClipEvent (load) {
// Set the move speed
moveSpeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
this.gotoAndStop(3);


// Move Right


} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
this.gotoAndStop(2);
// Move Left
}
}

onClipEvent (load) {
jumping = false;
jSpeed = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE) && !jumping) {
 jumping = true;
 jSpeed = 10;
}
if (jumping) {
 this._y-=jSpeed;
 jSpeed--;
 if (this.hitTest(_root.ground)) {
  jumping = false;
  jSpeed = 0;
  this.gotoAndStop(1);
 }
}
}
onClipEvent (enterFrame) {
if (this._x > 650.0) {
this._x = 0;
}
if (this._x < 0) {
this._x = 650.0;
}
if (this._y > 400) {
this._y = 0;
}
if (this._y < 0) {
this._y = 400;
}
}



Okay... in the first frame of the mc, you want a movieclip or graphic of Rob standing (mine has him swaying). The second and third are MCs of him walking left and right respectively. The fourth frame is of him jumping, the fifth I have him punching.
This is only the code for the movement of the character, so punches will need to be worked ouyt. Also, if the character walks off the groiund MC they float like in a cartoon, because it's a jump effect and not gravity. Perhaps there could be somepthing like if{hitTest = false} for him to fall off.

I'm BonzaiRob, a weird English student who's a jack-of-all-trades. Brackenwood rocks.
Offline Profile Quote Post Goto Top
 
Nodron Simpleton
Member Avatar
Original Brackenwoodian
thanlks and welcome!
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply