00:00
00:00
Newgrounds Background Image Theme

PalmVoe just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Foss:Platformer

1,987 Views | 10 Replies
New Topic Respond to this Topic

Foss:Platformer 2005-11-15 20:29:18


______________________________
The code is explained along the way...

onClipEvent (load) {
scale = _xscale;
jumping = false;
// jumping is true
speed = 0;
// speed is 0
maxmove = 15;
// maxmove is fifteen(max run seed)
_root.maxshoottime = 100;
// _root.maxshoottime is set to 100
// this is how far you want the bullets to travel before deleting
}
onClipEvent (enterFrame) {
if (!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
// if NOT hitting X and Y postion with the ground and NOT jumping
this._y += 6;
// Y positon moves up 6
jump = 0;
// jump is set to 0
jumping = true;
// jumping is set true
}
if (!_root.shooting) {
// if _root.shooting is false
_root.timer = 0;
// _root.timer is set to 0
_root.mvsp = _xscale/20;
// _root.mvsp is set to the chars xscale divided by 20
// the answer to this is the speed of the bullets
}
if (_root.dead) {
// if dead is true
this.gotoAndStop("dead");
// goto and stop on the "dead" frame
} else {
// otherwise (if they are not dead)
speed *= .9;
// speed is multipliued by .98
// the lower the faster is slows
if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
_root.health._x += speed;
// moves the health, the opposite way to the _root
_root.score._x += speed;
// moves the score, the opposite way to the _root
this._x += speed;
// moves the char, the opposite way to the _root
_root._x -= speed;
// moves the _root
}
if (dir == "left" && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
_root.health._x += speed;
// moves the health, the opposite way to the _root
_root.score._x += speed;
// moves the score, the opposite way to the _root
this._x += speed;
// moves the char, the opposite way to the _root
_root._x -= speed;
// moves the _root
}
if (Key.isDown(Key.LEFT)) {
// if left is pressed
if (speed>-maxmove) {
// if the speed is greater than neg. maxmove
speed--;
// speed goes lower
}
dir = "left";
// the var dir is set to left
this.gotoAndStop("run");
// goto and stop the run frame
this._xscale = -scale;
// scale is set to neg. 100
// this is what rotates ur char
} else if (Key.isDown(Key.RIGHT)) {
// otherwise if right is pressed
if (speed<maxmove) {
// if the speed is smaller than maxmove
speed++;
// speed goes up
}
dir = "right";
// the variable dir is set to right
this._xscale = +scale;
// scale is set to 100
// this is what rotates ur char
this.gotoAndStop("run");
// goto and stop the run frame
} else if (speed<1 && speed>-1 && !attacking) {
// if speed is smaller than one and greater than neg. 1
speed = 0;
// speed is set to 0
this.gotoAndStop("idle");
// gotoAndStop the idle frame
}
if (Key.isDown(Key.UP) && !jumping) {
// if up is pressed and NOT jumping
jumping = true;
// jumping is set true
}
if (jumping) {
// if jumping is true
this.gotoAndStop("jump");
this._y -= jump;
// Y position is set down jump
jump -= .5;
// jump is set down .5
if (jump<0) {
// if jump is smaller than 0
falling = true;
// falling is true
}
if (jump<-15) {
// if jump is smaller than neg. 5
jump = -15;
// jump is set to neg 5
// capping fall speeds prevents falling through grounds
}
}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
// if hitting X an Y postions with the ground and falling
jump = 12;
// jump is set to 9
jumping = false;
// jumping is false
falling = false;
// falling is false
}
}
}
onClipEvent (keyUp) {
// on Key Up
if (Key.getCode() == Key.CONTROL) {
// if the release is control
attacking = false;
// attacking is false
}
}FOSS:Main


wat

Response to Foss:Platformer 2005-11-15 20:43:53


could you host a sample?

Response to Foss:Platformer 2005-11-15 21:06:42


Yah.

lable = instance name

Ok,I forgot about this,but make your character movieclip...

Here are the frame orders-

Frame 1 - Idle position,frame has lable of 'idle' and is stopped.
Frame 2 - Running position,frame has lable of 'run' and is stopped.
Frame 3 - Jumping position,frame has lable of 'jump' and is stopped.
Frame 4 - Death position,frame has lable of 'dead' and is stopped.

Make sure that your death position has a movieclip or something with a few frames,and at the last frame is a 'gotoAndPlay' code to continue.

Also,don't forget to make one movieclip and lable it 'ground'

In the sample,run all the way to one side.The ground will come to an end.

wat

Response to Foss:Platformer 2005-11-15 22:00:48


great code just make him fall faster

mess around with initial velocity and acceloration until you get something more realistic

Response to Foss:Platformer 2005-11-16 02:42:10


Yes, nice and smooth script. :)


BBS Signature

Response to Foss:Platformer 2005-11-16 02:56:27


I kinda screwed up and forgot to add the FOSS:Main to the top...errr....hehe...


wat

Response to Foss:Platformer 2005-11-16 08:23:27


looks nice..

Response to Foss:Platformer 2005-11-16 14:52:56


not sure if this problem will affect anything, or if its just a mild error..
if you run too far right, the character goes off screen. shouldnt there be some kinda auto centre thing?

also, he cant step/jump off the platform.


WEBSITE

BLOG ~ Dont fuck around with my dog. All that I can see I steal. ~

NG FFR ~ Automatic for the people.

BBS Signature

Response to Foss:Platformer 2005-11-16 15:10:32


I know.I have an Action Scripted boundary in the Sample ;P


wat

Response to Foss:Platformer 2006-07-12 03:23:36


How do I get my character to shoot when using this script. I see the shooting part of the script, but I cant get it to work.

Response to Foss:Platformer 2006-07-12 05:25:38


At 7/12/06 03:23 AM, nay_size_00 wrote: How do I get my character to shoot when using this script. I see the shooting part of the script, but I cant get it to work.

Use this.