source: java-rpg-server/ProcessingThread.java@ 4fbc6ff

Last change on this file since 4fbc6ff was 4fbc6ff, checked in by dportnoy <dmp1488@…>, 17 years ago

[svn r31]

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import java.util.*;
2
3/*
4 * This thread handles events in the world such as monster movement and player movement and other things that do not require player input. It
5 * also sends information to all players to notify them of changes in the world.
6 */
7
8public class ProcessingThread extends Thread {
9 LostHavenServer server;
10
11 public ProcessingThread(LostHavenServer main) {
12 super("ProcessingThread");
13 server = main;
14 }
15
16 public void run() {
17 while(server.running) {
18 updateWorld();
19 //sendInfo();
20 try {
21 Thread.sleep(1);
22 }catch(InterruptedException ie) {
23 ie.printStackTrace();
24 }
25 }
26 }
27
28 private void updateWorld() {
29 Iterator<String> iter = server.orderedOnline.iterator();
30 Player p;
31 Point loc, target;
32
33 while(iter.hasNext()) {
34 p = server.registered.get(iter.next());
35 loc = p.getLoc();
36 target = p.getTarget();
37
38 //if((System.currentTimeMillis()-p.getLastMoved())>=10) {
39 if(Point.dist(loc, target) <= p.getSpeed())
40 p.setLoc(target);
41 else {
42 int xChange = new Double(p.getSpeed()*(System.currentTimeMillis()-p.getLastMoved())*(target.getX()-loc.getX())/Point.dist(loc, target)/20).intValue();
43 int yChange = new Double(p.getSpeed()*(System.currentTimeMillis()-p.getLastMoved())*(target.getY()-loc.getY())/Point.dist(loc, target)/20).intValue();
44
45 p.setLoc(new Point(p.getLoc().getX()+xChange, p.getLoc().getY()+yChange));
46 }
47 p.setLastMoved(System.currentTimeMillis());
48 server.sendAll(MessageType.Movement, p.getName()+" "+p.getLoc().toString());
49 //}
50 }
51 }
52}
Note: See TracBrowser for help on using the repository browser.