Be a Supporter!

AS: Overhead Game

  • 6,122 Views
  • 10 Replies
New Topic Respond to this Topic
Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
AS: Overhead Game 2006-03-16 18:18:27 Reply

AS; Main

DO NOT POST UNTILL I SAY SO PLEASE!

Hey, this is my second attempt at this (because the first one wasnt good enough). I explained almost every line in the code (the ones I didnt were used from other tutorials that Denvish made), and explained what to do better, as well as improving the code.

What you will be Making
You will have made an overhead game with enimies, walls, health potions, gold, and other things. This is the finsihed version. Game Demo

The Main Character
Ok, first create three animations of a person standing, walking, and attacking (overhead). Name the animations p1attacking, p1walking, and p1standing.

Now make all of those into a movieclip, and put each of these on their own frame. The standing animaiton should be on the first frame, the walking on the second, and the attacking on the third. Name this whole movieclip p1. Now add a stop action to each of the 3 frames inside the movieclip.

This is a little confusing, so let me expalin what we have so far. A movielcip called p1 which has 3 animations in it, one one on each frame. They are standing, walking, and attacking? Now onto the next step. The code.

Add this code onto the actions of p1 (the whole movieclip) For the code MC means movieclip

onClipEvent (mouseMove) {
Xd = _root._xmouse-_x;
Yd = _root._ymouse-_y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
}
// see Denvish's tut on rotating towards mouse
onClipEvent (enterFrame) {
//checks every frame
_root.standing = true;
//makes the variable standing to be true
if (Key.isDown(Key.UP)) {
// if up is pressed
_root.attacking = false;
//makes attacking false
_root.standing = false;
//makes standing false
_root.p1.gotoAndStop(2);
//makes the MC called p1 stop on the second frame
_root.p1.p1walking.play();
//makes the MC on the second frame play
if (_rotation>180) {
// if this rotation is greater than 180
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
// minusus the y from the distance from the mouse
_x += (5*Math.sin(Math.PI/180*(_rotation)));
// adds the x from the distance from the mouse
} else {
// otherwise
_y += (5*Math.cos(Math.PI/180*(_rotation)));
//same as the previous but opposite
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
//same as the previous but opposite
}
}
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)));
}
}
// this whole section is the opposite of the one with the UP key
if (_root.standing == true && _root.attacking == false) {
// if the variable standing is true and the variable attacking is false
_root.p1.gotoAndStop(1);
// the MC called p1 stops on frame 1
_root.p1.p1standing.play();
// the movieclip on that frame plays
}
}
onClipEvent (mouseDown) {
// if the mouse is down
_root.attacking = true;
//the variable attacking is true
_root.p1.gotoAndPlay(3);
//the MC called p1 goes to frame 3
_root.p1.p1attacking.play();
// the MC on that frame plays
}

The Enemy

Make a movieclip, and inside it have an animation of the enemy walking, flying, whatever it does. Now make that into a movieclip, and make an animaiton of it dissapearing. On the last frame of that aniamtion, add these actions

stop();
//stops the animation
_root.gold += Math.ceil(Math.random()*100);
//generates a random amount of gold from 1-100

On the first frame of the animation also add the stop(); action.

Now on the ouside of the whole movieclip, add these actions.

onClipEvent (enterFrame) {
// checks every frame
if (this.hitTest(_root.p1.p1standing)) {
// if this movieclip touches the p1standing MC inside the p1 MC
_root.health.nextFrame();
//makes the health bar go to the next frame
}
if (this.hitTest(_root.p1.p1walking)) {
// if this hits the p1walking MC inside the p1 MC
_root.health.nextFrame();
//makes health go to the next frame
}
if (_root.p1.p1attacking.sword.hitTest(this)) {
//if the p1attacking MC inside the p1 MC hits this
this.play();
//makes this play
}
}
onClipEvent (load) {
//when the movie loads (only does ths once)
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));
}
}
}
// see Denvish's tutorial on this for the explanation

