## As : Platformer

• 8,625 Views
• 55 Replies
Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
As : Platformer 2006-05-28 15:08:30

What you will be making- http://denvish.net/u..mer%20Code%20001.swf

As: Main

Preperation
Draw your character. Convert it into a movieclip, and make sure the + is on the bottem middle.
Make your ground and convert that into a movieclip. Give it the instance name of "ground" without the quotes. The ground can be anything, make it all in one movieclip., The code checks for walls and ceiling and floors by itself. Lucky you.

The Script
Click on your character, and go to actions. Now copy and paste this into him.
The // start a comment, they dont affect the script

// thanks to Vengance for helping
grav = 0;
// sets falling speed
speed = 7;
// sets movement speed
jumpHeight = 15;
// sets height that you can jump
scale = _xscale;
// sets size
slowfall = .8;
// sets glide
}
onClipEvent (enterFrame) {
// happens every frame
grav++;
// makes you fall faster
_y += grav;
// makes your _y go up by the varaible grav
while (_root.ground.hitTest(_x, _y, true)) {
// when this is touching the ground
_y--;
// makes the y keep on going up, this enables slopes
grav = 0;
// make it so you dont fall
}
if (Key.isDown(68)) {
// when the d key is down
_x += speed;
// makes the x go up by the speed
_xscale = scale;
// makes it face right
if (_root.ground.hitTest(_x, _y+3, true)) {
// if it is touching the ground
this.gotoAndStop(1);
// goes to frame 1
} else {
// otherwise
this.gotoAndStop(2);
// stops at frame 2
}
} else if (Key.isDown(65)) {
// if that isnt happening and the a key is pressed
_x -= speed;
// makes the x go gown by the speed
_xscale = -scale;
// makes it face left
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
// see other code for movign right
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79)) {
// if this is touching the ground and o isnt pressed
this.gotoAndStop(3);
// stops at frame 3
}
}
if (Key.isDown(83)) {
// if the s key is down
grav *= slowfall;
// slows down the gravity by multiplying it by the slowfall varialbe
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68)) {
// if 0 is down, and a s d w arent
this.gotoAndStop(4);
// goes to frame 4
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
// if w is pressed and it is touching the ground
grav = -jumpHeight;
// makes gravity negative jumpheight, causes jump
_y -= 4;
// makes the y go up by 3
this.gotoAndStop(2);
// stops on frame 2
}
if (_root.ground.hitTest(_x+(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2), _y-((_height/6)*4), true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2), _y-((_height/6)*4), true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height, true)) {
grav = 2;
}
// these all check for 2 points along the sides and top, to see if it is hitting a wall
}

How It Works
Well, first off the code makes the player go down by gravity. Gravity goes up every second, making the player fall faster. When the player touches the ground, gravity is reset to zero.

Then when the player presses the W key. Gravity is at negititve jump height. So the player will go up. But because gravity is goin up, the jump goes down. so gravity will be -14, -13, -12, -11, ect. that means it is going up. then it hits 0, and then 1, 2,3 and the player starts to fall again.

Paranoia
Paranoia
• Member since: Apr. 22, 2005
• Offline.
Forum Stats
Member
Level 35
Game Developer
Response to As : Platformer 2006-05-28 15:16:46

Hey, i wanted to to a platformer thread >:|

GustTheASGuy
GustTheASGuy
• Member since: Nov. 2, 2005
• Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As : Platformer 2006-05-28 15:18:24

You aren't very good with multiple hittests, huh.

DX14
DX14
• Member since: Oct. 4, 2005
• Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As : Platformer 2006-05-28 16:14:18

WOW, i think this is a great attempt at a platformer, and u dont get stuck with boring old squares for the ground, thx for that!!!

D.

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-05-29 08:43:14

At 5/28/06 03:18 PM, -Gust- wrote: You aren't very good with multiple hittests, huh.

What do you mean? I could have done it differntly, but I didnt. And I have never seen you say something nice. You also have no flash, and I havent seen any of your code, so I have no idea how good you are.

Trunks
Trunks
• Member since: Jul. 31, 2005
• Offline.
Forum Stats
Member
Level 22
Musician
Response to As : Platformer 2006-05-30 16:16:05

At 5/29/06 08:43 AM, pyro111 wrote:
At 5/28/06 03:18 PM, -Gust- wrote: You aren't very good with multiple hittests, huh.
What do you mean? I could have done it differntly, but I didnt. And I have never seen you say something nice. You also have no flash, and I havent seen any of your code, so I have no idea how good you are.

