Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




[MX04] Random Target/enemy



How do I make a random target/enemy or how to make it start from a random position?

In a shoot-out I need to make random showing enemys... Please help.



FlashKit > Flash Help > Flash ActionScript
Posted on: 07-22-2006, 10:25 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

[MX04]Random Enemy Movement
I want some enemies to move randomly around the screen no diagonally though, just like most enemies move in the old zelda games if anyone has played them - thanks in advance

F8 TBG - Enemy Problem - Random Direction Needed
Hello...

I'm hoping to make my enemy go in random directions without necessarily having to hit a wall or unwalkable tile...so far this is the code that I have...

this.onEnterFrame = function () {
downY = Math.floor( ( _y + (_height/2) ) /tileH );
upY = Math.floor( ( _y - (_height/2) ) /tileH );
leftX = Math.floor( ( _x - (_width/2) ) /tileW );
rightX = Math.floor( ( _x + (_width/2) ) /tileW );
centerX = Math.floor( _x /tileW );
centerY = Math.floor( _y /tileH );

if ( dir == "up" ) {
_y -= speed;
_x = (centerX * tileW) + (tileW*0.5);
gotoAndStop(2);
}
if ( dir == "down" ) {
_y += speed;
_x = (centerX * tileW) + (tileW*0.5);
gotoAndStop(15);
}
if ( dir == "left" ) {
_x -= speed;
_y = (centerY * tileH) + (tileH*0.5);
gotoAndStop(5);
}
if ( dir == "right" ) {
_x += speed;
_y = (centerY * tileH) + (tileH*0.5);
gotoAndStop(10);
}

// checkCollision - this depends on the enemy hitting the wall
if ((dir == "up") && (myMap[upY][centerX] == 1 )) {
newDir();
}
if ((dir == "down") && (myMap[downY][centerX] == 1 )) {
newDir();
}
if ((dir == "left") && (myMap[centerY][leftX] == 1 )) {
newDir();
}
if ((dir == "right") && (myMap[centerY][rightX] == 1 )) {
newDir();
}
}

i don't know how to go about making a function newDir aside from making switch statements like this:

function newDir() {
var someVar = Math.floor (Math.random() * 4);

switch (someVar){
case 0 :
dir = "up";
break;
case 1 :
dir = "down";
break;
case 2 :
dir = "left";
break;
case 3 :
dir = "right";
break;
} // end switch
}

my goal is to make the enemy go in random directions even if it doesn't hit an unwalkable tile...

hope someone can help. thanks very much!

[MX04] Target MovieClip ?
I have a MovieClip say (MyClip1) that just sits in the library with a given linkage identifier name. Inside this MovieClip (MyClip1) is a child MovieClip say (MyClip2) which contains say 65 keyframes. Now my question is, is how would I target to MovieClip (MyClip2) from anywhere in my main movie, whether it be from the _root of the main stage, or whether it be from another MovieClip ect., working with this linkage identifier or what have you not.

[MX04] Target Path Sliding Video
Working in MX2004
publishing Flash 6

I have an .fla, a web page, with a big mc named "large_mc", it takes up the whole page, and contains a number of buttons and mcs.

"large_mc" slides left and right when a button is clicked.

Inside of "large_mc" I have a button on the stage that activates an mc called "video_mc"; and makes it play, "video_mc has a place holder image for the video that animates and then "video_mc" loads an external .swf with a video on layer2.

My problem is I need to target this external "video.swf" so it slides along with "large_mc". I've tried a number of combinations but the video does not slide!!

What would be the code to load this, what do I load it into and how is it positioned at X 500 and y 120 pixels?

[MX04] Target A Flash Movie In An IFRAME
Hi:

I have two movies in an IFRAME. The bottom frame has a flash movie that consistents of thumbnails, and are made into buttons.

The top frame has a flash movie that contains a movieclip with larger images of the thumbnails.

I'm trying to figure out what actionscript to put in the buttons to make the movieclip in the top frame go to a certain keyframe, and of course target the IFRAME.

I've had no luck with this in the buttons:

on (release) {
muralsMov.gotoAndPlay(1, "top")
}




Can anyone help me out with this.

Thanks,

SP

[MX04] For What Is The Target Parameter On A Shared Object?
Hello people.

