-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathSunSingleton.java
More file actions
76 lines (70 loc) · 3.14 KB
/
SunSingleton.java
File metadata and controls
76 lines (70 loc) · 3.14 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
/*
* Copyright 2018 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.destinationsol.game.planet;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import org.destinationsol.assets.Assets;
import org.destinationsol.common.SolColor;
import org.destinationsol.common.SolMath;
import org.destinationsol.game.DmgType;
import org.destinationsol.game.GameDrawer;
import org.destinationsol.game.SolCam;
import org.destinationsol.game.SolGame;
import org.destinationsol.game.SolObject;
import org.destinationsol.game.context.Context;
import org.destinationsol.world.generators.SolarSystemGenerator;
public class SunSingleton {
public static final float SUN_HOT_RAD = .75f * SolarSystemGenerator.SUN_RADIUS;
public static final float GRAV_CONST = 2000;
private static final float SUN_DMG = 4f;
private final TextureAtlas.AtlasRegion gradatingTexture;
private final TextureAtlas.AtlasRegion whiteTexture;
private final Color gradatingTint;
private final Color fillTint;
SunSingleton() {
gradatingTexture = Assets.getAtlasRegion("engine:planetStarCommonGrad");
whiteTexture = Assets.getAtlasRegion("engine:planetStarCommonWhiteTex");
gradatingTint = SolColor.col(1, 1);
fillTint = SolColor.col(1, 1);
}
public void draw(SolGame game, GameDrawer drawer, Context context) {
SolCam solCam = context.get(SolCam.class);
Vector2 camPos = solCam.getPosition();
SolarSystem sys = game.getPlanetManager().getNearestSystem(camPos);
Vector2 toCam = SolMath.getVec(camPos);
toCam.sub(sys.getPosition());
float toCamLen = toCam.len();
if (toCamLen < SolarSystemGenerator.SUN_RADIUS) {
float closeness = 1 - toCamLen / SolarSystemGenerator.SUN_RADIUS;
gradatingTint.a = MathUtils.clamp(closeness * 4, (float) 0, (float) 1);
fillTint.a = MathUtils.clamp((closeness - .25f) * 4, (float) 0, (float) 1);
float sz = 2 * solCam.getViewDistance();
float gradAngle = SolMath.angle(toCam) + 90;
drawer.draw(whiteTexture, sz * 2, sz * 2, sz, sz, camPos.x, camPos.y, 0, fillTint);
drawer.draw(gradatingTexture, sz * 2, sz * 2, sz, sz, camPos.x, camPos.y, gradAngle, gradatingTint);
}
SolMath.free(toCam);
}
public void doDmg(SolGame game, SolObject obj, float toSys) {
float dmg = SUN_DMG * game.getTimeStep();
if (SUN_HOT_RAD < toSys) {
return;
}
obj.receiveDmg(dmg, game, null, DmgType.FIRE, null);
}
}