Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
126 lines (99 loc) · 3.41 KB
/
Copy pathMain.java
File metadata and controls
126 lines (99 loc) · 3.41 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import javax.swing.JFrame;
import java.util.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.lang.Thread;
import java.lang.Math;
class main{
public static void main(String[] args){
int screensize=800;
JFrame jframe=new JFrame();
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
jframe.setSize(screensize , screensize);
jframe.addKeyListener(new KeyBoard());
Map map=new Map();
Rainfall rainfall=new Rainfall();
Graphics g=jframe.getGraphics();
BufferedImage sea[]=new BufferedImage[]{new BufferedImage(screensize,screensize,1)
,new BufferedImage(screensize,screensize,1),new BufferedImage(screensize,screensize,1)};
makeSea(screensize, sea[0]);
makeNightSkySea(screensize, sea[1]);
makeNightStormSea(screensize, sea[2]);
BufferedImage drawbuffer=new BufferedImage(screensize,screensize,BufferedImage.TYPE_INT_ARGB);
Graphics drawbuffergraphics=drawbuffer.getGraphics();
long millispassed=System.currentTimeMillis();
map.update();
ShowCrafteables.setGrapihcs(g);
while(true){
(new ShowCrafteables()).main();
boolean onland=map.update();
DayCycleClass.update();
drawbuffergraphics.drawImage(DayCycleClass.isDay() ? sea[0] :
Rainfall.isActive()? sea[2] : sea[1], 0, 0, null);
map.paint(drawbuffergraphics, screensize, screensize);
rainfall.paint(drawbuffergraphics,screensize,screensize);
new Thread(rainfall).start();
g.drawImage(drawbuffer, 0, 0 , null);
try {
if(onland)
Thread.sleep(Math.max(0, 75+millispassed-System.currentTimeMillis()));
else
Thread.sleep(Math.max(0, 25+millispassed-System.currentTimeMillis()));
millispassed=System.currentTimeMillis();
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
private static void makeSea(int screensize, BufferedImage sea){
for(int j=0; j<screensize; j++){
double redbase=75;
double greenbase=100;
double bluebase=125;
double scale=(0.35*(screensize-j-1))/screensize;
scale+=1.0;
Color c=new Color(Math.min(255 , (int)(scale*redbase)) ,
Math.min(255 , (int)(scale*greenbase)), Math.min(255 , (int)(scale*bluebase)));
for(int i=0; i<screensize; i++){
sea.setRGB(i, j, c.getRGB());
}
}
}
private static void makeNightSkySea(int screensize, BufferedImage sea){
for(int j=0; j<screensize; j++){
double redbase=60;
double greenbase=50;
double bluebase=80;
double scale=(0.35*(screensize-j-1))/screensize;
scale+=1.0;
Color c=new Color(Math.min(255 , (int)(scale*redbase)) ,
Math.min(255 , (int)(scale*greenbase)), Math.min(255 , (int)(scale*bluebase)));
for(int i=0; i<screensize; i++){
sea.setRGB(i, j, c.getRGB());
}
}
Random RND=new Random();
Graphics g=sea.getGraphics();
for(int i=0; i<5000; i++){
Color c=new Color(200,220,255,RND.nextInt(100));
g.setColor(c);
g.fillRect(RND.nextInt(screensize), RND.nextInt(screensize),2,2);
}
}
private static void makeNightStormSea(int screensize, BufferedImage sea){
for(int j=0; j<screensize; j++){
double redbase=45;
double greenbase=60;
double bluebase=75;
double scale=(0.35*(screensize-j-1))/screensize;
scale+=1.0;
Color c=new Color(Math.min(255 , (int)(scale*redbase)) ,
Math.min(255 , (int)(scale*greenbase)), Math.min(255 , (int)(scale*bluebase)));
for(int i=0; i<screensize; i++){
sea.setRGB(i, j, c.getRGB());
}
}
}
}