-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrain.java
63 lines (48 loc) · 1.33 KB
/
Terrain.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.awt.Color;
import java.awt.Graphics;
public class Terrain {
static final int DEF_R = 255, DEF_G = 255, DEF_B = 255, COLOR_CONSTANT = 5;
int xCoord, yCoord, temp, altitude;
// An Object's position, expects int between 0 and Game.GAME_SIZE
Color tileTemp = Color.WHITE, tileAlt = Color.WHITE;
Game game;
public Terrain(Game game, int x, int y, int temp, int altitude) {
this.game = game;
xCoord = x;
yCoord = y;
setTemperature(temp);
setAltitude(altitude);
}
public Terrain(Game game, int x, int y) {
this.game = game;
xCoord = x;
yCoord = y;
setTemperature(0);
setAltitude(0);
}
void setTemperature(int temp) {
this.temp = temp;
if (temp < 0) {
tileTemp = new Color(DEF_R + (temp*COLOR_CONSTANT), DEF_G + (temp*COLOR_CONSTANT), DEF_B);
} else {
tileTemp = new Color(DEF_R, DEF_G - (temp*COLOR_CONSTANT), DEF_B - (temp*COLOR_CONSTANT));
}
}
void setAltitude(int alt) {
this.altitude = alt;
tileAlt = new Color(0,
DEF_G + (((alt - GenerateTerrain.HEIGHT_RANGE) / 2) *COLOR_CONSTANT), DEF_B);
}
protected void paint(Graphics g) {
switch (game.currentView) {
case Game.VIEW_TEMP:
g.setColor(tileTemp);
break;
case Game.VIEW_ALT:
g.setColor(tileAlt);
break;
}
g.fillRect(xCoord * game.zoomLevel, yCoord * game.zoomLevel,
game.zoomLevel, game.zoomLevel);
}
}