00:00
00:00
Newgrounds Background Image Theme

Demons202 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!

AS: Platformer engine

1,177 Views | 22 Replies
New Topic Respond to this Topic

AS: Platformer engine 2007-07-02 01:09:05


Yay!I've finaly made a platformer engine using while commands.You can make walls+slopes+curved slopes+celings....what else?
So i decided to share it with u guys:
First, draw your character.Make his width about 50 px and his height about 50 px (optional)
Now copy and paste this code into the character:
onClipEvent (load) {
speed = 10;
grav = 0;
jump = 20;
jumph = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x = _x-speed;
}
if (Key.isDown(Key.RIGHT)) {
_x = _x+speed;
}
if (Key.isDown(Key.UP)) {
jumph = true;
}
_y = _y+grav;
if (!_root.ground.hitTest(_x, _y, true)) {
grav = grav+2;
} else {
}
if (jumph) {
_y = _y-jump;
}
while (_root.ground.hitTest(_x, _y+18, true)) {
_y--;
grav = 0;
jumph = false;
}
while (_root.ground.hitTest(_x, _y-18, true)) {
_y++;
jumph = false;
}
while (_root.ground.hitTest(_x+18, _y-18, true)) {
_x--;
}
while (_root.ground.hitTest(_x-18, _y-18, true)) {
_x++;
}
}

Now draw your platforms on the main stage(BTW, you can draw walls,celings,slopes and curved slopes too!).Select all of your platforms(yes,ALL)
and convert them in ONE BIG MOVIE CLIP.Copy and paste this code into that movieclip:
onClipEvent (load) {
_name = "ground";
}

Now test your game.Its should work fine.BTW, if your slope is too steep, your character will slide down!
Here a DEMO SWF:
http://denvish.net/ulf/020707/47270_Platforme r_engine.php

Hope this helped!

Response to AS: Platformer engine 2007-07-02 01:21:08


It... Doesn't slide. Lmao

fail

Response to AS: Platformer engine 2007-07-02 01:25:30


At 7/2/07 01:09 AM, Carpo-ink wrote: if your slope is too steep, your character will slide down!

IF.


BBS Signature

Response to AS: Platformer engine 2007-07-02 01:32:23


Would have been nice to prove that
IF with a steep enough slope. =D

Response to AS: Platformer engine 2007-07-02 01:45:28



BBS Signature

Response to AS: Platformer engine 2007-07-02 01:51:27


At 7/2/07 01:45 AM, Kuoke wrote: I was bored.

Lmfao, I jumped underneath the circle and you can ride around and around it =D


asdfg

BBS Signature

Response to AS: Platformer engine 2007-07-02 01:54:37


At 7/2/07 01:39 AM, LCurtis wrote: If you hold up and hit a ceiling you slide along it. Maybe you can fix that.

errr......that does not usualy happens unless your celing is curved(The script will tell the character to be pushed to one side while blotting out the bouncing off the celing code)
I cant fix that, if i do , most of the code will be ruined.
OR i can re-write the whole thing, k guys?

Response to AS: Platformer engine 2007-07-02 02:06:12


Ok, new code,this time it BOUNCES off the ceiling though the UP key is held:
this is for the player:

onClipEvent (load) {
speed = 10;
grav = 0;
jump = 20;
jumph = false;
jumpp = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x = _x-speed;
}
if (Key.isDown(Key.RIGHT)) {
_x = _x+speed;
}
if (Key.isDown(Key.UP)) {
if(!jumpp){
jumph = true;
jumpp = true;
}
}
_y = _y+grav;
if (!_root.ground.hitTest(_x, _y, true)) {
grav = grav+2;
} else {
}
if (jumph) {
_y = _y-jump;
}
while (_root.ground.hitTest(_x, _y+18, true)) {
_y--;
grav = 0;
jumph = false;
jumpp = false;
}
while (_root.ground.hitTest(_x, _y-18, true)) {
_y++;
jumph = false;
}
while (_root.ground.hitTest(_x+18, _y-18, true)) {
_x--;
}
while (_root.ground.hitTest(_x-18, _y-18, true)) {
_x++;
}
}

ground code remains the same.

Response to AS: Platformer engine 2007-07-02 02:38:33


At 7/2/07 02:08 AM, LCurtis wrote: Now change it so that the code is added to the frame and put into cleaner functions. Also data type your variables and you will have a much nicer engine. 'Course you dont have to ...

So many noobs are gonna ctrl-c this!

How would one go about strictly typing ones variables for an external object from the frame? It'd be mighty great if you could help me out with that.

var blah:Number;

You seem to know, so pass on your knowledge!


These new signatures can suck on mah balls. My lolis don't fit in. Lol wut what are you guys still doing on NG, move on.

BBS Signature

Response to AS: Platformer engine 2007-08-06 10:18:29


Please!
If you make an AS code for guys who want to use it... then please explain it :/
i can't undetstand if (!_root.ground.hitTest(_x, _y, true)) { or something Oo
i want to make an platformer and used only for "fall" the AS:

