-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSun.java
More file actions
55 lines (47 loc) · 1.26 KB
/
Sun.java
File metadata and controls
55 lines (47 loc) · 1.26 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Enemy.java
// Wendy Xu
// Makes sun that the sunflowers create or the sky generates
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.io.*;
class Sun{
private double[] pos;
private double land; // where sun will land
private int landCount; // counts how long sun landed
private boolean timeUp; // counts how long sun has landed
private Image sunPic = new ImageIcon("Images/Game/sun.png").getImage();
private Rectangle2D sunRect;
public Sun(double[] pos, double land){
this.pos = pos;
landCount = 0;
timeUp = false;
sunRect = new Rectangle2D.Double(pos[0]-35,pos[1]-35,70,70);
this.land = land;
}
public void move(){
if(pos[1] < land){
pos[1] += 0.3;
sunRect.setRect(pos[0]-35,pos[1]-35,70,70);
}
else{
landCount ++;
if(landCount == 500){
timeUp = true;
}
}
}
public boolean timeUp(){ // checks if time is up for sun to disappear
return timeUp;
}
public boolean checkCollision(int[] pos){
return sunRect.contains(pos[0],pos[1]);
}
public void draw(Graphics g, JPanel panel){ // draws sun
g.setColor(Color.RED);
g.drawRect((int)pos[0]-35,(int)pos[1]-35,70,70); // draw rect
g.drawImage(sunPic,(int)pos[0]-45,(int)pos[1]-45,panel);
}
}