Of course he has no examples, he is a poser. He does not have much knowledge with AS. Trust me, he tried out for a flash team I am a part of as an Actionscripter, said he had examples ready that he wouldn't show us, flamed us, and got deleted. He came back and said that he had a flu and was bored, and was sorry. That is like saying if I had the power to kill everyone, I killed everyone because I was bored. It doesn't make much sense. We rejected him, and he has been hating us ever since. And, furthermore, the example he DID end up giving us was stolen.

Web developer, software engineer, musician, all-around nerd.

djdarran
djdarran
• Member since: May. 22, 2006
• Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to As : Platformer 2006-05-30 17:04:20

Awesome script. I've been looking for this type of scipt. You must have some ggod flash. :-D

djdarran
djdarran
• Member since: May. 22, 2006
• Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to As : Platformer 2006-05-30 17:14:35

how do u change it so u press LEFT arrow key instead of D RIGHT arrow key instead of s and UP arrow key instead of whatever it is?

Paranoia
Paranoia
• Member since: Apr. 22, 2005
• Offline.
Forum Stats
Member
Level 35
Game Developer
Response to As : Platformer 2006-05-30 17:15:24

Pfft, I bet I could top this engine in ten minutes, tops!

but not tonight; I'm tired

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-05-30 17:44:02

At 5/30/06 05:15 PM, _Paranoia_ wrote: Pfft, I bet I could top this engine in ten minutes, tops!

but not tonight; I'm tired

Well I see how it is. Conisdering I made it in like 10 minutes. But whatever.

2g4gzus
2g4gzus
• Member since: Mar. 20, 2006
• Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to As : Platformer 2006-05-30 18:53:29

according to someone who sounds more important than you, you're roughly the least trustable person on the planet. Either this took you about 200 years, or you stole it, and either way theres not a single thing that would help a beginner with platform game making, besides the ground.

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-05-30 19:22:18

At 5/30/06 06:53 PM, 2g4gzus wrote: according to someone who sounds more important than you, you're roughly the least trustable person on the planet. Either this took you about 200 years, or you stole it, and either way theres not a single thing that would help a beginner with platform game making, besides the ground.

Ok, I have no idea who you are, but what the hell is wrong with you?
Who is this person who sounds more reliable than me? I have never even talked to you!

This didnt take me 200 years, because it wasnt that hard to make! I didnt steal it, what makes you think that?

And what wont help a begginer? The ground is the whole platform game!

What are you on? According to your posts you know nothing about actionscript. So just leave.

djdarran
djdarran
• Member since: May. 22, 2006
• Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to As : Platformer 2006-05-30 19:32:59

How do you change the controls? Like from a s d w to left up and down?

djdarran
djdarran
• Member since: May. 22, 2006
• Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to As : Platformer 2006-05-30 20:00:32

At 5/30/06 07:35 PM, -Chaz- wrote:
At 5/30/06 07:32 PM, djdarran2 wrote: How do you change the controls? Like from a s d w to left up and down?
replace wherever is says 65 or whatever to Key.UP and Key.Down , same with Key.LEFT and Key.RIGHT

Understand?

Thanks

djdarran
djdarran
• Member since: May. 22, 2006
• Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to As : Platformer 2006-05-30 21:12:13

Wheres the script line that tells A to move it left?

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-05-30 21:20:11

if (Key.isDown(68)) {
// when the d key is down
_x += speed;
// makes the x go up by the speed
_xscale = scale;

Read the comments that tell you aht the code does. Btw- = 65, B=66, C=67, and so on.

seel
seel
• Member since: Jun. 27, 2005
• Offline.
Forum Stats
Member
Level 21
Musician
Response to As : Platformer 2006-06-04 11:32:36

At 5/30/06 06:53 PM, 2g4gzus wrote: according to someone who sounds more important than you, you're roughly the least trustable person on the planet. Either this took you about 200 years, or you stole it, and either way theres not a single thing that would help a beginner with platform game making, besides the ground.

Lol dont be surprised if 2g4gzus is -gust-s alt :)

Anyways good game engine pyro! worked pretty good.

flash-flood01
flash-flood01
• Member since: Dec. 26, 2004
• Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to As : Platformer 2006-06-08 04:28:21

if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68)) {
// if 0 is down, and a s d w arent
this.gotoAndStop(4);
// goes to frame 4
}

whats that for?

Toast
Toast
• Member since: Apr. 2, 2005
• Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As : Platformer 2006-06-08 11:18:27

If you want to know how good Gust is at actionscript, I can assure you he's better than you, and many other flash regs.

At 5/30/06 05:44 PM, pyro111 wrote: Well I see how it is. Conisdering I made it in like 10 minutes. But whatever.