IMPORTANT
In order for the walls to work (made later on), you must give each enemy the instance name of enemy and something else. (I used enemy1, enemy2, enemy3, ect.)

The Health Bar
Make a movieclip, and inside of that make an animation of of it going down to nothing. On the first frame add these actions stop();

On the last frame add these actions _root.gotoAndStop("death"); On your main timeline, call the gameover frame "death" without the quotes.

Now give the health bar the instance name of health.

Because of space issues, I cant finsih it all here, so please do not post.

Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Overhead Game 2006-03-16 18:31:52 Reply

Continued due to lack of space.

The Walls
Make a drawing of your wall now. Make it into 4 movieclips (top, bottom, left side, right side). Now add these actions to the top part of the movieclip

onClipEvent (enterFrame) {
//checks every frame
for (i in _root) {
if (_root[i]._name.indexOf("enemy") != -1) {
if (_root[i].hitTest(this)) {
_root[i]._y -= 6;
}
}
}
if (_root.p1.hitTest(this)) {
_root.p1._y -= 6;
}
}
// for this code, it says that for any movieclip that has the instance name of enemy
// in it, and that if it hits this movieclip, then it will make the p1 MC y go down by 6

Now, because of space, I am not going to post all 4 codes for all parts of the walls, but all you need to do is change the x and the y and the + and the - to fit all the walls.

Money

If you have a good memory, then you will remember that I posted a code that involed gold a tthe end of the enemy dying animaiton. Now, all we have to do is create a dynamic text box, and give it the instance name of gold.

But wait, theres more! If you want to be able to pick up gold (like in the demo I showed you) then all you have to do is one simple thing.

Make an animation of gold dissapearing, and put it in a movieclip. On the first frame, add the stop(); action. On the last frame of the animation, add these actions and create a blank movieclip.
root.gold += Math.ceil(Math.random()*25);
//makes a random amount of gold from 1-25
stop();
//stops the animation

On the ouside of the movieclip, add these actions.

onClipEvent (enterFrame) {
//checks every frame
if (this.hitTest(_root.p1)) {
// if this hits the MC p1
this.play();
// makes this play
}
}

Heath Potion
Make an animation of a health potion dissaperaing (like the gold), and make that into a movieclip. Then add a stop(); action onto the first frame, and on the outside of the MC, add the same actions added to the gold.

On the last frame of the health potion dissapearing, insert a blank frame and add these actions

_root.health.prevFrame();
//makes health go back a frame

Or if you want it to heal completly

_root.health.gotoAndStop(1);
//makes the Mc called health stop on the first frame.

That is all for the tutorial, and I hope I did it well enough so that it could be added next time. Also.
EVERYTHING IS COPY AND PASTEABLE Well, except for the main character and the health bar.

Thanks for reading this, sorry for all the writing, and I hope I helped. Specail thanks to Denvish for parts of the code.

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Overhead Game 2006-03-16 18:37:21 Reply

Related links:
AS: Pointing/Shooting at Mouse
AS: Bars (Health/Score/etc) by Inglor
AS: Bars (Health/Score/etc) by Darkfire_Blaze
AS: Collisions by Glaiel_Gamer
AS: Collision Detection by BleeBlap
AS: ClipEvents by Inglor


- - Flash - Music - Images - -

BBS Signature
citricsquid
citricsquid
  • Member since: Jun. 25, 2005
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to AS: Overhead Game 2006-03-17 12:38:03 Reply

Wow well done, i had a go at this my self and it turned out great.

Hoeloe
Hoeloe
  • Member since: Apr. 29, 2004
  • Offline.
Forum Stats
Member
Level 37
Game Developer
Response to AS: Overhead Game 2006-05-10 13:45:57 Reply

_root.p1.p1walking.play(); is unneccessary, as long as you havn't pu a stop(); action in the frame...


Song of the Firefly is on Steam Greenlight and Kickstarter. Give them a look and support the project!
------------------------------

BBS Signature
Cojones893
Cojones893
  • Member since: Mar. 9, 2003
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Overhead Game 2006-05-10 14:27:45 Reply