please excuse my nooby question but, i want to know, what is exactly the use of the target parameter on a shared object? i know that it stores data on the users computer, but in that case, why does it need to expecify a target path?

i dont get it

[MX04] Problems Using Drop Target With Nest Movie Clips
Hi !

I wonder if anyone can help me solve this bit of code i'm having problems with..

I'm working on a site that will have a panel that can be dragged from the botttom of the screen. the panel includes navigation and data from an xml file. i have made this and called it info_mc.

the first time i created it, i realised that making info_mc the draggable item meant i lost my buttons in the panel, so i created another movieclip called drag_mc and place it in info_mc.

Theorising that when you pressed on drag_mc it would drag info_mc with it. after much tinkering with the script i got this to work as i wanted. ( when you drage it up it slides up and when youo release it slides back down out of view.

I now want to put a drop target so that when it is dragged over the target it will stick, at present the droptarget doesn't work. I've done this before but not with an embedded drag_mc . below is the script as it is at present. i'm sure the problem has something to do with the paths to drag_mc, info_mc and circleTarget. but have not been able to fix it.

The elements are laid out as so:
main timeline contains - circleTarget, info_mc
info_mc contains - Drag_mc, script for dragging (see below)
circletarget contains - 2xkeyframes with script stop(); in each.

you can see a mock up of the flash movie and download the FLA here:
http://www.bru-ha.com/flashdemo/drangndrop
http://www.bru-ha.com/flashdemo/drangndrop.swf

Here is the script info_mc that should do all the dragging and dropping.
code:
drag_mc.onPress=function(){
startDrag(_root.info_mc,true,_x,580,_x,0)
}

drag_mc.onRelease=drag_mc.onReleaseOutside=functio n(){
stopDrag();
if (_root.info_mc._droptarget == "../targetCircle") {
_root.info_mc.onTarget=true;
_root.targetCircle.gotoAndStop(2);
}else{
_root.info_mc.onTarget=false;
_root._parent.targetCircle.gotoAndStop(1)
}
}

//sets function on embedded drag button to drag info_mc
//the variables below will store the clips starting position

_root.info_mc.myHomeX=_root.info_mc._x;
_root.info_mc.myHomeY=_root.info_mc._y;

drag_mc.onMouseDown=function(){
//this variable tells us if the mouse is up or down
mousePressed=true;
}
drag_mc.onMouseUp=function(){
mousePressed=false;
}
drag_mc.onEnterFrame=function(){
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point (with a smooth motion)

if(mousePressed==false&&_root.info_mc.onTarget==fa lse){
_root.info_mc._x-=(_root.info_mc._x-_root.info_mc.myHomeX)/5;
_root.info_mc._y-=(_root.info_mc._y-_root.info_mc.myHomeY)/5;
}
}

I hope someone out there will be able to help me, or give me some advice...

best
Andy

[MX04] Drag And Drop- Locking Object Into Center Of Target...
Hello all,
New member and relatively new Flash user. I created a drag and drop in Flash MX 2004, and I'm trying to find script that will lock the object into the center of the target when it is dragged over, sort of like a magnet effect. Here is the script I currently have on each object:


on(press) {
startDrag(this);
_root.reply.text="";
xstart = this._x;
ystart = this._y;
}

on(release) {
stopDrag();
if (this._droptarget == "/pinottarget") {
_root.reply.text="Correct!";
this.enabled = false;
_root.counter++;
}

else{
_root.reply.text="No, keep trying!";
this._x = xstart;
this._y = ystart;
}
}



If anybody can help me out with the correct script to do what I'm trying to do, I would greatly appreciate it. Attached is the source file. Thanks.

Lee

Random Then Tell Target
I have a problem that is doing my head in!
PLEASE HELP!!
------------------------------------------------------
I have a variable that is 10 random numbers from 1-10 with no repeat.
I then pull out the first five numbers in that variable
e.g.
pulledout1=4
pulledout2=7
pulledout3=2
pulledout4=9
pulletout5=8

I have ten movie clips called item1, item2, item3, item4,
item5, item6, item7, item8, item9, item10.
-------------------------------------------------------
I want to do something like this

telltarget _root["item"+pulletout1]
gotoandstop 2
telltarget _root["item"+pulletout2]
gotoandstop 2
telltarget _root["item"+pulletout3]
gotoandstop 2
etc....
I know this is wrong but I hope it gives you an idea of what I am trying to get at.
Telling the target of 5 different movieclips using 5 random numbers to goto to frame 2 of those clips.

Regards
Dogs Lipstick

Random Target Name
Hi I have three different movie clips with three different instance names:

throwmov0
throwmov1
throwmov2

I'm trying to randomise the clip to be played when I hit a button and am using:

on (press) {
ranthrow=random(3);
varthrow="throwmov"+ranthrow;
this.varthrow.gotoAndPlay("throwit");
}

However it's not working - I know the variable string is being created becuase I tested this using a dynamic text field.

Can anyone see the problem here?

Thanks in advance!

[MX04] Help With A Random Input?
Hey sorry for this silly question, I have been up too long.

Think of my project as a row of cookie jars.

When you select a button, 5 cookie jars will fill up with X number of cookies.

I have a variable arry with the numbers inside (1, 2, 3, 4, 5)

But I want it to be random, so on the first click jar 1 might have 2 cookies in it...

then it stays that way for the duration of the movie, jar 1 will ALWAYS have 2 cookies in it.

When I reset the movie and start over, THEN it may have a new number.

I am sure AS on the release of the button will be fine, I just can't get anything to work.

Ideas?

~MoN

[mx04] Random Movies
Okay, sorry for my bad English... This is what I have to produce:

- 15 or so SWF, with a pictures that fades in and stays for 50 seconds/1 minute in each

- the main movie with a code that loads all the 15 SWF once after the other, but randomly (with a different sequence each time)

...Is that possible and, if so, can someone help me with the aforementioned code? Thanks so much.

[MX04] Random Gravity
hello,
sorry about the vague title, but i didn't know how to describe my problem, in a few words. basically i've been piecing together a web site using tutorials and other info i've found to try and teach myself how to use action script. which wasn't going to bad until i encountered this problem.

workingblocks.fla

all the blocks have identical code yet the purple one doesn't fall all the way to the bottom of the stage and to a lesser extent nor does the yellow one.

is there some thing silly i'm over looking?!

cheers for any help!

[mx04] Random Numbers
Im not exactly sure where this post belongs, but i think its pretty easily answered by someone with a better flash vocabulary than I. I need the numbers 1-6 (or any other range of numbers) generated in a random order. i can make 6 completely random numbers, but i need them all to be different. Thanks for your assistance in advance!

cC

[MX04] Random Array Stuff
I'm putting together a childrens game whereby a certain number (4 in this case) of sentences are randomly pulled from an array and displayed on screen. This bit i have working just fine (or 'trace's ok anyway):


Code:
// set up array for items
arrLess = [];
// sentence list
arrLess[0] = {lineName:'line1', part1:'line1part1', part2:'line1part2', part3:'line1part3'};
arrLess[1] = {lineName:'line2', part1:'line2part1', part2:'line2part2', part3:'line2part3'};
arrLess[2] = {lineName:'line3', part1:'line3part1', part2:'line3part2', part3:'line3part3'};
arrLess[3] = {lineName:'line4', part1:'line4part1', part2:'line4part2', part3:'line4part3'};
arrLess[4] = {lineName:'line5', part1:'line5part1', part2:'line5part2', part3:'line5part3'};
arrLess[5] = {lineName:'line6', part1:'line6part1', part2:'line6part2', part3:'line6part3'};
arrLess[6] = {lineName:'line7', part1:'line7part1', part2:'line7part2', part3:'line7part3'};
arrLess[7] = {lineName:'line8', part1:'line8part1', part2:'line8part2', part3:'line8part3'};
arrLess[8] = {lineName:'line9', part1:'line9part1', part2:'line9part2', part3:'line9part3'};

function shuffle() {
newMoveX = arrLess.concat();
for (c=1; c<=4; c++) {
itemX = newMoveX.pop();
trace(itemX.lineName +" || item part1 - "+itemX.part1+" || item part2 - "+itemX.part2+" || item part3 - "+itemX.part3);
}
}
shuffle();


The sentences are each split up into 3 parts. What i need to be able to do is to randomly choose a part (or two) of the sentence which will then become a drag and drop label that the child can then move into place completing the sentence.

Any ideas how i could achieve this?

I thought that maybe there could be a number of empty movieclips in position on screen ready to accept via an attachMovie command the various parts of the sentences, with a select few of them told to position themselves somewhere else to be used as draggable parts.

But bearing in mind that the draggable elements have to graphically look different, so probably need to be identified before they are placed rather than placed based on an attachMovie command.

So have figured that the array gets sorted, the parts chosen then placed in specific Movieclips.

If that hasn't confused you plenty (i know it has for me) any suggestions would be great.

Below is an attached image of the layout, which might be more helpful for trying to figure out what i'm talking about!!

ta,
d.

[MX04] Random Selecting Scenes?
Is it possible to randomly select scenes with actionscript???

I hope anyone can help!

Thz,
Jules

[MX04]moving To A Random Frame
Hello,
currently I have been encountering a problem with random frame movement.I want to do something like this-
When I come to frame 1, automatically go to frame 2 or 15, not 2-15,
ONLY 2 OR 15.
I know how to do 2-15,

Code:
gotoAndPlay(random(2)+15)

Can somebody help me!
Thank You,
Chinmaya

[MX04] Generate A Random Sound
Hi, I cant seem to find this simple code on the net. could someone post up the basic flash to generate a random sound when button is clicked.

much appreciated Graham.

[MX04] Generate A Random Sound
Hi, I cant seem to find this simple code on the net. could someone post up the basic flash to generate a random sound (1 of 4) when button is clicked.

much appreciated Graham.

[MX04][AS2]moving To Random Frame
Hello,
currently I have been encountering a problem with random frame movement.I want to do something like this-
When I come to frame 1, automatically go to frame 2 or 15, not 2-15,
ONLY 2 OR 15.
I know how to do 2-15,
gotoAndPlay(random(2)+15)
Can somebody help me!
Thank You,
Chinmaya

How To Unload A Random Movie In A Target ?
Hello there, is there anyone who knows how to unload the current movie that is playing in a target? (not a level!)

I know how to unload a specific movie in a target, but the user can choose different movies to be displayed in the target, but i dont want to know witch *.swf file i want to unload ..i want any *.swf file to unload in that target.

I thought something like this?
on (release) {
unloadMovie ("targetname, *.swf");
}

but this doesnt work...

does anyone has a suggestion?

Move To A Random Target Location
hi!! i'm using flash five and i need some help with making the following happen.

a movie clips actions:


loop

pick a random number with math.random for x
pick a random number with math.random for y

loop:
head towards x and y one pixel at a time
until -> has reached x and y, then

loop

please excuse my crappy psuedo code, hope someone can help!

Build Target Path Using Random
hello,

Im having trouble with datatypes in my variables. What I would like to do is build a target path like this:

PHP Code:



targetCell ="_root.space" + (random(3)+1)+".load1";




and then reference it later like this:

PHP Code:



al = targetCell._alpha




it works fine if I dont include the random like this:

PHP Code:



targetCell =_root.space1.load1;




so my problem is in transforming the string back. How do I do that? Or is there a way to build the path without strings in the first place?

Random Selection Of Tell Target Movies
How can I randomly select one of 4 tell target movies?
(Flash MX Actionscript)

Random Selection Of 4 Tell Target Movies
How do I randomly select 1 of 4 tell target movies?
(Flash MX Actionscript)

Load Random Movies Into Target Mc
I am in the process of creating a VS Card game in Flash. It is basically a game where you can choose either one card or another, each randomly pulled from one of the eight different sets. The first card (or swf) can be pulled from any of the 8 sets (out of a total of 12 cards in each set))..and will load into a targetMC, and the second must be pulled randomly from any of the 8 sets except from the folder where the first card was chosen and load onto the second targetMC.

