public
Description:
Homepage: http://tjgames.org
Clone URL: git://github.com/ComputerDruid/gwar.git
gwar / Item.java
100644 34 lines (32 sloc) 0.711 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import javax.swing.*;
import java.awt.*;
 
class Item
{
int r;
double x,y,lX,lY;
java.awt.Color c;
public Item(double x, double y, int r, java.awt.Color c)
{
//probably shouldn't be using shadowing
this.x=x;
this.y=y;
this.lX = x;
this.lY = y;
this.r=r;
this.c=c;
}
public boolean intersects(Item b)
{
return Math.sqrt(Math.pow(x-b.x,2)+Math.pow(y-b.y,2))<=r+b.r;
}
public void draw(java.awt.Graphics g)
{
g.setColor(c);
g.fillOval((int)x-r,(int)y-r,2*r,2*r);
}
public void draw(java.awt.Graphics g, double xScale, double yScale)
{
g.setColor(c);
g.fillOval((int)((x-r)*xScale),(int)((y-r)*yScale),(int)(2*r*xScale),(int)(2*r*yScale));
}
}