Be a Supporter!

AS: Game (part 1)

  • 10,542 Views
  • 27 Replies
New Topic Respond to this Topic
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
AS: Game (part 1) 2005-07-26 17:41:32 Reply

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

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Game (part 1) 2005-07-26 17:59:18 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Game (part 1) 2005-07-26 18:09:17 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Game (part 1) 2005-07-27 07:29:16 Reply

Hey hey part 2 is here if you have already done this


- Matt, Rustyarcade.com

piefi
piefi
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Game (part 1) 2005-09-06 09:59:50 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Game (part 1) 2005-09-06 10:45:23 Reply

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

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Game (part 1) 2005-09-06 11:26:47 Reply

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

Binary increasment way is far better.

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Game (part 1) 2005-09-06 11:34:08 Reply

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

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Game (part 1) 2005-09-06 11:42:02 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Game (part 1) 2005-09-06 11:52:12 Reply

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

harman-dragon
harman-dragon
  • Member since: Feb. 18, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Game (part 1) 2005-12-01 16:30:37 Reply

but stills. nice AS tutorial, helps out

Vantavo
Vantavo
  • Member since: Apr. 6, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Game (part 1) 2006-01-04 05:19:33 Reply

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

swedekid
swedekid
  • Member since: Jan. 6, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Game (part 1) 2006-01-10 20:29:15 Reply

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

TehPhilippe
TehPhilippe
  • Member since: Dec. 3, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Game (part 1) 2006-01-21 17:43:52 Reply

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

DarkViper
DarkViper
  • Member since: May. 22, 2001
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to AS: Game (part 1) 2006-05-01 01:36:06 Reply

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

Raden101
Raden101
  • Member since: Nov. 23, 2005
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Game (part 1) 2006-05-13 18:44:51 Reply

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

veto2019
veto2019
  • Member since: Sep. 7, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Game (part 1) 2006-07-25 13:56:46 Reply

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

Morgan
Morgan
  • Member since: Jul. 31, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Game (part 1) 2006-08-12 19:27:15 Reply

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.

Morgan
Morgan
  • Member since: Jul. 31, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Game (part 1) 2006-08-13 07:50:00 Reply

Please??


This is my Signature. Signature it is.

Asterwix
Asterwix
  • Member since: Jun. 13, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Game (part 1) 2006-08-27 10:29:49 Reply

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

Rekhyt
Rekhyt
  • Member since: Sep. 4, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Game (part 1) 2006-10-08 06:30:03 Reply

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.
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Game (part 1) 2007-03-02 15:00:11 Reply

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


BBS Signature
Dizeaze
Dizeaze
  • Member since: Dec. 21, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Game (part 1) 2008-01-12 13:35:47 Reply

:(

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

Dizeaze
Dizeaze
  • Member since: Dec. 21, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Game (part 1) 2008-01-12 13:36:59 Reply

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

UnknownFury
UnknownFury
  • Member since: Aug. 10, 2005
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS: Game (part 1) 2008-01-12 13:43:24 Reply

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

Dizeaze
Dizeaze
  • Member since: Dec. 21, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Game (part 1) 2008-01-12 13:50:24 Reply

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

GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Game (part 1) 2008-01-12 14:11:58 Reply

Oh wow I said that? -_-"


BBS Signature