any help would be greatly appreciated!

Load Random Swfs Into Target Mcs
I am in the process of creating a VS Card game in Flash. It is basically a game where you can choose either one card or another, each randomly pulled from one of the eight different sets. The first card (or swf) can be pulled from any of the 8 sets (out of a total of 12 cards in each set))..and will load into a targetMC, and the second must be pulled randomly from any of the 8 sets except from the folder where the first card was chosen and load onto the second targetMC.

after the winning card is chosen, it will display winning animation (and send data off to a dynamic bargraph program), and then the main movie will reload two random cards from differnt sets.

can anybody help me on how to set this up??

Random Selection Of Tell Target Movies
How can I randomly select one of 4 tell target movies?
(Flash MX Actionscript)

Random Selection Of 4 Tell Target Movies
How do I randomly select 1 of 4 tell target movies?
(Flash MX Actionscript)

[MX04] Math.random Randomly Loads Nothing?
Hi there. I have a presentation which I want to play music randomly each time it starts. I have 3 music files. I have put them into the timeline of 3 movieclips (mc0, mc1, mc2) with are loaded using the math.random script (below):

clipNum=Math.floor (Math.random () *4);
_root.attachMovie("mc"+clipNum, "mc",1);

This works okay, but it also loads nothing randomly, leaving me with no sound at all?