onClipEvent (load) {
gravity = 0.5;
fall = 0;
jump = 0;
}
onClipEvent (enterFrame) {
_y += fall;
if (this.hitTest(_root.ground)) {
fall = 0;
} else {
fall += gravity;
}
}

the character don't fall and i dont know why ... i put him out of the map and he falls.. maybe the character dont fall because he touches the "scaling box" of the editor mode... because of that u must explain me how the AS works .. please...


Did you know Wampo is a river in south africa?

Unbelieveble :O

Response to AS: Platformer engine 2007-08-06 10:32:35


Pretty cool lol


BBS Signature

Response to AS: Platformer engine 2007-08-06 11:30:35


At 8/6/07 10:32 AM, PyroflameProductions wrote: Pretty cool lol

Pretty bump lol

</sarcasm>

Response to AS: Platformer engine 2007-11-09 20:10:34


Could someone please make a version of this code that is 1st person? (i.e. The player is stationary while the ground and everything else moves)

Seems simple enough, but some glitch happens when I change:

while (_root.ground.hitTest(_x, _y, true)) {

_y--
grav = 0;
jumph = false;
}

- to -

while (_root.ground.hitTest(_x, _y, true)) {

_root.gound._y++
grav = 0;
jumph = false;
}
.

Anyone???


.

Response to AS: Platformer engine 2007-11-10 05:27:20


just get a v cam

Response to AS: Platformer engine 2007-11-10 06:05:13


how can i make it so he has a turret on his body and it shoots

Response to AS: Platformer engine 2007-11-10 07:49:23


you should use action script 3.
I've made a kick ass platformer engine with that.
It has:
+Pause Menu with Quit functionality
+Tile based objects,BUT can be placed anywhere on any pixel
+Deletes tiles when they move off screen and loads tiles when they come on screen
+A level editor that I made so I can make levels easily(I choose, delete, save, position, chose collision type via my level editor)
+Custom made collision detection
+Dynamic player animation(walk, running, jump, push against wall, fall)
+Trigger objects(walk in area or swith)
+Custom built layer control (Made this so I can control which tiles over lap each other, instead of the lastest generated object is above all other objects)
+Health(still need to program death though)
+Dynamic camera which the world moves in relation to(so all objects use my custom worldx or worly variable instead of x. By seeing where the camera is, they can translate where they are on the stage.)
+Its a couple hundred lines of code!
+Runs incredibly smoothly in browser, even when there other 350 objects in a level!

Moral of story is USE ACTION SCRIPT 3!
:p

Response to AS: Platformer engine 2007-11-10 08:05:35


cool. i needed somthing to refine my platofrmer. I alreasd coded it, but the walls dont work, so il tyre this one! thanks man!


If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

Response to AS: Platformer engine 2007-11-10 08:25:40


good explanation for your code. im sure all of teh noobs will understand it

<sarcasm>


thanks, dr34m3r, for the sig!

BBS Signature

Response to AS: Platformer engine 2007-11-10 08:30:51


At 7/2/07 02:06 AM, Carpo-ink wrote: Ok, new code,this time it BOUNCES off the ceiling though the UP key is held:
this is for the player:

samapling?


thanks, dr34m3r, for the sig!

BBS Signature

Response to AS: Platformer engine 2007-11-10 08:34:43


I MEANT SAMPLING LOLZORS!!


thanks, dr34m3r, for the sig!

BBS Signature

Response to AS: Platformer engine 2007-11-10 08:59:39


At 11/10/07 07:49 AM, DemandingStudios wrote: you should use action script 3.
I've made a kick ass platformer engine with that.
It has:
+Pause Menu with Quit functionality
...
+Its a couple hundred lines of code!
+Runs incredibly smoothly in browser, even when there other 350 objects in a level!

Moral of story is USE ACTION SCRIPT 3!
p

That sounds cool and all, but could you post an example to see how well it works?
(You could post the source, too. Many people might be interested in how you mad a tile engine in AS 3)

Response to AS: Platformer engine 2007-11-10 09:11:17


At 11/10/07 08:59 AM, Dasuraga wrote:
At 11/10/07 07:49 AM, DemandingStudios wrote: you should use action script 3.
I've made a kick ass platformer engine with that.
It has:
+Pause Menu with Quit functionality
...
+Its a couple hundred lines of code!
+Runs incredibly smoothly in browser, even when there other 350 objects in a level!

Moral of story is USE ACTION SCRIPT 3!
p
That sounds cool and all, but could you post an example to see how well it works?
(You could post the source, too. Many people might be interested in how you mad a tile engine in AS 3)

Hmm, I dont really want post the source or game on the net until its done, but I think I'll make a thread about it with some annotated pics + some example source code.

Response to AS: Platformer engine 2008-01-03 16:13:26


yep!! this helps allot!!!

JUST WHAT I'M LOOKING FOR!!!!!


<sarcasm> Yeah thats great.</sarcasm>