To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-14-2007, 01:53 PM   #1
PXzyan
Patrick
 
Join Date: Feb 2006
Location: Ireland
Posts: 42
HELP object moves left, when hits a wall, how do I make him turn around and move that

Hey guys,

I am not a compleat noob at actionscripting but I have a problem here..very tricky and flash always ends up terminating the script during gamplay as it just does not work the way I think it should.

Anyway. I will give you an example of what I am doing:

I am making a game like Security 2. 2D overhead view where you are an agent going from room to room collecting objects and compleating objectives.

So far I have managed to create 1 unit..and duplicate that to make many more enemys which makes things very easy.

Now, I have the enemy spawn randomly around the map..max units are 7 and they will auto move to the left. Code looks like this:

this._x = random(600)+100;
this._y = random(480);
this.speed = random(3)+1;

now..I want it so when they meet a wall, they will rotate 180 degrees and move the other way...and t hen onec they hit another wall..they will rotate again and move that way!

this code is long here..works perfectly atm...it spawns the units..tells them to move at a random speed and spawn randomly...if you can..please show me how to make it so..hey will turn and move the other way!!

onClipEvent (load) {
function reset() {
if (this._name == "enemy") {
this._visible = false;
} else {
this._visible = true;
}
this._x = random(600)+100;
this._y = random(480);
this.speed = random(3)+1;
}
this.reset();
}
onClipEvent (enterFrame) {
this._x -= this.speed;
if (this._x<-50) {
this.reset();
}
}
onClipEvent (load) {
power = 3;
radius = 6;
}
onClipEvent (enterFrame) {
while (_root.wall.hitTest(_x-radius, _y, true)) {
_x++;
}
while (_root.wall.hitTest(_x+radius, _y, true)) {
_x--;
}
if ((_root.enemy.hitTest(_x, _y+radius, true)) or (_root.enemy.hitTest(_x, _y-radius, true)) or (_root.enemy.hitTest(_x+radius, _y, true)) or (_root.enemy.hitTest(_x-radius, _y, true))) {
_x = 1000;
_y = 1000;
}
}


Thank you for listening and I hope you can give me a hand.
PXzyan is offline   Reply With Quote
Old 07-09-2007, 01:49 PM   #2
sturesten
Member
 
Join Date: Jul 2007
Posts: 32
I think this will do it ( i havent tested).

if(this.hitTest(_root.wall_right)
this._rotation = 180
move = 5
plusminus = +
}
}
the moving is the variable move. you will have to do like this in the begining:

this._x plusminus= move
(dont know if plusminus is working)

it will look like this in the end:

this._x += 5

i dont know if you can write:

this._x = +5

if you can you can just set move to +5

so it whould look like this:

this._x = move

or:

this._x = +5

Hope this will help you.
sturesten is offline   Reply With Quote
Old 07-09-2007, 02:33 PM   #3
PXzyan
Patrick
 
Join Date: Feb 2006
Location: Ireland
Posts: 42
Thanks! I shall try this out!
PXzyan is offline   Reply With Quote
Old 07-10-2007, 04:28 AM   #4
sturesten
Member
 
Join Date: Jul 2007
Posts: 32
You are welcome
sturesten is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:53 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.