I have attached a test movie which I made with shapes in movieclips, which does the same thing; every so often it loads nothing.

Does anyone know what is wrong with the script, or if there is something I need to add so that it loads a mc every time?

Thanks

[MX04] Random External Jpgs With Transition
Hi!

i have to load randomly 4 jpgs from flashvars. They must have a transition.

i used


Code:
function loadFinished () {
trace ("load complete");
_root.thumbs.play();
randeffect = random(3)+1;
if (randeffect eq 1){
_root.mask.goToAndPlay("lato");
}
else if (randeffect eq 2){

_root.mask.goToAndPlay("lati");
}
else if (randeffect eq 3){

_root.mask.goToAndPlay("sugiu");
}
_root.thumbs.play();
}

function preload (clip, loadBar, loadText, callBack) {
var totalBytes = clip.getBytesTotal();
var loadedBytes = clip.getBytesLoaded();
var percentLoaded = Math.floor((loadedBytes/totalBytes)*100);
loadBar._xscale = percentLoaded;
loadText.text = percentLoaded+"%";
if (totalBytes > 30 && totalBytes == loadedBytes) {
clearInterval (preload_interval);
callBack ();
}
}

//usage

rand = random(4)+1;


trace(rand);
mc.loadMovie(eval("_level0.img_"+rand), 20);
preload_interval = setInterval (preload, 100, mc, loadBar_mc, loadText_txt, loadFinished);



