Skip to content

Commit 53dfd38

Browse files
committed
Gravitational lensing
1 parent 92cde02 commit 53dfd38

File tree

11 files changed

+209
-143
lines changed

11 files changed

+209
-143
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#define HIGHP
2+
3+
#define HALFPI 3.1415926535897932384626433832795 / 2.0
4+
5+
uniform sampler2D u_texture;
6+
7+
uniform vec2 u_campos;
8+
uniform vec2 u_resolution;
9+
10+
uniform vec2 u_center;
11+
uniform vec2 u_radii;
12+
13+
varying vec2 v_texCoords;
14+
15+
float interp(float a){
16+
return 1.0 - cos(a * HALFPI);
17+
}
18+
19+
void main() {
20+
vec2 c = v_texCoords.xy;
21+
vec2 coords = (c * u_resolution) + u_campos;
22+
float dst = distance(u_center, coords);
23+
24+
if(dst < u_radii.x){
25+
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
26+
}else if(dst > u_radii.y){
27+
gl_FragColor = texture2D(u_texture, c);
28+
}else{
29+
float p = (dst - u_radii.x) / (u_radii.y - u_radii.x);
30+
p = interp(p);
31+
float a = atan(coords.x - u_center.x, coords.y - u_center.y) + HALFPI;
32+
vec2 pos = u_center + vec2(-u_radii.y * cos(a) * p, u_radii.y * sin(a) * p);
33+
gl_FragColor = texture2D(u_texture, (pos - u_campos) / u_resolution);
34+
}
35+
}

assets/shaders/passThrough.frag

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#define HIGHP
2+
3+
uniform sampler2D u_texture;
4+
5+
varying vec2 v_texCoords;
6+
7+
void main() {
8+
gl_FragColor = texture2D(u_texture, v_texCoords.xy);
9+
}

