-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpellet.java
45 lines (45 loc) · 1.87 KB
/
pellet.java
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
35
36
37
38
39
40
41
42
43
44
45
package snake;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
class pellet extends JComponent{
int x = 0, y = 0, si = m.sizeOfObjects;
Rectangle2D.Float p = new Rectangle2D.Float(x,y,si,si);
Random r = new Random();
pellet(){
setSize(m.dx,m.dy);
newRandomLocation();
}
public void paintComponent(Graphics co){
Graphics2D g = (Graphics2D) co;
p.setFrame(x,y,si,si);
g.setColor(Color.RED);
g.fill(p);
}
void newRandomLocation(){
int newx = r.nextInt(m.dx);
int newy = r.nextInt(m.dy);
System.out.println(newx + " | " + newy);
if(newx % m.sizeOfObjects != 0){
while(newx % 10 != 0){
newx--;
}
}
if(newy % m.sizeOfObjects != 0){
while(newy % 10 != 0){
newy--;
}
}
if(newx > m.dx - (m.sizeOfObjects * 16)){
newx-=(m.sizeOfObjects * 16);
}
if(newy > m.dy - (m.sizeOfObjects * 16)){
newy-=(m.sizeOfObjects * 16);
}
x = newx;
y = newy;
System.out.println("After Proecessing: " + newx + " | " + newy);
repaint();
}
}