slogan=_level0.slogan;
stop();

setInterval(function () {
rand2 = random(4)+1;
if (rand2 eq rand){
function loadFinished () {
trace ("load complete");
_root.thumbs.play();
randeffect = random(3)+1;
if (randeffect eq 1){
_root.mask.goToAndPlay("lato");
}
else if (randeffect eq 2){

_root.mask.goToAndPlay("lati");
}
else if (randeffect eq 3){

_root.mask.goToAndPlay("sugiu");
}
_root.thumbs.play();
}

function preload (clip, loadBar, loadText, callBack) {
var totalBytes = clip.getBytesTotal();
var loadedBytes = clip.getBytesLoaded();
var percentLoaded = Math.floor((loadedBytes/totalBytes)*100);
loadBar._xscale = percentLoaded;
loadText.text = percentLoaded+"%";
if (totalBytes > 30 && totalBytes == loadedBytes) {
clearInterval (preload_interval);
callBack ();
}
}
rand2 = random(4)+1;
mc.loadMovie(eval("_level0.img_"+rand2), 20);
preload_interval = setInterval (preload, 100, mc, loadBar_mc, loadText_txt, loadFinished);

}



else {
function loadFinished () {
trace ("load complete");
_root.thumbs.play();
randeffect = random(3)+1;
if (randeffect eq 1){
_root.mask.goToAndPlay("lato");
}
else if (randeffect eq 2){

_root.mask.goToAndPlay("lati");
}
else if (randeffect eq 3){

_root.mask.goToAndPlay("sugiu");
}
_root.thumbs.play();
}

function preload (clip, loadBar, loadText, callBack) {
var totalBytes = clip.getBytesTotal();
var loadedBytes = clip.getBytesLoaded();
var percentLoaded = Math.floor((loadedBytes/totalBytes)*100);
loadBar._xscale = percentLoaded;
loadText.text = percentLoaded+"%";
if (totalBytes > 30 && totalBytes == loadedBytes) {
clearInterval (preload_interval);
callBack ();
}
}
mc.loadMovie(eval("_level0.img_"+rand2), 20);
preload_interval = setInterval (preload, 100, mc, loadBar_mc, loadText_txt, loadFinished);

rand = rand2;
}

trace(randeffect);
}, 20000);

setInterval(function () {

mc1.loadMovie(eval("_level0.img_"+rand2), 20);


}, 22000);
but it doesn't work properly.

