00:00
00:00
Newgrounds Background Image Theme

Mekatov 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: Game (part 1)

12,588 Views | 27 Replies
New Topic Respond to this Topic

AS: Game (part 1) 2005-07-26 17:41:32


I quote a brillianbt man when I say "its better then sex with a n00b"

AS: Game part 1

I was thinking of an AS: to do and couldnt really find anything that hasnt already been covered (Damn you inglor making everything so good!).
Anyways I though I might go ahead and make a little project to do using the AS: topics as help. In the end of this we will be making a nice little game using many of the topics covered in AS: MAIN and hopefully will give everyone a good understanding on practical uses of the AS: MAIN topics.

To start...

so lets begin shall we?

For starts make a hero. Draw him and then convert him to a movieClip. Lets give him the instance name hero.Also make sure his registration point is in the middle of his x axis at his feet. Also make sure he is facing right side on.Now in this tutorial we wont bother with animating him (because this is a purely AS tutorial and I dont want to waste much time). It should be easy for you to slot the animation code in anyways.

Type the following code into the actions panel

onClipEvent (enterFrame) {
}

Im sure we know what this does if not then this should be useful.

"Moving" on

Okay to make our guy move we are going to make a function! If you are unsure with these please read this first.

On the main time line put the following code

function hero_move(target, speed):Void {
with (target) {
_x -= Key.isDown(Key.LEFT)*speed-Key.isDown(Key.
RIGHT)*speed;
}
}

Basically what this does is makes a new function called hero_move . The parameters for the function are target and speed. There is no return. When the function is run it tells the target to respond to this.

_x -= Key.isDown(Key.LEFT)*speed-Key.isDown(Key.
RIGHT)*speed;

If you are unsure of binary increasement then read
this .

Now we have our function written we can go and call it from our hero.

Yey finally something that works

Thats right we are about to have amoving man (WOOPEDY DOO). Go onto the hero and replace his current code with the following:

onClipEvent (enterFrame) {
_level0.hero_move(this,10);
}

Dun dun dun OMG it is soooo complicated. Basically it just calls the function and sets the target to this (itself) and speed to 10. I think setting speed to be 10 all the time kind of eliminates the point of having the variable even accessable as a parmeter so lets make that a variable. Replace the code with this:

onClipEvent (load) {
var speed:Number = 10;
}
onClipEvent (enterFrame) {
_level0.hero_move(this, 10);
}

if you are unsure of variables and how they work here is a VERY vague explanation of them.
(I cant be assed with HTML ANYMORE)

http://www.newground../topic.php?id=297928

Now you can press Ctrl + ENTER and voila a moving man! (left and right arrows)

Sure hes a moving man but hes not very interesting yet is he?

A step UP!

Now here is where it gets WILD!

Lets make our little guy jump!

Another function I think...

On the main time line (again frame 1) put the following:

function hero_jump(target, height):Void {
with (target) {
if (Key.isDown(Key.UP)) {
if (!jumping) {
gravity = height;
jumping = true;
}
}
if (jumping) {
this._y -= gravity;
gravity--;
if (gravity == -height) {
jumping = false;
}
}
}
}

This is again pretty straight forward and all you need do is read it carefully.

So now we have our hero_jump function we can call it in our little man...

add this to his onClipEvent...

_level0.hero_jump(this, height);

and this to the onLoad

var height:Number = 20

horrah we have an all moving all jumping man! But wait...

on testing the movie dont you find it appauling that he jumps and moves oh so very slowly and jaggedly...

Just set the fps to 30fps and we're good to go!

Beutiful. Well no. Where the hell is the floor?!

Getting "on top" of things

Well now we have our beloved man and his super powers of jumping! Wait a minuit... Where is the floor?!
Ever heard of a hitTest? Well if not then you should seriously think about reading this.

http://www.macromedi..t_dictionary534.html

So lets make a floor. We could make a naf flat floor (no alliteration intended) but that is boring. Lets draw a nice curvey line for a floor. Here is an excellent tutorial covering most of what we are about to do.

