Page 1 of 1

how to do random stuff

PostPosted: Sat Nov 19, 2011 5:34 am
by raminkhan
Here I attached a file which shows what I need. Okay I got a ball on a screen ALL IN X-DIRECTION. okay now this ball comes on screen, gets hit by the players gun then it stops for a minute then moves toward other objects on X-AXIS then destroys them. then it rolls off the screen. if you can't clearly understand what I mean then please see this .swf file animation. thanks a bunch friends.

Re: how to do random stuff

PostPosted: Sun Nov 20, 2011 12:23 pm
by foleyjo
Quick run down of what to look at to get this to work.

Do this in the balls events and make an actor variable called speed

in create actor use
Code: Select all
xvelocity = speed;  //speed being an actor variable that holds the speed

In the collision between the ball and the bullet
Code: Select all
xvelocity = 0;  //stops the balls movement
createtimer(); //create a new timer (Note you will have to fill the details in for this ti have the correct time and don't loop it)

when the timer ends you want to change the speed value to whatever you want the new speed to be then multiply it by -1 to reverse direction
Code: Select all
speed = speed * -1; //reverse the direction
xvelocity = speed;

On collision with any of the 2 objects do the same
Code: Select all
speed = speed *-1;
xvelocity = speed;

On out of vision destroy the actor

Re: how to do random stuff

PostPosted: Sun Nov 20, 2011 11:46 pm
by raminkhan
can you please make a demo file for this I am really having trouble doing it because its just not working.

Re: how to do random stuff

PostPosted: Mon Nov 21, 2011 3:59 pm
by foleyjo
Not got a lot of spare time at the moment but I quickly knocked up this little prog that demonstrates what I said to do.
You will need to change the actors to match what you want.
The ball will move in one direction till it hits one of the actors on either side. It will then change direction.
Pressing space will make the bullet shoot up. If the ball collides with it there will be a pause and then it will continue in the opposite direction.

Haven't done anything with the direction of the bullet, it will only move up the screen in this demo so try and time it right.
I have also kept the speed of the ball slow so it's easy to hit.

Let me know if there's anything you don't understand

Re: how to do random stuff

PostPosted: Mon Nov 21, 2011 6:07 pm
by raminkhan
LOVE YOUUUUUUU MMMMYYYYYY FFFFFRRRRRIIIIIEEEENNNNDDDD, YOUR AWESOME. THANKS A BUNCH.

Re: how to do random stuff

PostPosted: Wed Nov 23, 2011 10:45 am
by foleyjo
small update as requested in PM