Any suggestion?

pleeeeaze

[MX04] Show Images In Random Order
i have a client that started out loving my simple alpha fade movie of his portfolio images.
now he has asked me if they can appear in random order.
well, i don't have a clue and his site was gonna be inexpensive.
here's the link to his format test site.

http://www.amotionstudio.com/KDC.html

any ideas out there?

thanks in advance for your time.

[MX04] Random Numbers In Dynamic Text?
I have been going through trial and error for 3 days, searched flashkit, and the forums, and could not find this out!

I want, upon loading, a little dynamic text box to take away off the number in the text box, a random number inbetween 1 and 10.

This is what I have in the code (It is in the frame):

Code:
_root.testbox-random(10);


It does nothing when I load.
No, I did not forget to give the text box the instance name "testbox".

Can anyone please help? I am pulling my brothers hair out, because I'm already bald.

[MX04] The Same Random Frame In Two Different Movie Clips
Hi, I'm a student at university and I frequently work with flash MX 2004. I'm currently working on a project that involves many characters on screen at once. only as a twist, I wish to have them scripted so that they all look different every time the swf is played.

for example, I have the head working. when the character is loaded into the frame, a random face, hairstyle and hair colour is chosen and works every time.
however what I'm stuck on is the rest of the body. I can easily set every body part at random but that will result in a bunch of characters wearing multicoloured clothing. each body part of the character is a seperate movieclip embedded into one movieclip.
right now, so that I can get a feel of it, I'm working on the shoes. I want the style of shoe to be random but i want both shoes to come out the same. initially my idea was that I have the random script on one shoe and then use script on the right but all my ideas fall short. here is what I have so far:

on the left shoe:
onClipEvent (load)
{
gotoAndStop(random (6));
}

and then on the right shoe:
onClipEvent(load)
{
gotoAndStop ((zombie.foot1.shoe1.currentFrame));
}

that was my first idea, I also thought about having:
this.currentFrame == zombie.foot1.shoe1.currentFrame;

and also the same only with currentFrame replaced with frameNumber.

this is the best that I can explain it. if people need me to go into more detail I'll be happy to.

any help would be great as I'd really love to get these things working

[MX04] Need Advice On Saving With Random Variable/values
Hello any/everyone!

I have a little fla (see attatched) that is basically nothing of use to anyone except the person I made it for.

However, now that I have all the math done and all the graphics and everything works perfectly, I was asked to see if I could save progress.

Being as this is a specific operation (not to mention one I have never done before) I was finding my self in need of help.

If you take a gander at the attatched fla, you will see that I have a variable of 22 different "points" 1 through 20,000

There is a button on stage that will take those values and distribute them to the 22 "boxes" on the stage.

then there is a "go to next round" button that well, takes you to the next round and then the third button to do the math part of the program. (I KNEW I should have done this in php, LOL)

Okay, so the main purpose of doing this program was to keep the person I am doing it for, from having to do it with pen and paper.

She will be using it every day, but, sometimes she wont be going through all 6 rounds in one day, and closes out the browser.

SOOOO... what I want is a way to save the random numbers and the boxes already "checked" and all the point balues where they are when she leaves for the day.

The options are pretty limitless here. This will be only used by one person, so local save is fine. Also it will be run on a web server, so uploading a txt file (or what ever) will also be fine.

I am not too concerned with beauty, just functionality.

I found this thread but I don't know if I can use that.

my main goal here is to preserve the points where they are origonally placed, until all round have been completed.

I will add a "save" button if needed.

Thanks for any help!

~MoN

[MX04] Random Spliced Array Attachmovie Problem
I'm trying to get an array to randomize and then have the first few items used to do an attachmovie function.

Here's what i have so far, but can i get it to work? Not on your nelly!


Code:
Array.prototype.randomize = function() {
var i = this.length;
if (i == 0) {
return;
}
while (--i) {
var j = Math.floor(Math.random()*(i+1));
var tmp1 = this[i];
var tmp2 = this[j];
this[i] = tmp2;
this[j] = tmp1;
}
return this;
};
function shuffle() {
// set up array
var arr = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
// randomize array
var newMoveX:Array = new Array(arr.randomize());
// test
trace("this is the randomized array: " + newMoveX);
// set up movieclips
for (c=1; c<=6; c++) {
item[c] = newMoveX.splice(c, 1);
_root["movieclip"+c].attachMovie(item[c], "item"+i, this.getNextHighestDepth());
trace(item);
}
}
shuffle();


