File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Following and escape two ball Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Following and escape two ball" Watch "Following and escape two ball" New topic
Author

Following and escape two ball

fahimeh hashemian
Ranch Hand

Joined: Aug 07, 2012
Posts: 85
I have a ball in screen , the ball moves via accelerometer sensor. I want shows another ball in screen, that first ball chasing and following second ball and second ball escape of first ball. I searched on the internet but i can't find any link or tutorial, maybee i don't use correct sentence for search, anyway. Please help me with link or advise. Thanks.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

First, you should work with just the ball that reacts to the motion sensor. Read this tutorial: http://developer.android.com/guide/topics/sensors/sensors_motion.html

Then when you have a ball that moves around smoothly you can create the other ball - the logic of the other ball which the user chases.


Steve
fahimeh hashemian
Ranch Hand

Joined: Aug 07, 2012
Posts: 85
Steve Luke wrote:First, you should work with just the ball that reacts to the motion sensor. Read this tutorial: http://developer.android.com/guide/topics/sensors/sensors_motion.html

Then when you have a ball that moves around smoothly you can create the other ball - the logic of the other ball which the user chases.


Thanks for quick reply. I know about how can move a ball with Accelerometer and i implemented this! but i don't know how can implemented this with two ball! When first ball approached to second ball, i want second ball escape of first ball and go to another place . Please help me to implement this Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

In that case, the first thing to do is have the running ball be notified of the location of the first ball. The chaser ball keeps track of its location and publishes its position to listeners (for example). The escaping ball keeps track of its own location and is a listener to the chaser's position. When the escaping ball determines the chaser is too close it moves.

There is decisions on how it moves: how far away does the chaser have to be to move? How far/fast/long is it allowed to move? How does it choose a course to move in (i.e. you have to avoid obstacles, such as the chaser ball)? Does it have a destination? Does it move randomly or towards that destination? Those are all application - specific stuff you will have to work out, but the basic strategy is the chaser is independent and controlled by the phone's motion, while the escaper is a.i. that reacts to the chaser (and whatever other stimuli you provide it). So what you need to do is feed the escaper the coordinates of the chaser so it can react.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Following and escape two ball