Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Following and escape two ball

 
fahimeh hashemian
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fahimeh hashemian
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic