In my ongoing quest to get a handle on Java, I decided to undertake a personal project involving objects (dots) moving across a window. We've been discussing mobility models for MANETs in my networking class and it suggested to me that trying to implement the Random Waypoint mobility model (the most basic of them) would be a good exercise. The algorithm is as follows:
1). Pick a random position in on the map, and jump to it.
2). Loop:
- Pause for P0 seconds.
- Pick a random position X on the map.
- Pick a random speed s that is between some minimum (usually 0) and some maximum.
- Move towards X at constant speed s.
3). Jump to step 2.
So I've been taking this in steps. First figuring out how to draw multiple objects to the screen, then figuring how to get those objects to move around. So far it works, except the objects simply teleport around the screen rather than actually moving to their next location at some constant speed. The code I have so far, after initializing all the objects/placing them on the map, is as follows:
http://pastebin.com/5X2KUck2
Now this is clearly pretty damn basic, as the object is merely moved a pixel at a time until it reaches its destination. However, the way it is now its just a bunch of dots teleporting around the screen. For what I want, I know that the parameters I'll need are pause time and speed in pixels/millisecond. I also know I'll need linear interpolation and the passage of time (the difference between when the loop started and the current time) to determine how far the dot should move at any given point. I've made several attempts so far but I only get a program that hangs forever. So I'm making this post now in the hopes I can be steered in the right direction. If you need any more information, I'll be more than happy to provide it.