Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / client / RobotIcon.java @ 533

History | View | Annotate | Download (1.65 KB)

1
/*
2
*         RobotIcon class
3
*         Provides a means for graphically representing and keeping track of webcam bots.
4
*/
5

    
6
import javax.swing.*;
7
import javax.swing.event.*;
8
import javax.imageio.*;
9
import java.awt.*;
10
import java.awt.image.*;
11
import java.awt.event.*;
12
import java.net.*;
13
import java.io.*;
14
import java.util.*;
15

    
16
public class RobotIcon {
17
        public final int RADIUS = 30;
18
        public final int CLOSE = 80;
19

    
20
        public int x, y;
21
        public int destx, desty;
22
        public int id;
23
        public Color color;
24
        public int battery;
25

    
26
        public RobotIcon (int id, int x, int y) {
27
                this.color = Color.RED;
28
                this.x = x;
29
                this.y = y;
30
                this.id = id;
31
                this.destx = -1;
32
                this.desty = -1;
33
                this.battery = -1;
34
        }
35

    
36
        /**
37
                *         Relocates this RobotIcon to a new coordinate point.
38
                *
39
                */
40
        public void move (int newX, int newY) {
41
                this.x = newX;
42
                this.y = newY;
43
        }
44

    
45
        /**
46
                *         Determines if a given point is within a reasonable range of the current location
47
                *         to be considered the same robot when moving. The threshold is determined by the
48
                *         CLOSE value.
49
                *
50
                *         @returns Whether or not the given point is reasonably close to the current location.
51
                *
52
                */
53
        public boolean isClose (int nx, int ny) {
54
                int dist = (int) Point.distance(this.x, this.y, nx, ny);
55
                return (dist < CLOSE);
56
        }
57

    
58
        /**
59
                *         Determines whether a given point is within the rectangle that circumscribes the
60
                *         robot's circlular icon. Used for clicking on robots in webcam view.
61
                *
62
                */
63
        public boolean contains (int px, int py) {
64
                Rectangle rect = new Rectangle(x-RADIUS, y-RADIUS, 2*RADIUS, 2*RADIUS);
65
                return rect.contains(px, py);
66
        }
67

    
68
        public String toString () {
69
                String s = "RobotIcon at (" + x + "," + y + "), id " + id;
70
                return s;
71
        }
72
}