Move core launch/landing to CoreBlock (#8055)

* Move core launch/landing to CoreBlock

* Slight cleanup

* just gonna...
This commit is contained in:
MEEPofFaith
2023-02-15 09:16:51 -08:00
committed by GitHub
parent 9b02a274f1
commit a8a3453632
2 changed files with 138 additions and 110 deletions

View File

@@ -32,7 +32,6 @@ public class Renderer implements ApplicationListener{
private static final float cloudScaling = 1700f, cfinScl = -2f, cfinOffset = 0.3f, calphaFinOffset = 0.25f;
private static final float[] cloudAlphas = {0, 0.5f, 1f, 0.1f, 0, 0f};
private static final float cloudAlpha = 0.81f;
private static final float[] thrusterSizes = {0f, 0f, 0f, 0f, 0.3f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 0f};
private static final Interp landInterp = Interp.pow3;
public final BlockRenderer blocks = new BlockRenderer();
@@ -174,13 +173,14 @@ public class Renderer implements ApplicationListener{
laserOpacity = settings.getInt("lasersopacity") / 100f;
bridgeOpacity = settings.getInt("bridgeopacity") / 100f;
animateShields = settings.getBool("animatedshields");
drawStatus = Core.settings.getBool("blockstatus");
drawStatus = settings.getBool("blockstatus");
enableEffects = settings.getBool("effects");
drawDisplays = !settings.getBool("hidedisplays");
if(landTime > 0){
if(!state.isPaused()){
updateLandParticles();
CoreBuild build = landCore == null ? player.bestCore() : landCore;
build.updateLandParticles();
}
if(!state.isPaused()){
@@ -453,63 +453,26 @@ public class Renderer implements ApplicationListener{
}
void updateLandParticles(){
float time = launching ? coreLandDuration - landTime : landTime;
float tsize = Mathf.sample(thrusterSizes, (time + 35f) / coreLandDuration);
landPTimer += tsize * Time.delta;
if(landCore != null && landPTimer >= 1f){
landCore.tile.getLinkedTiles(t -> {
if(Mathf.chance(0.4f)){
Fx.coreLandDust.at(t.worldx(), t.worldy(), landCore.angleTo(t) + Mathf.range(30f), Tmp.c1.set(t.floor().mapColor).mul(1.5f + Mathf.range(0.15f)));
}
});
landPTimer = 0f;
}
}
void drawLanding(){
CoreBuild build = landCore == null ? player.bestCore() : landCore;
var clouds = assets.get("sprites/clouds.png", Texture.class);
if(landTime > 0 && build != null){
float fout = landTime / coreLandDuration;
if(launching) fout = 1f - fout;
float fin = 1f - fout;
//draw core
var block = launching && launchCoreType != null ? launchCoreType : (CoreBlock)build.block;
TextureRegion reg = block.fullIcon;
float scl = Scl.scl(4f) / camerascale;
float shake = 0f;
float s = reg.width * reg.scl() * scl * 3.6f * Interp.pow2Out.apply(fout);
float rotation = Interp.pow2In.apply(fout) * 135f, x = build.x + Mathf.range(shake), y = build.y + Mathf.range(shake);
float thrustOpen = 0.25f;
float thrusterFrame = fin >= thrustOpen ? 1f : fin / thrustOpen;
float thrusterSize = Mathf.sample(thrusterSizes, fin);
//when launching, thrusters stay out the entire time.
if(launching){
Interp i = Interp.pow2Out;
thrusterFrame = i.apply(Mathf.clamp(fout*13f));
thrusterSize = i.apply(Mathf.clamp(fout*9f));
}
Draw.color(Pal.lightTrail);
//TODO spikier heat
Draw.rect("circle-shadow", x, y, s, s);
Draw.color(Pal.lightTrail);
float pfin = Interp.pow3Out.apply(fin), pf = Interp.pow2In.apply(fout);
//draw particles
Draw.color(Pal.lightTrail);
Angles.randLenVectors(1, pfin, 100, 800f * scl * pfin, (ax, ay, ffin, ffout) -> {
Lines.stroke(scl * ffin * pf * 3f);
Lines.lineAngle(build.x + ax, build.y + ay, Mathf.angle(ax, ay), (ffin * 20 + 1f) * scl);
});
Draw.color();
CoreBlock block = launching && launchCoreType != null ? launchCoreType : (CoreBlock)build.block;
block.drawLanding(build, build.x, build.y);
Draw.color();
Draw.mixcol(Color.white, Interp.pow5In.apply(fout));
@@ -522,44 +485,6 @@ public class Renderer implements ApplicationListener{
}
}
Draw.scl(scl);
Draw.alpha(1f);
//draw thruster flame
float strength = (1f + (block.size - 3)/2.5f) * scl * thrusterSize * (0.95f + Mathf.absin(2f, 0.1f));
float offset = (block.size - 3) * 3f * scl;
for(int i = 0; i < 4; i++){
Tmp.v1.trns(i * 90 + rotation, 1f);
Tmp.v1.setLength((block.size * tilesize/2f + 1f)*scl + strength*2f + offset);
Draw.color(build.team.color);
Fill.circle(Tmp.v1.x + x, Tmp.v1.y + y, 6f * strength);
Tmp.v1.setLength((block.size * tilesize/2f + 1f)*scl + strength*0.5f + offset);
Draw.color(Color.white);
Fill.circle(Tmp.v1.x + x, Tmp.v1.y + y, 3.5f * strength);
}
drawThrusters(block, x, y, rotation, thrusterFrame);
Drawf.spinSprite(block.region, x, y, rotation);
Draw.alpha(Interp.pow4In.apply(thrusterFrame));
drawThrusters(block, x, y, rotation, thrusterFrame);
Draw.alpha(1f);
if(block.teamRegions[build.team.id] == block.teamRegion) Draw.color(build.team.color);
Drawf.spinSprite(block.teamRegions[build.team.id], x, y, rotation);
Draw.color();
Draw.scl();
Draw.reset();
//draw clouds
if(state.rules.cloudColor.a > 0.0001f){
float scaling = cloudScaling;
@@ -582,32 +507,6 @@ public class Renderer implements ApplicationListener{
}
}
void drawThrusters(CoreBlock block, float x, float y, float rotation, float frame){
float length = block.thrusterLength * (frame - 1f) - 1f/4f;
float alpha = Draw.getColor().a;
//two passes for consistent lighting
for(int j = 0; j < 2; j++){
for(int i = 0; i < 4; i++){
var reg = i >= 2 ? block.thruster2 : block.thruster1;
float rot = (i * 90) + rotation % 90f;
Tmp.v1.trns(rot, length * Draw.xscl);
//second pass applies extra layer of shading
if(j == 1){
Tmp.v1.rotate(-90f);
Draw.alpha((rotation % 90f) / 90f * alpha);
rot -= 90f;
Draw.rect(reg, x + Tmp.v1.x, y + Tmp.v1.y, rot);
}else{
Draw.alpha(alpha);
Draw.rect(reg, x + Tmp.v1.x, y + Tmp.v1.y, rot);
}
}
}
Draw.alpha(1f);
}
public void scaleCamera(float amount){
targetscale *= (amount / 4) + 1;
clampScale();
@@ -638,6 +537,26 @@ public class Renderer implements ApplicationListener{
clampScale();
}
public boolean isLaunching(){
return launching;
}
public CoreBlock getLaunchCoreType(){
return launchCoreType;
}
public float getLandTime(){
return landTime;
}
public float getLandPTimer(){
return landPTimer;
}
public void setLandPTimer(float landPTimer){
this.landPTimer = landPTimer;
}
public void showLanding(){
launching = false;
camerascale = minZoomScl;

View File

@@ -2,15 +2,18 @@ package mindustry.world.blocks.storage;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -28,6 +31,7 @@ import static mindustry.Vars.*;
public class CoreBlock extends StorageBlock{
//hacky way to pass item modules between methods
private static ItemModule nextItems;
protected static final float[] thrusterSizes = {0f, 0f, 0f, 0f, 0.3f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 0f};
public @Load(value = "@-thruster1", fallback = "clear-effect") TextureRegion thruster1; //top right
public @Load(value = "@-thruster2", fallback = "clear-effect") TextureRegion thruster2; //bot left
@@ -100,7 +104,7 @@ public class CoreBlock extends StorageBlock{
addBar("capacity", (CoreBuild e) -> new Bar(
() -> Core.bundle.format("bar.capacity", UI.formatAmount(e.storageCapacity)),
() -> Pal.items,
() -> e.items.total() / ((float)e.storageCapacity * content.items().count(i -> i.unlockedNow()))
() -> e.items.total() / ((float)e.storageCapacity * content.items().count(UnlockableContent::unlockedNow))
));
}
@@ -196,6 +200,95 @@ public class CoreBlock extends StorageBlock{
}
}
public void drawLanding(CoreBuild build, float x, float y){
float fout = renderer.getLandTime() / coreLandDuration;
if(renderer.isLaunching()) fout = 1f - fout;
float fin = 1f - fout;
float scl = Scl.scl(4f) / renderer.getDisplayScale();
float shake = 0f;
float s = region.width * region.scl() * scl * 3.6f * Interp.pow2Out.apply(fout);
float rotation = Interp.pow2In.apply(fout) * 135f;
x += Mathf.range(shake);
y += Mathf.range(shake);
float thrustOpen = 0.25f;
float thrusterFrame = fin >= thrustOpen ? 1f : fin / thrustOpen;
float thrusterSize = Mathf.sample(thrusterSizes, fin);
//when launching, thrusters stay out the entire time.
if(renderer.isLaunching()){
Interp i = Interp.pow2Out;
thrusterFrame = i.apply(Mathf.clamp(fout*13f));
thrusterSize = i.apply(Mathf.clamp(fout*9f));
}
Draw.color(Pal.lightTrail);
//TODO spikier heat
Draw.rect("circle-shadow", x, y, s, s);
Draw.scl(scl);
//draw thruster flame
float strength = (1f + (size - 3)/2.5f) * scl * thrusterSize * (0.95f + Mathf.absin(2f, 0.1f));
float offset = (size - 3) * 3f * scl;
for(int i = 0; i < 4; i++){
Tmp.v1.trns(i * 90 + rotation, 1f);
Tmp.v1.setLength((size * tilesize/2f + 1f)*scl + strength*2f + offset);
Draw.color(build.team.color);
Fill.circle(Tmp.v1.x + x, Tmp.v1.y + y, 6f * strength);
Tmp.v1.setLength((size * tilesize/2f + 1f)*scl + strength*0.5f + offset);
Draw.color(Color.white);
Fill.circle(Tmp.v1.x + x, Tmp.v1.y + y, 3.5f * strength);
}
drawLandingThrusters(x, y, rotation, thrusterFrame);
Drawf.spinSprite(region, x, y, rotation);
Draw.alpha(Interp.pow4In.apply(thrusterFrame));
drawLandingThrusters(x, y, rotation, thrusterFrame);
Draw.alpha(1f);
if(teamRegions[build.team.id] == teamRegion) Draw.color(build.team.color);
Drawf.spinSprite(teamRegions[build.team.id], x, y, rotation);
Draw.color();
Draw.scl();
Draw.reset();
}
protected void drawLandingThrusters(float x, float y, float rotation, float frame){
float length = thrusterLength * (frame - 1f) - 1f/4f;
float alpha = Draw.getColor().a;
//two passes for consistent lighting
for(int j = 0; j < 2; j++){
for(int i = 0; i < 4; i++){
var reg = i >= 2 ? thruster2 : thruster1;
float rot = (i * 90) + rotation % 90f;
Tmp.v1.trns(rot, length * Draw.xscl);
//second pass applies extra layer of shading
if(j == 1){
Tmp.v1.rotate(-90f);
Draw.alpha((rotation % 90f) / 90f * alpha);
rot -= 90f;
Draw.rect(reg, x + Tmp.v1.x, y + Tmp.v1.y, rot);
}else{
Draw.alpha(alpha);
Draw.rect(reg, x + Tmp.v1.x, y + Tmp.v1.y, rot);
}
}
}
Draw.alpha(1f);
}
public class CoreBuild extends Building{
public int storageCapacity;
public boolean noEffect = false;
@@ -294,6 +387,22 @@ public class CoreBlock extends StorageBlock{
thrusterTime -= Time.delta/90f;
}
public void updateLandParticles(){
float time = renderer.isLaunching() ? coreLandDuration - renderer.getLandTime() : renderer.getLandTime();
float tsize = Mathf.sample(thrusterSizes, (time + 35f) / coreLandDuration);
renderer.setLandPTimer(renderer.getLandPTimer() + tsize * Time.delta);
if(renderer.getLandTime() >= 1f){
tile.getLinkedTiles(t -> {
if(Mathf.chance(0.4f)){
Fx.coreLandDust.at(t.worldx(), t.worldy(), angleTo(t) + Mathf.range(30f), Tmp.c1.set(t.floor().mapColor).mul(1.5f + Mathf.range(0.15f)));
}
});
renderer.setLandPTimer(0f);
}
}
@Override
public boolean canPickup(){
//cores can never be picked up