http://www.newground../topic.php?id=293653
<-------- BRILLIANT EXAMPLE

Draw your wavy floor (not too steep waves) and make the instance name floor *shocking*.
(obvously on the main stage) Now here is where you MUST be careful. Go into the hero MC and draw a little square right at his feet. Convert it into and MC and give it the instance name feet.
Now add this function to the timeline:

function hero_land(target):Void {
with (target) {
while (_root.land.hitTest(point.x, point.y, true)) {
_y -= 1;
point.y -= 1;
}
_y += 10;
var point:Object = new Object();
point.x = feet._x;
point.y = feet._y;
localToGlobal(point);
}
}

If you dont know what is going on here read the link I mentioned above and for further info on the while loop read this.

http://www.newground../topic.php?id=311428

or
http://www.newground../topic.php?id=296699
for all the loops (almost)

Now put the following code into the onEnterFrame of the hero...

_level0.hero_land(this);

OMG that is smarts!!!

okay now you have an all jumping all landing all cooly hero

well you can mess around with the variables and stuff whilst I write the next part of this tutorial please ask any questions / critisms below and please I like praise heh.

Coming soon -- next part of this tutorial

LINKS

the one useful link to rule them all
A PLUG
A bookmark
And most importantly
THE LINK

full chars too


- Matt, Rustyarcade.com

Response to AS: Game (part 1) 2005-07-26 17:59:18


it's not how I do it, but it's a very nice structure :) good work

Response to AS: Game (part 1) 2005-07-26 18:09:17


At 7/26/05 06:04 PM, SpamBurger wrote: The only thing is, your movement code seemed very wacked. Couldnt you of just set the varialbels and do something like this?

if(Key.isDown(Key.UP)) {
_y-=speed;
}

Thats much more simple. But, hey, whatever suits you best!

Yes well I wanted to do it this way for 2 reasons
1) it gives me a use of one of the AS topics (which is the whole point) and
2) it is simpler and quicker


- Matt, Rustyarcade.com

Response to AS: Game (part 1) 2005-07-27 07:29:16



- Matt, Rustyarcade.com

Response to AS: Game (part 1) 2005-09-06 09:59:50


AS n00b:
when i jump so does the floor
what do i do?

Response to AS: Game (part 1) 2005-09-06 10:45:23


At 9/6/05 09:59 AM, -memartyo- wrote: AS n00b:
when i jump so does the floor
what do i do?

maybe you put the function in the floor by mistake ??? Just read throuhg it again at the part you screwed up


- Matt, Rustyarcade.com

Response to AS: Game (part 1) 2005-09-06 11:26:47


At 7/26/05 06:04 PM, SpamBurger wrote: if(Key.isDown(Key.UP)) {
_y-=speed;
}

Binary increasment way is far better.

Response to AS: Game (part 1) 2005-09-06 11:34:08


At 9/6/05 11:26 AM, T-H wrote:
At 7/26/05 06:04 PM, SpamBurger wrote: if(Key.isDown(Key.UP)) {
_y-=speed;
}
Binary increasment way is far better.

well im going to have to disagree with you there because this way alows animation and stuff much easier but in this situation yes it was


- Matt, Rustyarcade.com

Response to AS: Game (part 1) 2005-09-06 11:42:02


But for that you can just do a seperate if(kLeft){.... to handle the animation/x scaling/other properties.

Response to AS: Game (part 1) 2005-09-06 11:52:12


At 9/6/05 11:42 AM, T-H wrote: But for that you can just do a seperate if(kLeft){.... to handle the animation/x scaling/other properties.

true but that would over complicate things I geuss


- Matt, Rustyarcade.com

Response to AS: Game (part 1) 2005-12-01 16:30:37


but stills. nice AS tutorial, helps out

Response to AS: Game (part 1) 2006-01-04 05:19:33


At 9/6/05 10:45 AM, Ninja-Chicken wrote:
At 9/6/05 09:59 AM, -memartyo- wrote: AS n00b:
when i jump so does the floor
what do i do?
maybe you put the function in the floor by mistake ??? Just read throuhg it again at the part you screwed up

my floor also jumps...
NOT ONLY the floor, everything i drew jumps. lol

and i don't have a script in them :P

Response to AS: Game (part 1) 2006-01-10 20:29:15


Crapping movement code ai'nt working. O well guess I'll use a different code for the movement.

Response to AS: Game (part 1) 2006-01-21 17:43:52


AAAAAH seriosuly-my char keeps on falling and my ground jumps...what the hell do I do???

Response to AS: Game (part 1) 2006-05-01 01:36:06


same as previous poster, my land jumps and my man keeps falling, whats going on, i followed the tutorial exactly.

Response to AS: Game (part 1) 2006-05-13 18:44:51


I get the same thing floor dont work and it jumps... he must of forgot to add somthing..

Response to AS: Game (part 1) 2006-07-25 13:56:46


My floor also moved, but I realised something. In this:

function hero_jump(target, height):Void {
with (target) {
if (Key.isDown(Key.UP)) {
if (!jumping) {
gravity = height;
jumping = true;
}
}
if (jumping) {
this._y -= gravity;

gravity--;
if (gravity == -height) {
jumping = false;
}
}
}
}

function hero_jump(target, height):Void {
with (target) {
if (Key.isDown(Key.UP)) {
if (!jumping) {
gravity = height;
jumping = true;
}
}
if (jumping) {
_root.hero._y -= gravity;
gravity--;
if (gravity == -height) {
jumping = false;
}
}
}
}

This has to be replaced....but now....it jumps but it doesn't stops when the hero hitTest's the florr :S

Response to AS: Game (part 1) 2006-08-12 19:27:15


Now put the following code into the onEnterFrame of the hero...

_level0.hero_land(this);

OMG that is smarts!!!

Ive done every thing right until i enter in this code.
EG. my guy can move, he can jump but the ground is'nt reconised yet
until i enter in this code, right?
Well, when i do enter it in and play the game, i just fall behind the ground and down
into infinity. Its not reconised as a wall.
Why?
I cant explain it. Ive tried re-doing everything you sid several times, but with the same result.

Can you please help me??


This is my Signature. Signature it is.

Response to AS: Game (part 1) 2006-08-13 07:50:00


Please??


This is my Signature. Signature it is.

Response to AS: Game (part 1) 2006-08-27 10:29:49


shitty tut nothing works and u let others explain with this hundred links just say WHERE to put WHAT!!!! >:((((((

Response to AS: Game (part 1) 2006-10-08 06:30:03


This is fairly straight forward...
All the function codes go in the main timeline, whilst all other codes go into objects defined by the poster.

thanks.

Response to AS: Game (part 1) 2007-03-02 15:00:11


Too bad NC is now a greedy emo site-whoring fucker. :P


BBS Signature

Response to AS: Game (part 1) 2008-01-12 13:35:47


:(

It wont jump... i dont get were to put the stuff FOR jumping...

could i get a picture? like a screenshot?


YOU GOT RICK-ROLLED!

fuck

Response to AS: Game (part 1) 2008-01-12 13:36:59


At 8/27/06 10:29 AM, Asterwix wrote: shitty tut nothing works and u let others explain with this hundred links just say WHERE to put WHAT!!!! >:((((((

you mean shitty user who is a fucking idiot?

I agree, you are a shitty user who is a fucking idiot...

moving on...


YOU GOT RICK-ROLLED!

fuck

Response to AS: Game (part 1) 2008-01-12 13:43:24


1. Why post in a year old thread? Its against the rules.
2. Rusty is not shitty >:(

Response to AS: Game (part 1) 2008-01-12 13:50:24


At 1/12/08 01:43 PM, UnknownFury wrote: 1. Why post in a year old thread? Its against the rules.
2. Rusty is not shitty >:(

1. Didnt look at the year-old part... and i wasnt trying to break the rules...

2. Rusty CAN be shitty >:(


YOU GOT RICK-ROLLED!

fuck

Response to AS: Game (part 1) 2008-01-12 14:11:58


Oh wow I said that? -_-"


BBS Signature