Lol I hate when people try to look serious and intelligent towards sarcasm. We all know you made it in a lot more than 10 minutes, even typing it would take 10 minutes, but we don't care how long it took you as long as it's good. Paranoia was just messing around, perhaps it was not sarcasm but he wasn't exactly serious.

Shroome
Shroome
• Member since: Mar. 19, 2006
• Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As : Platformer 2006-06-08 11:24:27

How do I make the little + go to the bottom?

flash-flood01
flash-flood01
• Member since: Dec. 26, 2004
• Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to As : Platformer 2006-06-09 21:14:58

At 6/8/06 11:24 AM, daaadddoo wrote: How do I make the little + go to the bottom?

What do you mean?

• Member since: Jan. 7, 2005
• Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to As : Platformer 2006-06-09 21:19:16

At 6/9/06 09:14 PM, flash_flood01 wrote:
At 6/8/06 11:24 AM, daaadddoo wrote: How do I make the little + go to the bottom?
What do you mean?

I think he's talking about the mc centerpoint.

Go inside the mc and drag everything in there up.
If it has multiple frames, use the onionskinning multiple frame editing option.

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-07-02 15:11:45

I made the script better(less buggy, better hitTets), and I also added in water (slows you down walking and falling).

To add water, just draw it and give it the instance name of water.

// help by Vengance
// updated on July 2, 2006
var hp:Number = 100;
var maxhp:Number = 100;
var grav:Number = 0;
var speed:Number = 5;
var jumpHeight:Number = 12;
var slow:Number = .7;
// sets water falling speed
var slowspd:Number = speed/1.5;
// sets water walking speed
var setspeed:Number = speed;
var scale:Number = _xscale;
var ex:Number = 5;
// makes hitTests better, change for a closer hitTest (warning, more buggy if smaller)
var dam:Number = 25;
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}
if (_root.water.hitTest(_x, _y, true)) {
if (grav>0) {
grav *= slow;
}
speed = slowspd;
} else {
speed = setspeed;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
this.gotoAndStop(4);
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}
if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-((_height/6)*4), true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-((_height/6)*4), true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height, true)) {
grav = 1;
}
}

• Member since: Jul. 26, 2005
• Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to As : Platformer 2006-07-26 10:24:04

neh! these always fuck me off when i try it out my player always just falls staright through the ground

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-07-26 11:45:14

At 7/26/06 10:24 AM, deadpool15 wrote: neh! these always fuck me off when i try it out my player always just falls staright through the ground

The ground's insance name needs to be ground. Otherwise it wont work.

Paranoia
Paranoia
• Member since: Apr. 22, 2005
• Offline.
Forum Stats
Member
Level 35
Game Developer
Response to As : Platformer 2006-07-26 14:11:13

At 6/8/06 11:18 AM, -Toast- wrote: Paranoia was just messing around, perhaps it was not sarcasm but he wasn't exactly serious.

I'm never serious :)

omg hows that for a late reply?

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-07-26 14:41:53

At 7/26/06 02:11 PM, _Paranoia_ wrote:
omg hows that for a late reply?

Ive seen later.

Those people who bump topics from like 99 or 00.

Ultranova
Ultranova
• Member since: Jun. 10, 2006
• Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to As : Platformer 2006-07-26 15:03:21

Reguarding your original Code, is there anyway you can Add a small Bounce to it? For example, your character is a ball and when it falls to the ground or jumps you want it to bounce when it hits the ground. Is this possible, and please just post that specific code if possible, don't repost the whole thing... Thanks

red-stapler
red-stapler
• Member since: Oct. 24, 2005
• Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As : Platformer 2006-07-26 15:08:35

At 7/26/06 03:03 PM, PixlStudios wrote: Reguarding your original Code, is there anyway you can Add a small Bounce to it? For example, your character is a ball and when it falls to the ground or jumps you want it to bounce when it hits the ground. Is this possible, and please just post that specific code if possible, don't repost the whole thing... Thanks

AS: platformer with slopes by pyro111

Pyromaniac
Pyromaniac
• Member since: Jan. 14, 2005
• Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to As : Platformer 2006-07-26 15:09:38

At 7/26/06 03:03 PM, PixlStudios wrote: Reguarding your original Code, is there anyway you can Add a small Bounce to it? For example, your character is a ball and when it falls to the ground or jumps you want it to bounce when it hits the ground. Is this possible, and please just post that specific code if possible, don't repost the whole thing... Thanks

Of course its possible, but you should try and figure it out yourself. And when you cant, post the code that you did get, and ill help you from there. Also, use the updated code, as it is much better and there are almost no bugs in it.