From e3136e9e091640effbb39ad025b48d1affd4e323 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 6 Feb 2020 14:58:12 -0500 Subject: [PATCH] more rendering --- .../mindustry/entities/def/HealthComp.java | 4 ++ core/src/mindustry/entities/def/LegsComp.java | 38 ++++++++++++++++++- core/src/mindustry/entities/def/UnitComp.java | 34 +++++++++++++++-- .../mindustry/entities/def/WeaponsComp.java | 2 +- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/entities/def/HealthComp.java b/core/src/mindustry/entities/def/HealthComp.java index 86b4127783..c83690dcf1 100644 --- a/core/src/mindustry/entities/def/HealthComp.java +++ b/core/src/mindustry/entities/def/HealthComp.java @@ -25,6 +25,10 @@ abstract class HealthComp implements Entityc{ hitTime -= Time.delta() / hitDuration; } + float hitAlpha(){ + return hitTime / hitDuration; + } + void killed(){ //implement by other components } diff --git a/core/src/mindustry/entities/def/LegsComp.java b/core/src/mindustry/entities/def/LegsComp.java index 2ab7a115ba..658bc3aa33 100644 --- a/core/src/mindustry/entities/def/LegsComp.java +++ b/core/src/mindustry/entities/def/LegsComp.java @@ -1,9 +1,43 @@ package mindustry.entities.def; +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; +import mindustry.world.blocks.*; @Component -abstract class LegsComp implements Posc, Flyingc{ - float baseRotation; +abstract class LegsComp implements Posc, Flyingc, Hitboxc{ + float baseRotation, walkTime; + + void drawLegs(){ + Draw.mixcol(Color.white, hitAlpha()); + TextureRegion legRegion = null, baseRegion = null; + + float ft = Mathf.sin(walkTime * vel().len() * 5f, 6f, 2f + hitSize() / 15f); + + Floor floor = floorOn(); + + if(floor.isLiquid){ + Draw.color(Color.white, floor.color, 0.5f); + } + + for(int i : Mathf.signs){ + Draw.rect(legRegion, + x() + Angles.trnsx(baseRotation, ft * i), + y() + Angles.trnsy(baseRotation, ft * i), + legRegion.getWidth() * i * Draw.scl, legRegion.getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90); + } + + if(floor.isLiquid){ + Draw.color(Color.white, floor.color, drownTime() * 0.4f); + }else{ + Draw.color(Color.white); + } + + Draw.rect(baseRegion, x(), y(), baseRotation - 90); + + Draw.mixcol(); + } } diff --git a/core/src/mindustry/entities/def/UnitComp.java b/core/src/mindustry/entities/def/UnitComp.java index 77e7826450..57255ef3e7 100644 --- a/core/src/mindustry/entities/def/UnitComp.java +++ b/core/src/mindustry/entities/def/UnitComp.java @@ -19,7 +19,9 @@ import mindustry.world.blocks.*; import static mindustry.Vars.*; @Component -abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, DrawShadowc{ +abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, DrawShadowc, DrawLayerGroundc, DrawLayerFlyingc{ + transient float x, y, rotation; + private UnitController controller; private UnitDef type; @@ -103,15 +105,39 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox public void drawLight(){ //TODO move if(type.lightRadius > 0){ - renderer.lights.add(getX(), getY(), type.lightRadius, type.lightColor, 0.6f); + renderer.lights.add(x, y, type.lightRadius, type.lightColor, 0.6f); } } @Override public void draw(){ + drawCell(); + } + + @Override + public void drawBody(){ + Draw.mixcol(Color.white, hitAlpha()); + + Draw.rect(type.region, x, y, rotation - 90); + + Draw.reset(); + } + + @Override + public void drawFlying(){ + if(isFlying()) draw(); + } + + @Override + public void drawGround(){ + if(isGrounded()) draw(); + } + + @Override + public void drawCell(){ //draw power cell - TODO move Draw.color(Color.black, team().color, healthf() + Mathf.absin(Time.time(), Math.max(healthf() * 5f, 1f), 1f - healthf())); - Draw.rect(type.cellRegion, getX(), getY(), rotation() - 90); + Draw.rect(type.cellRegion, x, y, rotation() - 90); Draw.color(); } @@ -119,7 +145,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox public void killed(){ float explosiveness = 2f + item().explosiveness * stack().amount; float flammability = item().flammability * stack().amount; - Damage.dynamicExplosion(getX(), getY(), flammability, explosiveness, 0f, bounds() / 2f, Pal.darkFlame); + Damage.dynamicExplosion(x, y, flammability, explosiveness, 0f, bounds() / 2f, Pal.darkFlame); //TODO cleanup //ScorchDecal.create(getX(), getY()); diff --git a/core/src/mindustry/entities/def/WeaponsComp.java b/core/src/mindustry/entities/def/WeaponsComp.java index cec56eaade..25c148d5c2 100644 --- a/core/src/mindustry/entities/def/WeaponsComp.java +++ b/core/src/mindustry/entities/def/WeaponsComp.java @@ -87,7 +87,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{ } /** Draw weapon mounts. */ - void draw(){ + void drawWeapons(){ for(WeaponMount mount : mounts){ Weapon weapon = mount.weapon;