Skip to content

Commit

Permalink
WIP Interplanetary Accelerator animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Jan 29, 2025
1 parent 2253884 commit 6c31853
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 171 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ ability.stat.buildtime = [stat]{0} sec[lightgray] build time

bar.onlycoredeposit = Only Core Depositing Allowed
bar.drilltierreq = Better Drill Required
bar.nobatterypower = Insufficieny Battery Power
bar.nobatterypower = Insufficient Battery Power
bar.noresources = Missing Resources
bar.corereq = Core Base Required
bar.corefloor = Core Zone Tile Required
Expand All @@ -1100,7 +1100,7 @@ bar.drillspeed = Drill Speed: {0}/s
bar.pumpspeed = Pump Speed: {0}/s
bar.efficiency = Efficiency: {0}%
bar.boost = Boost: +{0}%
bar.powerbuffer = Battery Power: {0}/{1}
bar.powerbuffer = Batteries: {0}/{1}
bar.powerbalance = Power: {0}/s
bar.powerstored = Stored: {0}/{1}
bar.poweramount = Power: {0}
Expand Down
8 changes: 6 additions & 2 deletions core/assets/shaders/blockbuild.frag
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ bool cont(vec2 T, vec2 v){
id(T + vec2(-step, -step) * v, base) || id(T + vec2(-step, step) * v, base));
}

vec4 blend(vec4 dst, vec4 src){
return src * src.a + dst * (1.0 - src.a);
}

void main(){

vec2 t = v_texCoords.xy;
Expand All @@ -41,11 +45,11 @@ void main(){
float dst = (abs(center.x - coords.x) + abs(center.y - coords.y))/2.0;

if((mod(u_time / 1.5 + value, 20.0) < 15.0 && cont(t, v))){
gl_FragColor = v_color;
gl_FragColor = blend(color, v_color);
}else if(dst > (1.0-u_progress) * (center.x)){
gl_FragColor = color;
}else if((dst + 2.0 > (1.0-u_progress) * (center.x)) && color.a > 0.1){
gl_FragColor = v_color;
gl_FragColor = blend(color, v_color);
}else{
gl_FragColor = vec4(0.0);
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/mindustry/content/Fx.java
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,12 @@ public class Fx{
});
}),

launchAccelerator = new Effect(22, e -> {
color(Pal.accent);
stroke(e.fout() * 2f);
Lines.circle(e.x, e.y, 4f + e.finpow() * 160f);
}),

