more rendering

This commit is contained in:
Anuken 2020-02-06 14:58:12 -05:00
parent ddecb2d831
commit e3136e9e09
4 changed files with 71 additions and 7 deletions

View File

@ -25,6 +25,10 @@ abstract class HealthComp implements Entityc{
hitTime -= Time.delta() / hitDuration;
}
float hitAlpha(){
return hitTime / hitDuration;
}
void killed(){
//implement by other components
}

View File

@ -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();
}
}

View File

@ -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());

View File

@ -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;