The randomizing works just fine but nothing else afterwards.

Where am i going wrong here?

Cheers,
Dave.

[MX04] Random Number Generator Tells A Movie Clip To Start
I have a movie clip. In it i am trying to get a dynamic text box to constantly generate random numbers. When it finds a certain number i want it to make a movie clip play.
I am using:
onClipEvent (enterFrame);
_root.randomtext = random (10);
If (_root.randomtext == 4)
gotoAndPlay ("start clip");
}}

The problem is the text box will sometimes generate only ONE number or none at all. Please help.

Enemy AI
Hi Friends,

how do you make smart 'enemies' that chase or move towards your fighter? any tutorials on this?

Another challenge is how to make diagonal movement with the keyboard arrows? How do I make two keypresses(up and left for example) represent a diagonal movement?

Thanks, woktoc

Enemy
I have this script on my character for my game but it says their is something wrong with it. Please fix it

onClipEvent (enterFrame) {
if(this.hitTest(_root.enemy))
_root.hb.nextFrame();
)

Hit More Than 1 Enemy
In my game I have more than 1 enemy. and put a few script for the char like that.

if(_root.char.Thumb.hitTest(_root.enemy)){
//then attack
}

So the char can hit the enemies and decrease their lifetime.
But when I put the instance name "enemy" to all enemies. Only 1 enemy can work. The other doesnt work.

Should I create a array for it? Or any better way to do that?



I tried to use array like that, but it doesnt work

