Forum Topic: As: Movement, Ai, Walls, And Other

(484 views • 21 replies)

This topic is 1 page long.

<< < > >>
None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 09:18 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Insert Clever As:Main Joke Here
Well, this is my first topic, so I dont know exactly how to do this, and i couldn't really think up of a good name. Also, not all of these codes are mine, but I took them and edited them to make them work. I dont know if this was allowed, but I did it anyway. Ok, onto the topic.
What you will be learning
After this, you will be able to create a game with a main char, enimies, walls, health, gold, and potions. Here is an example of what you will be making.
Part A- Main Character
First off, you need to make some drawings. Draw your main character, and make 3 MCs into 3 different animations. They are standing, walking, and attacking. Now put off off these into one MC, with each of these on a seperate frame. Name(the instance name) each of the 3 animations p1walking, p1standing, p1attacking. Then put them on the 3 frames in this order- Standing, walking, attacking, Name the outside MC p1(instance name). Good. Now add a stop(); action to each of the frames inside of p1. This is a little confusing, but let me recap it all for you. You have a MC with the instance name of p1. Inside of it there are 3 frames, one called p1standing, with the person stnadng, one called p1walking, with the person walking, and on the last fram eit is called p1 attacking, with the person attacking. Good, and we are almost done with making the main character. Now go to the Mc with the 3 animations in it and give it this code. Make sure all of the instance names are right.
I almost forgot. Go to the animation of your player attackign, and make his weapon the instance name of sword.
onClipEvent (mouseMove) {
Xd = _root._xmouse-_x;
Yd = _root._ymouse-_y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
}
onClipEvent (enterFrame) {
_root.standing = true;
if (Key.isDown(Key.UP)) {
_root.attacking = false;
_root.standing = false;
_root.p1.gotoAndStop(2);
_root.p1.p1walking.play();
if (_rotation>180) {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
}
}
if (Key.isDown(Key.DOWN)) {
_root.standing = false;
_root.attacking = false;
_root.p1.gotoAndStop(2);
_root.p1.p1walking.play();
if (_rotation>180) {
_y += (5*Math.cos(Math.PI/180*(_rotation)));
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
} else {
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
_x += (5*Math.sin(Math.PI/180*(_rotation)));
}
}
}
onClipEvent (enterFrame) {
if (_root.standing == true && _root.attacking == false) {
_root.p1.gotoAndStop(1);
_root.p1.p1standing.play();
}
}
onClipEvent (mouseDown) {
_root.attacking = true;
_root.p1.gotoAndPlay(3);
_root.p1.p1attacking.play();
}
Now this might of gotten messed up because the BBS does it. Now, this code basicly makes the Character rotate towards the mouse, and when you press keys it makes it move towards it. The rest is just variables that check what it is doing. Another makes the character attack when the mouse is clicked. I am not going to explain all of this, because it would take forever. Now, your main character should walk towards you mouse. If not, check all of your instance names to see if they are named correctly. Now onto enimies.
Part B-Enemies
Ok, draw your enemy, and make an animation of it walking/flying, ect.. Make this into a MC. Now, make an animation of it dying. I made it glow red, and then dissapear. At the last frame make an empty MC.Now on the first frame of that MC, add a stop(); action.
At the last frame of the MC add these actions-
stop();
_root.gold += Math.ceil(Math.random()*100);
(This will be used for later, dont worry about it now.)
Ok, now on the ouside of your MC, add these actions to it.

onClipEvent (enterFrame) {
if (this.hitTest(_root.p1.p1standing)) {
_root.health.nextFrame();
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.p1.p1walking)) {
_root.health.nextFrame();
}
}
onClipEvent (enterFrame) {
if (_root.p1.p1attacking.sword.hitTest(this)) {
this.play();
}
}
onClipEvent (load) {
spd = 2;
}
onClipEvent (enterFrame) {
Xdiff = _parent.p1._x-_x;
Ydiff = _parent.p1._y-_y;
radAngle = Math.atan2(Ydiff, Xdiff);
_rotation = int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
if (this.hitTest(_parent.p1)) {
} else {

if (_rotation>180) {
_y += (spd*Math.cos(Math.PI/180*_rotation));
_x -= (spd*Math.sin(Math.PI/180*_rotation));
} else {
_y -= (spd*Math.cos(Math.PI/180*_rotation));
_x += (spd*Math.sin(Math.PI/180*_rotation));
}
}
}

I cannot explain of of this as well, but it makes the enemy rotate towards the player, and then walking towards him/her. The rest just makes it so that when the enemy hits the player, the player loses health. The other stuff makes the enemy play when it is hit by the player attacking. I think this is it for the enemy.
Part C- Health
Make a health bar and make it a MC. Now make an animation of it going down to nothing. On the first frame add a stop(); action. On the last frame add these action _root.gotoAndStop("death"); change death to the name of the frame where you die. Now give the health bar the instance name of health. Thats it for the health bar.
Part D- Walls
Now this was the hard part. There was a problem, becuase the player and the enemies both needed to be stopped by walls, and I needed them both to be copy and pasteable. (which they are) Now, the walls are a little confusing to make. First, make a a drawing of your wall. Then, make 4 Mc's out of it. One on the top, one on the bottem, =and one on each side. Not add these actions to the the top part of the wall.
onClipEvent (enterFrame) {
for (i in _root) {
if (_root[i]._name.indexOf("enemy") != -1) {
if (_root[i].hitTest(this)) {
_root[i]._y -= 6;
}
}
}
}
onClipEvent (enterFrame) {
if (_root.p1.hitTest(this)) {
_root.p1._y -= 6;
}
}

Now because of space issues, I can't post all the codes for all the walls. You will have to change the codes your slef (the x and y) to make it work. I am out of space, so I will explain this code in the next post. Dont post!


None

TommyGun

Reply To Post Reply & Quote

Posted at: 2/11/06 09:27 AM

TommyGun EVIL LEVEL 30

Sign-Up: 10/14/05

Posts: 8,426

good work^_^ deserves to be in AS:Main.

I wonder...will AS:MAin Ever be so full of AS related content that it will take 30 posts just for the contents....

"It isn't that democrats are ignorant. Far from it. it's just that they know so much that just isn't so"
Ronald Reagan
Proud supporter of the Dinosaur Conspiracy Theory

BBS Signature

None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 09:28 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Continued due to lack of space, sorry.
Ok, for the wall code now. The code stops the paler, and also any Mc with the word enemy in its instance name. I did not make that part of the code, but I must say, it is a lifesaver. Now to make the walls work, you must have your enemy have the instance name with the word enemy in it. I named all of mine enemymum1. enemymum2, ect.
That should be it for the walls. Make sure you change the code to fit all 4 parts of the wall.
Part E- Other
Its time to make the gold and health potions. For the gold, all you need to do is make a text box with the variable of gold. If you remeber, I had put the gold code at the end of the enemy dying. But if you want to make gold like I did (on the ground), it is pretty simple. Just make a MC with the animation of gold, and then make it dissapear. At the beggining of the aniamtion, add a stop(); command. At the end, add a blank frame. Also add these actions at the end.
_root.gold += Math.ceil(Math.random()*25);
stop();
This generates a random amount of gold. Ok, not on the outside of the Mc add these actions.
onClipEvent (enterFrame) {
if (this.hitTest(_root.p1)) {
this.play();
}
}
Now the health potion is very similer, but at the end instead of adding gold script, add these actions.
stop();
_root.health.prevFrame();
Make as many previous frmaes as you want it to heal. If you wan tit to heal completly add these actions
_root.helath.gotoAndStop(1);
Thats it for health and gold!
Acually, that is it for everything. Please post any errors you may find, or anything else. Thanks for reading theses longs posts, and good luck!


None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 10:25 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

I know I shouldn't bump after only 1 hour but, still nothing? I spent a long time writing this, and I don't care what you have to say, even if its just telling me I suck and have no life. Im sure there is a bug, or you have questions. Did any1 even try it to see if it works? Or is it just too long to read? An dim sure my code could be made loads shorter and better.

yeah, im desperate

None

Rantzien

Reply To Post Reply & Quote

Posted at: 2/11/06 10:36 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,422

At 2/11/06 10:25 AM, pyro111 wrote: I know I shouldn't bump after only 1 hour but, still nothing?

It's just that... I dunno... paragraphs.

BBS Signature

None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 10:38 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

it is. The bold writing means a new paragraph. And I would tab in, but it doesnt let me.


None

TommyGun

Reply To Post Reply & Quote

Posted at: 2/11/06 10:38 AM

TommyGun EVIL LEVEL 30

Sign-Up: 10/14/05

Posts: 8,426

relax pyro.

you just posted at a time when all the AS junkies are sleeping

or in Denvish case, drinking more coffee in order to mod the forums for 27 consecutive days

"It isn't that democrats are ignorant. Far from it. it's just that they know so much that just isn't so"
Ronald Reagan
Proud supporter of the Dinosaur Conspiracy Theory

BBS Signature

None

Cybex

Reply To Post Reply & Quote

Posted at: 2/11/06 10:40 AM

Cybex NEUTRAL LEVEL 20

Sign-Up: 03/04/05

Posts: 7,744

I didn't really bother reading the whole tutorial, but the example you posted looks good. One thing though. Up and Down are backwards.


None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 10:43 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Yeah, I realise that. I liked it better. I dont know why. Then I got used to it. But thanks for noticing it anyway. And sorry for the Dp.


None

Momo-the-Monkey

Reply To Post Reply & Quote

Posted at: 2/11/06 10:44 AM

Momo-the-Monkey EVIL LEVEL 30

Sign-Up: 10/15/05

Posts: 3,096

Good work man. n00bs will be flocking to get their hands on this one and maybe....just maybe...one day the portal wont have GAY NOOBISH CRAP...*cough* sorry..lolz

good job

