Rev | Line | |
---|
[057edef] | 1 | import java.util.*;
|
---|
| 2 |
|
---|
| 3 | public class ProcessingThread extends Thread {
|
---|
| 4 | LostHavenServer server;
|
---|
| 5 |
|
---|
| 6 | public ProcessingThread(LostHavenServer main) {
|
---|
| 7 | super("ProcessingThread");
|
---|
| 8 | server = main;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | public void run() {
|
---|
| 12 | while(server.running) {
|
---|
| 13 | updateWorld();
|
---|
| 14 | //sendInfo();
|
---|
| 15 | try {
|
---|
| 16 | Thread.sleep(1);
|
---|
| 17 | }catch(InterruptedException ie) {
|
---|
| 18 | ie.printStackTrace();
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | private void updateWorld() {
|
---|
| 24 | Iterator<String> iter = server.orderedOnline.iterator();
|
---|
| 25 | Player p;
|
---|
| 26 | Point loc, target;
|
---|
| 27 |
|
---|
| 28 | while(iter.hasNext()) {
|
---|
| 29 | p = server.registered.get(iter.next());
|
---|
| 30 | loc = p.getLoc();
|
---|
| 31 | target = p.getTarget();
|
---|
| 32 |
|
---|
| 33 | //if((System.currentTimeMillis()-p.getLastMoved())>=10) {
|
---|
| 34 | if(Point.dist(loc, target) <= p.getSpeed())
|
---|
| 35 | p.setLoc(target);
|
---|
| 36 | else {
|
---|
| 37 | int xChange = new Double(p.getSpeed()*(System.currentTimeMillis()-p.getLastMoved())*(target.getX()-loc.getX())/Point.dist(loc, target)/20).intValue();
|
---|
| 38 | int yChange = new Double(p.getSpeed()*(System.currentTimeMillis()-p.getLastMoved())*(target.getY()-loc.getY())/Point.dist(loc, target)/20).intValue();
|
---|
| 39 |
|
---|
| 40 | p.setLoc(new Point(p.getLoc().getX()+xChange, p.getLoc().getY()+yChange));
|
---|
| 41 | }
|
---|
| 42 | p.setLastMoved(System.currentTimeMillis());
|
---|
| 43 | server.sendAll(MessageType.Movement, p.getName()+" "+p.getLoc().toString());
|
---|
| 44 | //}
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.