onClipEvent (enterFrame) {
if(keyIsDown(36)){
enemy_array = new Array();
for (i=0; i<2; i++){
if(_root.char.Thumb.hitTest(_root.enemy_array[i])){
//then attack
}
}
}

Any hints of doing it?

Enemy Won't Die
Hello,

I've a problem. I'm creating a puzzle/action game based off "tonyPa's tile-based game tutorials" (http://www.tonypa.pri.ee/tbw/index.html). In this game, the enemy move two spaces closer to the "hero" in a horizontal-then-verticle fashion. The hero can place a bomb, which will explode after the hero has 5 turns (moves or waits). If the enemy is upon the same tile as the bomb when it explodes, the enemy should die.

The problem is, he doesn't die.

With the code below, when the enemy and bomb are on the same tile, both their movie clips are deleted. however, after a couple moves, the "invisible" enemy runs into the hero, causeing the game to end. therefore, I must derive that the enemy is indeed still on the gameboard, just not his movie clip. The bombs work fine. Alowing placement only if there are no bombs currently present (ie. none placed yet, or any placed have blown up [deleted]).

Here is my code:

PHP Code:



//THIS CREATES THE ENEMY
// IT IS INSIDE THE BUILDMAP FUNCTION

    // Place enemies
    var enemies = myEnemies[game.currentMap];
    // save the number of enemies on stage
    game.currentEnemies = enemies.length;
    for (var i = 0; i<game.currentEnemies; i++) {
        // name of new enemy
        var name = "enemy"+i;
        // make new enemy object in the game
        game[name] = new game["Enemyp"+enemies[i][0]]();
        // add id to enemy object
        game[name].id = i;
        // push enemy into enemies array
        game.currentEnemies.push(game[name]);
        // add start position, width and height to new enemy from enemies array
        game[name].xtile = enemies[i][1];
        game[name].ytile = enemies[i][2];
        game[name].width = game.clip[name]._width/2;
        game[name].height = game.clip[name]._height/2;
        // calculate starting position
        game[name].x = (game[name].xtile*game.tileW)+game.tileW/2;
        game[name].y = (game[name].ytile*game.tileH)+game.tileH/2;
        //FIND DEPTH
        game[name].depth = game[name].y*300+game[name].x+3003;
        // add enemy to the stage        
        game.clip.attachMovie("enemy"+enemies[i][0], name, game[name].depth);
        // declare clip in the enemy object
        game[name].clip = game.clip[name];
        // place enemy mc
        game[name].clip._x = game[name].x;
        game[name].clip._y = game[name].y;
    }


--------------- 

// THIS FUNCTION LAYS THE BOMB AFTER THE APPROPRIATE KEY IS STRUCK 

function layBomb ()
{
    if(game.bombs.length > 0){
        return;
    }else{    
    ob.lastbomb = getTimer();
    ob = _root.char;
    game.bombcounter++;
    _root.bombcounter = game.bombcounter;
    if (game.bombcounter > 100)
    {
        game.bombcounter = 0;
    }
    var name = "bomb" + game.bombcounter;
    game[name] = new game.Bomb;
    game[name].id = game.bombcounter;
    game.bombs.push(game[name]);
    game[name].xtile = ob.xtile;
    game[name].ytile = ob.ytile;
    game[name].timer = 1;
        game[name].depth = ob.depth -1;
        game.clip.attachMovie("bomb", name, game[name].depth);
    game[name].clip.gotoAndStop(game[name].timer);
    game[name].clip = game.clip[name];
    game[name].x = (ob.x);
    game[name].y = (ob.y);
    game.clip[name]._x = game[name].x;
    game.clip[name]._y = game[name].y;
    }
    }
}

--------------- 

// THIS FUNCTION IS CALLED AFTER THE HERO AND ENEMY HAVE COMPLETED THIER TURNS 
// THIS IS THE FUNCTION THAT CHECKS TO SEE IF THE BOMB AND ENEMY ARE ON THE SAME TILE 

function bombTimer ()
{
    name = "bomb" + game.bombcounter;
    obbomb = game[name];
    obbomb.timer++;
    i = 0;
    
    if(obbomb.timer >=6){
    for (var j = 0; j<game.currentEnemies; ++j) {
          var name = "enemy"+j;
          var obenemy = game[name];
     if (obenemy.xtile == obbomb.xtile && obenemy.ytile == obbomb.ytile){
        obenemy.clip.removeMovieClip();
        delete game["enemy"+game.currentEnemies[j].id];
        game.currentEnemies.splice(j,1);

      }
    }    
          obbomb.clip.gotoAndPlay(obbomb.timer);
        obbomb.clip.removeMovieClip();
         delete game["bomb"+game.bombs[i].id];
          game.bombs.splice(i,1);

    }else{
        obbomb.clip.gotoAndStop(obbomb.timer);
    }
    






Any help appreciated.

Enemy Ai Help Please
I am really bad at actionscript so this is probably a really dumb question, if i want an enemy to follow my character in a platformer what do i do!!!!
(sorry i am so dumb )

I was thinking along the lines of

Quote:




onClipEvent (enterFrame) {
if(playerx>enemyx) {
this._x=_x-10;
}
onClipEvent (enterFrame) {
if(playerx<enemyx) {
this._x=_x+10;
}

Enemy AI In AS3.0
I'm looking for tutorials for enemy AI in ActionScript 3.0

Does anyone know of any or could provide a quick one?

AI Of Enemy
Hello

I'm making a ninja fighting game like street fighter or mortal combat. I can control my player with left and right and let him hit with is sword and throw a ninja star. But when I threw my opponent ninja on the stage, it got mixed up. Can anyone explain how to create the AI of the enemy. On what should I test to let my enemy react or attack and where should I put the code ?

Thx

Enemy Shooting
How do you make an enemy shoot? I am not using the mouse in my game, otherwise I would have used flashjunkie's tutorial. Thanks.

Enemy Scripts
I am trying to make a simple "pong" game but need the scripts to make the enemy move towards the position of the ball. I can make the ball reflect off the players bat but the enemy stands there doing jack all.

Please help if you can

Timo

Enemy In Game
this tutorial shows how to have scrolling backgrounds... thats not what im trying to figure out tho

http://www.flashkit.com/tutorials/Ga...u-82/index.php

im trying to get the cannon out of that tutorial so i can use the script for my game, but theres so many variables that i get lost so could someone please show me how that cannon works so i can do it myself? thanks for any help

Embed With The Enemy
is it possible to embed a movie player like windows media player on a flash site, like you can on a html site?

Enemy Fire Help
Hi,

i have a graphic and inside it are some mc's that move, im trying to get a mc called enemyfire to be attached to the mc's inside the graphic in the correct place but it just keeps adding them somewhere els.

does anyone know howto fix this?

iv attached my FLA i you wanna have a look at it

Copyright © 2005-08 www.BigResource.com, All rights reserved