In the demo "down" walks towards the mouse and "up" walks away.

UnknownFear
UnknownFear
  • Member since: Feb. 27, 2004
  • Offline.
Forum Stats
Member
Level 37
Gamer
Response to AS: Overhead Game 2006-06-18 22:10:11 Reply

At 5/10/06 02:27 PM, Cojones893 wrote: In the demo "down" walks towards the mouse and "up" walks away.

I was just about to post this :P

suppi
suppi
  • Member since: Jun. 29, 2003
  • Offline.
Forum Stats
Member
Level 07
Audiophile
Response to AS: Overhead Game 2007-03-31 19:23:58 Reply

its nice but to make the game feel complete it really needs strafing. strafing would be cool

nightmare-series
nightmare-series
  • Member since: Sep. 10, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Overhead Game 2007-09-16 00:10:46 Reply

At 5/10/06 02:27 PM, Cojones893 wrote: In the demo "down" walks towards the mouse and "up" walks away.

yea how do you fix THAT?

Smconstpdgy
Smconstpdgy
  • Member since: Jul. 8, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Overhead Game 2008-03-07 23:19:13 Reply

Here, I know this is like my first post.. but I made this code so you go faster forward then backward and you press the "W" key to go forward and the "S" key to go backward. Just a simple adjustment for better keyboard layout.
onClipEvent (mouseMove) {
Xd = _root._xmouse-_x;
Yd = _root._ymouse-_y;
radAngle = Math.atan2(Yd, Xd);
_rotation = int((radAngle*360/(2*Math.PI))+90);
updateAfterEvent();
}
// see Denvish's tut on rotating towards mouse
onClipEvent (enterFrame) {
//checks every frame
_root.standing = true;
//makes the variable standing to be true
if (Key.isDown(83)) {
// if up is pressed
_root.attacking = false;
//makes attacking false
_root.standing = false;
//makes standing false
_root.p1.gotoAndStop(2);
//makes the MC called p1 stop on the second frame
_root.p1.p1walking.play();
//makes the MC on the second frame play
if (_rotation>180) {
// if this rotation is greater than 180
_y -= (5*Math.cos(Math.PI/180*(_rotation)));
// minusus the y from the distance from the mouse
_x += (5*Math.sin(Math.PI/180*(_rotation)));
// adds the x from the distance from the mouse
} else {
// otherwise
_y += (5*Math.cos(Math.PI/180*(_rotation)));
//same as the previous but opposite
_x -= (5*Math.sin(Math.PI/180*(_rotation)));
//same as the previous but opposite
}
}
if (Key.isDown(87)) {
_root.standing = false;
_root.attacking = false;
_root.p1.gotoAndStop(2);
_root.p1.p1walking.play();
if (_rotation>180) {
_y += (7*Math.cos(Math.PI/180*(_rotation)));
_x -= (7*Math.sin(Math.PI/180*(_rotation)));
} else {
_y -= (7*Math.cos(Math.PI/180*(_rotation)));
_x += (7*Math.sin(Math.PI/180*(_rotation)));
}
}
// this whole section is the opposite of the one with the UP key
if (_root.standing == true && _root.attacking == false) {
// if the variable standing is true and the variable attacking is false
_root.p1.gotoAndStop(1);
// the MC called p1 stops on frame 1
_root.p1.p1standing.play();
// the movieclip on that frame plays
}
}
onClipEvent (mouseDown) {
// if the mouse is down
_root.attacking = true;
//the variable attacking is true
_root.p1.gotoAndPlay(3);
//the MC called p1 goes to frame 3
_root.p1.p1attacking.play();
// the MC on that frame plays
}

If you want more keys go to
AS: KeyCode

Renandchi2
Renandchi2
  • Member since: Jul. 24, 2008
  • Offline.
Forum Stats
Member
Level 13
Filmmaker
Response to AS: Overhead Game 2008-10-09 18:15:21 Reply

i did everything, but some walls, the enemy dying, and the health bar don't work! can somebody please help? here is the fla . can somebody please help! and no, it's not even close to done yet.


/