You should see Gir's Soundboard...
{ PHP: Main | | Java: Main }
Every Villian Is Lemons

BBS Signature

None

FlashKid

Reply To Post Reply & Quote

Posted at: 2/11/06 10:49 AM

FlashKid EVIL LEVEL 14

Sign-Up: 11/22/03

Posts: 1,178

Heh, I've been making a game similar to this and now everyone will come out with well hitested and mouse controlled versions and mine won't look so cool. = (

although it looks like a great tutorial.
I'll give it a read when I feel needy for infomation. I'm sure your efforts won't go to waste. = )

Below is what would of been a picture of my real time stratergy, it's just too bad I can't fit it's awesomeness in 599X50. Who thinks up these dimensions?!

BBS Signature

None

Blaze

Reply To Post Reply & Quote

Posted at: 2/11/06 11:03 AM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,957

At 2/11/06 10:38 AM, SaiNT_SiLEiGHtY wrote: relax pyro.

you just posted at a time when all the AS junkies are sleeping

Totally agree.

Just relax and wait. I wont bother reading it all, since its kinda stuff that i know. Eitherway i would.


None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 11:10 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Did you know this?
onClipEvent (enterFrame) {
for (i in _root) {
if (_root[i]._name.indexOf("enemy") != -1) {
if (_root[i].hitTest(this)) {
_root[i]. //actions
}
}
}
}

Now that is a lifesaver, which I never knew about. Saves tons of lines of code.


None

Rantzien

Reply To Post Reply & Quote

Posted at: 2/11/06 11:25 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,422

At 2/11/06 11:10 AM, pyro111 wrote: Did you know this?

Yeah, he did =P
Although I'd rather use arrays, or the good ol' mc['name' + identifier] method =)
Doesn't use up as much memory.

Also, when I said paragraphs, what I actually meant was adding space between them, like I did here =) It eases up readability a whole lot.

BBS Signature

None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/11/06 11:34 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Oh. Yeah....... I knew that.
Well, I had never seen that before so It helped me a lot at least. Now I feel stupid. I had always seen that _name thing, but i thought it was like _root, _parent, and this.


Angry

Nuggs

Reply To Post Reply & Quote

Posted at: 2/11/06 11:36 PM

Nuggs LIGHT LEVEL 19

Sign-Up: 12/17/05

Posts: 1,222

aghhhh help. my character walks sideways twards the mouse intead of wacing the mouse.
ive tried everythin ( rotating the character, changing the rotation point, changin the center point, making all new mcs, checking the instances), but nothing seems to change the rotation point for the character. please help
Here is What I'm Talking About

Games|1|2|3| Movies|1|2|

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 2/11/06 11:48 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,342

At 2/11/06 11:36 PM, hckypck555 wrote: Here is What I'm Talking About

when you draw the character, he needs to be facing upwards, not right. otherwise, add or subtract multiples of 90 to rotate him properly.

umm, the thread as a whole is sorta iffy. on one hand, i want to give you the benefit of the doubt for writing this whole thing out, but really, AS: MAIN doesnt need a bunch of "how to create this game" or "how to create that game" threads. the point of AS: MAIN is to teach the fundamentals of AS without giving room to just copy and paste.

all in all, ill give you a 2/5 for trying, but i dont think this is really AS: MAIN material.

wii friend codes: [LISTED]

BBS Signature

None

Rammer

Reply To Post Reply & Quote

Posted at: 2/11/06 11:53 PM

Rammer DARK LEVEL 31

Sign-Up: 06/08/03

Posts: 4,314

At 2/11/06 11:48 PM, authorblues wrote: AS: MAIN doesnt need a bunch of "how to create this game" or "how to create that game" threads. the point of AS: MAIN is to teach the fundamentals of AS without giving room to just copy and paste.

all in all, ill give you a 2/5 for trying, but i dont think this is really AS: MAIN material.

that's what i was thinking :S

can you get on msn? i need some help with function-type stuff-things.

{ AMD Athlon 64 X2 5200+ 2.6 GHz - two 320 GB HDDs in RAID 0 - NVIDIA GeForce 8800 GT - Gyration mouse - Razer Tarantula keyboard - 2 GB Corsair RAM }

(:


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 2/13/06 05:57 AM

GuyWithHisComp LIGHT LEVEL 24

Sign-Up: 11/10/05

Posts: 4,027

If it is a AS:Thread it should comment almost every line but since it doesn't I think this would fit better with FOSS.

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 2/13/06 06:06 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

It's detailed but not explained. :/

Nice tutorial anyway.

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 2/15/06 04:37 PM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Well, should I explain the codes then. I just thought it would take too long and too much space, if you want me too I will explain them now.


None

Blaze

Reply To Post Reply & Quote

Posted at: 2/15/06 04:38 PM

Blaze LIGHT LEVEL 22

Sign-Up: 08/04/05

Posts: 6,957

in my opinion, fuck yes you should.


All times are Eastern Standard Time (GMT -5) | Current Time: 12:51 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!