PDA

View Full Version : [AS2] Waypoints ?? Tutorial ??


TastyTeo
07-13-2009, 06:02 PM
stop();
attachMovie("path", "path", _root.getNextHighestDepth());
waypoint_x = new Array(40, 140, 140, 220, 220, 80, 80, 340, 340, 420, 420);
waypoint_y = new Array(140, 140, 60, 60, 240, 240, 320, 320, 100, 100, -20);
delay = 25;
new_monster = 0;
monsters_placed = 0;
onEnterFrame = function () {
if (monsters_placed<25) {
new_monster++;
}
if (new_monster == delay) {
monsters_placed++;
new_monster = 0;
min = attachMovie("minion", "minion"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:40, _y:-20});
min.point_to_reach = 0;
min.speed = 1;
min.onEnterFrame = function() {
dist_x = waypoint_x[this.point_to_reach]-this._x;
dist_y = waypoint_y[this.point_to_reach]-this._y;
if ((Math.abs(dist_x)+Math.abs(dist_y))<1) {
this.point_to_reach++;
}
angle = Math.atan2(dist_y, dist_x);
this._x = this._x+this.speed*Math.cos(angle);
this._y = this._y+this.speed*Math.sin(angle);
this._rotation = angle/Math.PI*180-90;
};
}
};


I Don't know what is this, i just copied from:

http://www.emanueleferonato.com/2007/10/06/make-a-flash-game-like-flash-element-tower-defense-part-1/

May it help you to find a solution for me....

So let's start describing my problem...
I Want to make a game "Coin Collector".
and i just want to spawn coins....

Before describing i recommend you to take a look at "THIS GAME"

How they make spikes spawn??? I Want to make COINS SPAWN!!!
and the way is with waypoints i think

And let's describe......
Document Size: 550 x 400
FPS: 60
I Have a MovieClip exported to actionscript as "coin" and the instance name "coin" too.

So i want this coin to spawn from the upper part of the screen, and go straight down to the bottom of the screen....
so my movie clip "player"
exported to actionscript as "player" and the instance name "player" too
can catch the coins falling down from the screen... with little words a simple hitTest. When he catch a coin, the var: coins i want to increase by 1.

Thanks
MSN: theofilaktos.spendas@windowslive.com
G-MAIL: theofilaktos.spendas@gmail.com
Yahoo Mail: theofilaktos.spendas@yahoo.com

I Recommend you to send email to my Gmail and Talk to me to the MSN
And if you want reply here...

rrh
07-14-2009, 06:33 PM
The link you gave explains the code very well.

The purpose of the waypoints is to make the creeps follow a path. If your coins only move downwards, then the waypoints won't be of much help.

asf8
07-15-2009, 03:43 PM
So i want this coin to spawn from the upper part of the screen, and go straight down to the bottom of the screen....

If your coins only move downwards, then the waypoints won't be of much help.

^ Exactly as rrh mentioned.

can anyone help me guys? No? Yes?

So whats wrong with the Help/Code that crosshair provided in your other thread???? That should get you going.

http://www.actionscript.org/forums/showthread.php3?p=902370

TastyTeo
07-15-2009, 10:19 PM
it didn't worked. when they spawn they didnt moved and they removed immediately

rrh
07-16-2009, 04:04 PM
That tower defense code is described on the page you linked to, line by line, which is as good detail as you can hope to see in a tutorial. There's a lot you could learn from going through that example and trying out slight alterations to learn how it changes the behaviour.

You could also learn by comparing the similarities and differences between that example and crosshair's example. Both use attachMovie to spawn, but one has it inside a setInterval and one has it inside an if statement inside an enterFrame function. Both assign the spawned item an enterFrame function for movement, but the contents differ because one just moves down and the other follows waypoints using trigonometry.

I'm not trying to be mean, but when you post a link to a page that explains the code in incredible detail and say, "I don't know what is this," I think it's better that you learn something instead of keep posting, "It's not perfect yet, fix it!" until other people write your whole game.