src/progressed/content/blocks/PMBlocks.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ public void setStats(){
765765
reload = 520f;
766766
range = 256f;
767767
shootEffect = smokeEffect = Fx.none;
768-
shoot.firstShotDelay = EnergyFx.kugelblitzCharge.lifetime - 1f;
768+
shoot.firstShotDelay = EnergyFx.kugelblitzGrow.lifetime - 1f;
769769
rotateSpeed = 2f;
770770
recoil = 2f;
771771
recoilTime = 240f;

src/progressed/content/bullets/PMBullets.java

+2-39
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PMBullets{
2727

2828
blackHole, absorbed,
2929

30-
harbingerLaser, excaliburLaser, sentinelLaser,
30+
excaliburLaser, sentinelLaser,
3131

3232
harmanuke,
3333

@@ -110,7 +110,7 @@ public static void load(){
110110
backMove = false;
111111
lightRadius = 8f;
112112
lightOpacity = 0.7f;
113-
chargeEffect = EnergyFx.kugelblitzCharge;
113+
chargeEffect = EnergyFx.kugelblitzGrow;
114114
}};
115115

116116
absorbed = new BulletType(0f, 0f){
@@ -135,43 +135,6 @@ public void update(Bullet b){
135135
}
136136
};
137137

138-
harbingerLaser = new LaserBulletType(Float.POSITIVE_INFINITY){
139-
{
140-
colors = new Color[]{Color.valueOf("F3E97966"), Color.valueOf("F3E979"), Color.white};
141-
length = 900f;
142-
width = 75f;
143-
lifetime = 130;
144-
lightColor = colors[1];
145-
ammoMultiplier = 1;
146-
147-
lightningSpacing = 20f;
148-
lightningLength = 15;
149-
lightningLengthRand = 10;
150-
lightningDelay = 0.5f;
151-
lightningDamage = (float)Double.MAX_VALUE;
152-
lightningAngleRand = 45f;
153-
lightningColor = colors[1];
154-
155-
sideAngle = 25f;
156-
sideWidth = width / 8f;
157-
sideLength = length / 1.5f;
158-
159-
chargeEffect = EnergyFx.harbingerCharge;
160-
}
161-
162-
@Override
163-
public void hitTile(Bullet b, Building build, float x, float y, float initialHealth, boolean direct){
164-
super.hitTile(b, build, x, y, initialHealth, direct);
165-
if(build.team != b.team) build.kill();
166-
}
167-
168-
@Override
169-
public void hitEntity(Bullet b, Hitboxc other, float initialHealth){
170-
super.hitEntity(b, other, initialHealth);
171-
if(((Teamc)other).team() != b.team) ((Healthc)other).kill();
172-
}
173-
};
174-
175138
excaliburLaser = new CrossLaserBulletType(1500f){{
176139
length = 800f;
177140
width = 26f;

src/progressed/content/effects/EnergyFx.java

+10-78
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
import progressed.graphics.renders.*;
1111

1212
import static arc.graphics.g2d.Draw.*;
13-
import static arc.graphics.g2d.Lines.line;
1413
import static arc.graphics.g2d.Lines.*;
1514
import static arc.math.Angles.*;
1615
import static arc.util.Tmp.*;
17-
import static mindustry.graphics.Drawf.*;
1816

1917
public class EnergyFx{
2018
public static Effect
@@ -58,34 +56,18 @@ public class EnergyFx{
5856
}
5957
}),
6058

61-
kugelblitzCharge = new Effect(80f, e -> {
62-
float in = 6f,
63-
out = 160f;
64-
PMRenders.blackHole(e.x, e.y, in * e.fin(), (in + (out - in) * 0.33f) * e.fin(), e.color);
59+
kugelblitzGrow = new Effect(80f, e -> {
60+
float in = 6f;
61+
float fin = e.fin(Interp.sineOut);
62+
PMRenders.blackHole(e.x, e.y, in * fin, in * 6f * fin, e.color);
6563
}),
6664

6765
blackHoleSwirl = makeSwirlEffect(90f, 8, 3f, 90f, 720f, true).layer(Layer.effect + 0.005f),
6866

69-
blackHoleDespawn = new Effect(24f, e -> {
70-
color(Color.darkGray, Color.black, e.fin());
71-
72-
e.scaled(12f, s -> {
73-
stroke(2f * e.fout());
74-
Lines.circle(e.x, e.y, s.fin() * 10f);
75-
});
76-
77-
stroke(2f * e.fout());
78-
randLenVectors(e.id, 4, e.fin() * 15f, (x, y) -> {
79-
float ang = angle(x, y);
80-
lineAngle(e.x + x, e.y + y, ang, e.fout() * 3 + 1f);
81-
});
82-
83-
color(e.color);
84-
randLenVectors(e.id * 2L, 4, e.fin() * 15f, (x, y) -> {
85-
float ang = angle(x, y);
86-
lineAngle(e.x + x, e.y + y, ang, e.fout() * 3 + 1f);
87-
});
88-
}).layer(Layer.effect + 0.005f),
67+
blackHoleDespawn = new Effect(40f, e -> {
68+
Lines.stroke(2f * e.fout(), Color.black);
69+
Lines.circle(e.x, e.y, 18f * e.fin(Interp.pow3Out));
70+
}).layer(Layer.effect + 0.03f),
8971

9072
blackHoleAbsorb = new Effect(20f, e -> {
9173
color(Color.black);
@@ -132,57 +114,7 @@ public class EnergyFx{
132114
}
133115

134116
Drawf.light(e.x, e.y, circleRad * 1.6f, Pal.heal, e.fout());
135-
}),
136-
137-
harbingerCharge = new Effect(150f, 1600f, e -> {
138-
Color[] colors = {Color.valueOf("D99F6B55"), Color.valueOf("E8D174aa"), Color.valueOf("F3E979"), Color.valueOf("ffffff")};
139-
float[] tscales = {1f, 0.7f, 0.5f, 0.2f};
140-
float[] strokes = {2f, 1.5f, 1, 0.3f};
141-
float[] lenscales = {1, 1.12f, 1.15f, 1.17f};
142-
143-
float lightOpacity = 0.4f + (e.finpow() * 0.4f);
144-
145-
Draw.color(colors[0], colors[2], 0.5f + e.finpow() * 0.5f);
146-
Lines.stroke(Mathf.lerp(0f, 28f, e.finpow()));
147-
Lines.circle(e.x, e.y, 384f * (1f - e.finpow()));
148-
149-
for(int i = 0; i < 36; i++){
150-
v1.trns(i * 10f, 384f * (1 - e.finpow()));
151-
v2.trns(i * 10f + 10f, 384f * (1f - e.finpow()));
152-
light(e.x + v1.x, e.y + v1.y, e.x + v2.x, e.y + v2.y, 14f / 2f + 60f * e.finpow(), Draw.getColor(), lightOpacity + (0.2f * e.finpow()));
153-
}
154-
155-
float fade = 1f - Mathf.curve(e.time, e.lifetime - 30f, e.lifetime);
156-
float grow = Mathf.curve(e.time, 0f, e.lifetime - 30f);
157-
158-
for(int i = 0; i < 4; i++){
159-
float baseLen = (900f + (Mathf.absin(Time.time / ((i + 1f) * 2f) + Mathf.randomSeed(e.id), 0.8f, 1.5f) * (900f / 1.5f))) * 0.75f * fade;
160-
Draw.color(Tmp.c1.set(colors[i]).mul(1f + Mathf.absin(Time.time / 3f + Mathf.randomSeed(e.id), 1.0f, 0.3f) / 3f));
161-
for(int j = 0; j < 2; j++){
162-
int dir = Mathf.signs[j];
163-
for(int k = 0; k < 10; k++){
164-
float side = k * (360f / 10f);
165-
for(int l = 0; l < 4; l++){
166-
Lines.stroke((16f * 0.75f + Mathf.absin(Time.time, 0.5f, 1f)) * grow * strokes[i] * tscales[l]);
167-
Lines.lineAngle(e.x, e.y, (e.rotation + 360f * e.finpow() + side) * dir, baseLen * lenscales[l], false);
168-
}
169-
170-
v1.trns((e.rotation + 360f * e.finpow() + side) * dir, baseLen * 1.1f);
171-
172-
light(e.x, e.y, e.x + v1.x, e.y + v1.y, ((16f * 0.75f + Mathf.absin(Time.time, 0.5f, 1f)) * grow * strokes[i] * tscales[j]) / 2f + 60f * e.finpow(), colors[2], lightOpacity);
173-
}
174-
}
175-
Draw.reset();
176-
}
177-
}),
178-
179-
//[circle radius, distance]
180-
everythingGunSwirl = new Effect(120f, 1600f, e -> {
181-
float[] data = (float[])e.data;
182-
v1.trns(Mathf.randomSeed(e.id, 360f) + e.rotation * e.fin(), (16f + data[1]) * e.fin());
183-
color(e.color, Color.black, 0.25f + e.fin() * 0.75f);
184-
Fill.circle(e.x + v1.x, e.y + v1.y, data[0] * e.fout());
185-
}).layer(Layer.bullet - 0.00999f);
117+
});
186118

187119
public static Effect makeSwirlEffect(Color color, float eLifetime, int length, float maxWidth, float minRot, float maxRot, float minDst, float maxDst, boolean lerp){
188120
return new Effect(eLifetime, 400f, e -> {
@@ -191,7 +123,7 @@ public static Effect makeSwirlEffect(Color color, float eLifetime, int length, f
191123
float lifetime = e.lifetime - length;
192124
float dst;
193125
if(minDst < 0 || maxDst < 0){
194-
dst = Math.abs(e.rotation);;
126+
dst = Math.abs(e.rotation);
195127
}else{
196128
dst = Mathf.randomSeed(e.id, minDst, maxDst);
197129
}

src/progressed/entities/bullet/energy/BlackHoleBulletType.java

+25-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class BlackHoleBulletType extends BulletType{
3030

3131
public Color color = Color.black;
3232
public Effect absorbEffect = EnergyFx.blackHoleAbsorb, swirlEffect = EnergyFx.blackHoleSwirl;
33-
public float suctionRadius = 160f, size = 6f, damageRadius = 17f;
33+
public float suctionRadius = 160f, size = 6f, lensEdge = -1f, damageRadius = 17f;
3434
public float force = 10f, scaledForce = 800f, bulletForce = 0.1f, bulletScaledForce = 2f;
3535
public float swirlInterval = 3f;
3636
public int swirlEffects = 4;
@@ -46,6 +46,14 @@ public BlackHoleBulletType(float speed, float damage){
4646
layer = Layer.effect + 0.03f;
4747
}
4848

49+
@Override
50+
public void init(){
51+
super.init();
52+
if(lensEdge < 0f) lensEdge = size * 6f;
53+
54+
drawSize = Math.max(drawSize, lensEdge * 2f);
55+
}
56+
4957
@Override
5058
public float continuousDamage(){
5159
return damage / 2f * 60f; //Damage every 2 ticks
@@ -54,20 +62,22 @@ public float continuousDamage(){
5462
@Override
5563
public void update(Bullet b){
5664
if(b.timer(1, 2f)){
57-
PMDamage.completeDamage(b.team, b.x, b.y, damageRadius, b.damage);
65+
float fout = fout(b);
66+
PMDamage.completeDamage(b.team, b.x, b.y, damageRadius * fout, b.damage);
5867

59-
Units.nearbyEnemies(b.team, b.x - suctionRadius, b.y - suctionRadius, suctionRadius * 2f, suctionRadius * 2f, unit -> {
60-
if(unit.within(b.x, b.y, suctionRadius)){
61-
Vec2 impulse = Tmp.v1.trns(unit.angleTo(b), force + (1f - unit.dst(b) / suctionRadius) * scaledForce);
68+
float sR = suctionRadius * fout;
69+
Units.nearbyEnemies(b.team, b.x - sR, b.y - sR, sR * 2f, sR * 2f, unit -> {
70+
if(unit.within(b.x, b.y, sR)){
71+
Vec2 impulse = Tmp.v1.trns(unit.angleTo(b), force + (1f - unit.dst(b) / sR) * scaledForce);
6272
if(repel) impulse.rotate(180f);
6373
unit.impulseNet(impulse);
6474
}
6575
});
6676

67-
Groups.bullet.intersect(b.x - suctionRadius, b.y - suctionRadius, suctionRadius * 2f, suctionRadius * 2f, other -> {
68-
//if(other != null && Mathf.within(b.x, b.y, other.x, other.y, suctionRadius) && b != other && b.team != other.team && other.type.speed > 0.01f && !checkType(other.type)){
69-
if(other != null && Mathf.within(b.x, b.y, other.x, other.y, suctionRadius) && b != other && b.team != other.team && b.type.absorbable && other.type.speed > 0.01f){
70-
Vec2 impulse = Tmp.v1.trns(other.angleTo(b), bulletForce + (1f - other.dst(b) / suctionRadius) * bulletScaledForce);
77+
Groups.bullet.intersect(b.x - sR, b.y - sR, sR * 2f, sR * 2f, other -> {
78+
//if(other != null && Mathf.within(b.x, b.y, other.x, other.y, sR) && b != other && b.team != other.team && other.type.speed > 0.01f && !checkType(other.type)){
79+
if(other != null && Mathf.within(b.x, b.y, other.x, other.y, sR) && b != other && b.team != other.team && b.type.absorbable && other.type.speed > 0.01f){
80+
Vec2 impulse = Tmp.v1.trns(other.angleTo(b), bulletForce + (1f - other.dst(b) / sR) * bulletScaledForce);
7181
if(repel) impulse.rotate(180f);
7282
other.vel().add(impulse);
7383

@@ -102,14 +112,19 @@ public void updateTrailEffects(Bullet b){
102112

103113
@Override
104114
public void draw(Bullet b){
105-
PMRenders.blackHole(b.x, b.y, size, size + (suctionRadius - size) * 0.33f, b.team.color);
115+
float fout = fout(b);
116+
PMRenders.blackHole(b.x, b.y, size * fout, lensEdge * fout, b.team.color);
106117
}
107118

108119
@Override
109120
public void drawLight(Bullet b){
110121
//none
111122
}
112123

124+
public float fout(Bullet b){
125+
return Interp.sineOut.apply(1 - Mathf.curve(b.time, b.lifetime - swirlEffect.lifetime, b.lifetime));
126+
}
127+
113128
@Override
114129
public void despawned(Bullet b){
115130
despawnEffect.at(b.x, b.y, b.rotation(), b.team.color);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package progressed.entities.effect;
2+
3+
import arc.graphics.g2d.*;
4+
import mindustry.entities.*;
5+
6+
public class RepeatEffect extends Effect{
7+
public Effect effect;
8+
public float interval;
9+
public int times;
10+
11+
public RepeatEffect(Effect effect, float interval, int times){
12+
this.effect = effect;
13+
this.interval = interval;
14+
this.times = times;
15+
}
16+
17+
@Override
18+
public void init(){
19+
lifetime = interval * times + effect.lifetime;
20+
clip = effect.clip;
21+
}
22+
23+
@Override
24+
public void render(EffectContainer e){
25+
var cont = e.inner();
26+
float life = e.time;
27+
for(int i = 0; i < times; i++){
28+
float del = i * interval;
29+
if(life > del && life <= del + effect.lifetime){
30+
cont.set(e.id + i, e.color, life - del, effect.lifetime, e.rotation, e.x, e.y, e.data);
31+
Draw.z(effect.layer);
32+
effect.render(cont);
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)