launch = new Effect(28, e -> {
color(Pal.command);
stroke(e.fout() * 2f);
Expand Down
4 changes: 2 additions & 2 deletions core/src/mindustry/core/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ public Control(){

float coreDelay = 0f;
if(!settings.getBool("skipcoreanimation") && !state.rules.pvp){
coreDelay = core.landDuration();
coreDelay = core.launchDuration();
//delay player respawn so animation can play.
player.deathTimer = Player.deathDelay - core.landDuration();
player.deathTimer = Player.deathDelay - core.launchDuration();
//TODO this sounds pretty bad due to conflict
if(settings.getInt("musicvol") > 0){
//TODO what to do if another core with different music is already playing?
Expand Down
4 changes: 3 additions & 1 deletion core/src/mindustry/core/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ public static void researched(Content content){
@Override
public void dispose(){
//save the settings before quitting
netServer.admins.forceSave();
if(netServer != null){
netServer.admins.forceSave();
}
Core.settings.manualSave();
}

Expand Down
47 changes: 21 additions & 26 deletions core/src/mindustry/core/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class Renderer implements ApplicationListener{
public TextureRegion[][] fluidFrames;

//currently landing core, null if there are no cores or it has finished landing.
private @Nullable LaunchAnimator landCore;
private @Nullable LaunchAnimator launchAnimator;
private Color clearColor = new Color(0f, 0f, 0f, 1f);
private float
//target camera scale that is lerp-ed to
Expand All @@ -59,8 +59,6 @@ public class Renderer implements ApplicationListener{
camerascale = targetscale,
//starts at coreLandDuration, ends at 0. if positive, core is landing.
landTime,
//timer for core landing particles
landPTimer,
//intensity for screen shake
shakeIntensity,
//reduction rate of screen shake
Expand Down Expand Up @@ -170,21 +168,21 @@ public void update(){
pixelate = settings.getBool("pixelate");

//don't bother drawing landing animation if core is null
if(landCore == null) landTime = 0f;
if(launchAnimator == null) landTime = 0f;
if(landTime > 0){
if(!state.isPaused()) landCore.updateLaunching();
if(!state.isPaused()) launchAnimator.updateLaunch();

weatherAlpha = 0f;
camerascale = landCore.zoomLaunching();
camerascale = launchAnimator.zoomLaunch();

if(!state.isPaused()) landTime -= Time.delta;
}else{
weatherAlpha = Mathf.lerpDelta(weatherAlpha, 1f, 0.08f);
}

if(landCore != null && landTime <= 0f){
landCore.endLaunch();
landCore = null;
if(launchAnimator != null && landTime <= 0f){
launchAnimator.endLaunch();
launchAnimator = null;
}

camera.width = graphics.getWidth() / camerascale;
Expand Down Expand Up @@ -376,9 +374,14 @@ public void draw(){
Draw.draw(Layer.overlayUI, overlays::drawTop);
if(state.rules.fog) Draw.draw(Layer.fogOfWar, fog::drawFog);
Draw.draw(Layer.space, () -> {
if(landCore == null || landTime <= 0f) return;
landCore.drawLanding();
if(launchAnimator == null || landTime <= 0f) return;
launchAnimator.drawLaunch();
});
if(launchAnimator != null){
Draw.z(Layer.space);
launchAnimator.drawLaunchGlobalZ();
Draw.reset();
}

Events.fire(Trigger.drawOver);
blocks.drawBlocks();
Expand Down Expand Up @@ -507,37 +510,29 @@ public float getLandTime(){
}

public float getLandTimeIn(){
if(landCore == null) return 0f;
float fin = landTime / landCore.landDuration();
if(launchAnimator == null) return 0f;
float fin = landTime / launchAnimator.launchDuration();
if(!launching) fin = 1f - fin;
return fin;
}

public float getLandPTimer(){
return landPTimer;
}

public void setLandPTimer(float landPTimer){
this.landPTimer = landPTimer;
}

public void showLanding(LaunchAnimator landCore){
this.landCore = landCore;
this.launchAnimator = landCore;
launching = false;
landTime = landCore.landDuration();
landTime = landCore.launchDuration();

landCore.beginLaunch(false);
camerascale = landCore.zoomLaunching();
camerascale = landCore.zoomLaunch();
}

public void showLaunch(LaunchAnimator landCore){
control.input.config.hideConfig();
control.input.planConfig.hide();
control.input.inv.hide();

this.landCore = landCore;
this.launchAnimator = landCore;
launching = true;
landTime = landCore.landDuration();
landTime = landCore.launchDuration();

Music music = landCore.launchMusic();
music.stop();
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/ui/dialogs/PlanetDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ void playSelected(){
Runnable doLaunch = () -> {
renderer.showLaunch(core);
//run with less delay, as the loading animation is delayed by several frames
Time.runTask(core.landDuration() - 8f, () -> control.playSector(from, sector));
Time.runTask(core.launchDuration() - 8f, () -> control.playSector(from, sector));
};

//load launchFrom sector right before launching so animation is correct
Expand Down
19 changes: 13 additions & 6 deletions core/src/mindustry/world/blocks/LaunchAnimator.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package mindustry.world.blocks;

import arc.audio.*;
import mindustry.gen.*;

public interface LaunchAnimator{

void drawLanding();
void drawLaunch();

default void drawLaunchGlobalZ(){}

void beginLaunch(boolean launching);

void endLaunch();

void updateLaunching();
void updateLaunch();

float landDuration();
float launchDuration();

Music landMusic();
default Music landMusic(){
return Musics.land;
}

Music launchMusic();
default Music launchMusic(){
return Musics.launch;
}

float zoomLaunching();
float zoomLaunch();
}
Loading

0 comments on commit 6c31853

Please sign in to comment.