Added shield effects

This commit is contained in:
Anuken 2020-05-14 12:07:33 -04:00
parent a06f6f0b2d
commit d54d8a25af
12 changed files with 94 additions and 12 deletions

View File

@ -80,8 +80,8 @@ public class Vars implements Loadable{
public static final float miningRange = 70f;
/** range for building */
public static final float buildingRange = 220f;
/** ticks spent out of bound until self destruct. */
public static final float boundsCountdown = 60 * 7;
/** duration of one turn. */
public static final float turnDuration = 5 * Time.toMinutes;
/** for map generator dialog */
public static boolean updateEditorOnChange = false;
/** size of tiles in units */

View File

@ -1189,6 +1189,23 @@ public class Fx{
Lines.poly(e.x, e.y, 6, e.rotation + e.fin(), 90);
}),
unitShieldBreak = new Effect(35, e -> {
if(!(e.data instanceof Unitc)) return;
Unitc unit = e.data();
float radius = unit.hitSize() * 1.3f;
color(Pal.shield, e.fout());
randLenVectors(e.id, (int)(radius * 0.7f), radius, radius * e.finpow(), (x, y) -> {
Fill.poly(e.x + x, e.y + y, 3, e.fout() * 3f, Angles.angle(x, y));
});
stroke(1f * e.fout());
Lines.circle(e.x, e.y, radius);
}),
coreLand = new Effect(120f, e -> {
});
}

View File

@ -167,7 +167,7 @@ public class UnitTypes implements ContentList{
health = 400;
buildSpeed = 0.4f;
engineOffset = 6.5f;
hitsize = 7f;
hitsize = 8f;
}};
/*

View File

@ -1,21 +1,31 @@
package mindustry.entities.def;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.gen.*;
@Component
abstract class ShieldComp implements Healthc{
abstract class ShieldComp implements Healthc, Posc{
@Import float health, hitTime;
@Import boolean dead;
/** Absorbs health damage. */
float shield;
/** Shield opacity. */
transient float shieldAlpha = 0f;
@Replace
@Override
public void damage(float amount){
hitTime = 1f;
boolean hadShields = shield > 0.0001f;
if(hadShields){
shieldAlpha = 1f;
}
float shieldDamage = Math.min(shield, amount);
shield -= shieldDamage;
amount -= shieldDamage;
@ -25,6 +35,16 @@ abstract class ShieldComp implements Healthc{
if(health <= 0 && !dead){
kill();
}
if(hadShields && shield <= 0.0001f){
Fx.unitShieldBreak.at(x(), y(), 0, this);
}
}
}
@Override
public void update(){
shieldAlpha -= Time.delta() / 12f;
if(shieldAlpha < 0) shieldAlpha = 0f;
}
}

View File

@ -20,7 +20,6 @@ import static mindustry.Vars.*;
public class GlobalData{
private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>();
private ObjectIntMap<Item> items = new ObjectIntMap<>();
private Array<Satellite> satellites = new Array<>();
private boolean modified;
public GlobalData(){

View File

@ -1,4 +0,0 @@
package mindustry.game;
public class Turns{
}

View File

@ -6,12 +6,14 @@ import arc.util.*;
import mindustry.content.*;
import mindustry.type.*;
import static mindustry.Vars.state;
import static mindustry.Vars.*;
/** Updates the campaign universe. Has no relevance to other gamemodes. */
public class Universe{
private long seconds;
private float secondCounter;
private int turn;
private float turnCounter;
public Universe(){
load();
@ -35,6 +37,7 @@ public class Universe{
public void update(){
secondCounter += Time.delta() / 60f;
if(secondCounter >= 1){
seconds += (int)secondCounter;
secondCounter %= 1f;
@ -45,6 +48,15 @@ public class Universe{
}
}
//update turn state - happens only in-game
turnCounter += Time.delta();
if(turnCounter >= turnDuration){
turn ++;
turnCounter = 0;
onTurn();
}
if(state.hasSector()){
//update sector light
float light = state.getSector().getLight();
@ -56,6 +68,10 @@ public class Universe{
}
}
private void onTurn(){
//create a random event here, e.g. invasion
}
public float secondsMod(float mod, float scale){
return (seconds / scale) % mod;
}
@ -69,11 +85,16 @@ public class Universe{
}
private void save(){
Core.settings.putSave("utime", seconds);
Core.settings.put("utime", seconds);
Core.settings.put("turn", turn);
Core.settings.put("turntime", turnCounter);
Core.settings.save();
}
private void load(){
seconds = Core.settings.getLong("utime");
turn = Core.settings.getInt("turn");
turnCounter = Core.settings.getFloat("turntime");
}
}

View File

@ -8,6 +8,9 @@ public class Pal{
items = Color.valueOf("2ea756"),
command = Color.valueOf("eab678"),
shield = Color.valueOf("7e8ffc").mul(1.3f).a(0.7f),
shieldIn = Color.black.cpy().a(0f),
bulletYellow = Color.valueOf("fff8e8"),
bulletYellowBack = Color.valueOf("f9c27a"),

View File

@ -0,0 +1,12 @@
package mindustry.logic;
import mindustry.ui.dialogs.*;
public class LogicDialog extends FloatingDialog{
public LogicDialog(){
super("");
clear();
addCloseButton();
}
}

View File

@ -1,4 +1,4 @@
package mindustry.world.blocks.experimental;
package mindustry.logic;
import mindustry.gen.*;

View File

@ -0,0 +1,4 @@
package mindustry.logic;
public class LogicNode{
}

View File

@ -141,6 +141,16 @@ public class UnitType extends UnlockableContent{
if(drawCell) drawCell(unit);
if(drawItems) drawItems(unit);
drawLight(unit);
if(unit.shieldAlpha() > 0){
drawShield(unit);
}
}
public void drawShield(Unitc unit){
float alpha = unit.shieldAlpha();
float radius = unit.hitSize() * 1.3f;
Fill.light(unit.x(), unit.y(), Lines.circleVertices(radius), radius, Tmp.c1.set(Pal.shieldIn), Tmp.c2.set(Pal.shield).lerp(Color.white, Mathf.clamp(unit.hitTime())).a(Pal.shield.a * alpha));
}
public void drawControl(Unitc unit){