Implemented passable liquids
This commit is contained in:
@@ -4,16 +4,16 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.content.Weapons;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
@@ -77,7 +77,7 @@ public class Player extends Unit{
|
||||
|
||||
@Override
|
||||
public boolean isFlying(){
|
||||
return mech.flying;
|
||||
return mech.flying || noclip;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,13 +87,14 @@ public class Player extends Unit{
|
||||
|
||||
@Override
|
||||
public void damage(float amount){
|
||||
if(debug || mech.flying) return;
|
||||
//if(debug || mech.flying) return;
|
||||
hitTime = hitDuration;
|
||||
|
||||
health -= amount;
|
||||
if(health <= 0 && !dead && isLocal){ //remote players don't die normally
|
||||
onDeath();
|
||||
dead = true;
|
||||
if(!debug) {
|
||||
health -= amount;
|
||||
if(health <= 0 && !dead && isLocal){ //remote players don't die normally
|
||||
onDeath();
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +106,7 @@ public class Player extends Unit{
|
||||
@Override
|
||||
public void onDeath(){
|
||||
dead = true;
|
||||
drownTime = 0f;
|
||||
if(Net.active()){
|
||||
NetEvents.handleUnitDeath(this);
|
||||
}
|
||||
@@ -148,9 +150,16 @@ public class Player extends Unit{
|
||||
|
||||
float ft = Mathf.sin(walktime, 6f, 2f);
|
||||
|
||||
Floor floor = getFloorOn();
|
||||
|
||||
Draw.color();
|
||||
Draw.alpha(hitTime / hitDuration);
|
||||
|
||||
if(!mech.flying) {
|
||||
if(floor.liquid){
|
||||
Draw.tint(Color.WHITE, floor.liquidColor, 0.5f);
|
||||
}
|
||||
|
||||
for (int i : Mathf.signs) {
|
||||
tr.trns(baseRotation, ft * i);
|
||||
Draw.rect(mname + "-leg", x + tr.x, y + tr.y, 12f * i, 12f - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
|
||||
@@ -159,6 +168,12 @@ public class Player extends Unit{
|
||||
Draw.rect(mname + "-base", x, y,baseRotation- 90);
|
||||
}
|
||||
|
||||
if(floor.liquid) {
|
||||
Draw.tint(Color.WHITE, floor.liquidColor, drownTime * 0.4f);
|
||||
}else {
|
||||
Draw.tint(Color.WHITE);
|
||||
}
|
||||
|
||||
Draw.rect(mname, x, y, rotation -90);
|
||||
|
||||
for (int i : Mathf.signs) {
|
||||
@@ -202,7 +217,7 @@ public class Player extends Unit{
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
|
||||
//if player is in solid block
|
||||
if(tile != null && ((tile.floor().liquid && tile.block() == Blocks.air) || tile.solid())){
|
||||
if(tile != null && tile.solid()){
|
||||
stucktime += Timers.delta();
|
||||
}else{
|
||||
stucktime = 0f;
|
||||
@@ -248,15 +263,12 @@ public class Player extends Unit{
|
||||
|
||||
movement.limit(speed);
|
||||
|
||||
if(!noclip){
|
||||
move(movement.x*Timers.delta(), movement.y*Timers.delta());
|
||||
}else{
|
||||
x += movement.x*Timers.delta();
|
||||
y += movement.y*Timers.delta();
|
||||
}
|
||||
velocity.add(movement);
|
||||
|
||||
updateVelocity(0.4f, speed);
|
||||
|
||||
if(!movement.isZero()){
|
||||
walktime += Timers.delta();
|
||||
walktime += Timers.delta() * velocity.len()*(1f/0.5f)/speed * getFloorOn().speedMultiplier;
|
||||
baseRotation = Mathf.slerpDelta(baseRotation, movement.angle(), 0.13f);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public abstract class Unit extends SyncEntity {
|
||||
//total duration of hit effect
|
||||
@@ -14,6 +21,7 @@ public abstract class Unit extends SyncEntity {
|
||||
public Team team = Team.blue;
|
||||
public Vector2 velocity = new Vector2();
|
||||
public float hitTime;
|
||||
public float drownTime;
|
||||
|
||||
@Override
|
||||
public void damage(float amount){
|
||||
@@ -26,6 +34,55 @@ public abstract class Unit extends SyncEntity {
|
||||
return other instanceof Bullet && state.teams.areEnemies((((Bullet) other).team), team);
|
||||
}
|
||||
|
||||
public Floor getFloorOn(){
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
return (Floor)(tile == null || (!(tile.floor() instanceof Floor)) ? Blocks.defaultFloor : tile.floor());
|
||||
}
|
||||
|
||||
public void updateVelocity(float drag, float maxVelocity){
|
||||
Floor floor = getFloorOn();
|
||||
|
||||
velocity.limit(maxVelocity);
|
||||
|
||||
if(isFlying()) {
|
||||
x += velocity.x / getMass();
|
||||
y += velocity.y / getMass();
|
||||
}else{
|
||||
if(floor.liquid && velocity.len() > 0.4f && Timers.get(this, "flooreffect", 14 - (velocity.len() * floor.speedMultiplier)*2f)){
|
||||
Effects.effect(floor.walkEffect, floor.liquidColor, x, y);
|
||||
}
|
||||
|
||||
status.handleApply(this, floor.status, floor.statusIntensity);
|
||||
|
||||
if(floor.damageTaken > 0f){
|
||||
damagePeriodic(floor.damageTaken);
|
||||
}
|
||||
|
||||
if(floor.drownTime > 0){
|
||||
drownTime += Timers.delta() * 1f/floor.drownTime;
|
||||
if(Timers.get(this, "drowneffect", 15)){
|
||||
Effects.effect(floor.drownUpdateEffect, floor.liquidColor, x, y);
|
||||
}
|
||||
}else{
|
||||
drownTime = Mathf.lerpDelta(drownTime, 0f, 0.03f);
|
||||
}
|
||||
|
||||
drownTime = Mathf.clamp(drownTime);
|
||||
|
||||
if(drownTime >= 1f){
|
||||
damage(health + 1, false);
|
||||
}
|
||||
|
||||
move(velocity.x / getMass() * floor.speedMultiplier, velocity.y / getMass() * floor.speedMultiplier);
|
||||
}
|
||||
|
||||
velocity.scl(Mathf.clamp(1f-drag* floor.dragMultiplier* Timers.delta()));
|
||||
}
|
||||
|
||||
public void damagePeriodic(float amount){
|
||||
damage(amount * Timers.delta(), Timers.get(this, "damageeffect", 20));
|
||||
}
|
||||
|
||||
public void damage(float amount, boolean withEffect){
|
||||
if(withEffect){
|
||||
damage(amount);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EffectEntity;
|
||||
import io.anuke.ucore.function.EffectRenderer;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class GroundEffectEntity extends EffectEntity {
|
||||
private boolean once;
|
||||
|
||||
public GroundEffectEntity(GroundEffect effect, Color color, float rotation) {
|
||||
super(effect, color, rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
GroundEffect effect = (GroundEffect)renderer;
|
||||
|
||||
if(effect.isStatic) {
|
||||
time += Timers.delta();
|
||||
|
||||
time = Mathf.clamp(time, 0, effect.staticLife);
|
||||
|
||||
if (!once && time >= lifetime) {
|
||||
once = true;
|
||||
time = 0f;
|
||||
} else if (once && time >= effect.staticLife) {
|
||||
remove();
|
||||
}
|
||||
}else{
|
||||
super.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(){
|
||||
GroundEffect effect = (GroundEffect)renderer;
|
||||
|
||||
if(once && effect.isStatic)
|
||||
Effects.renderEffect(id, renderer, color, lifetime, rotation, x, y);
|
||||
else if(!effect.isStatic)
|
||||
Effects.renderEffect(id, renderer, color, time, rotation, x, y);
|
||||
}
|
||||
|
||||
public static class GroundEffect extends Effect{
|
||||
public final float staticLife;
|
||||
public final boolean isStatic;
|
||||
|
||||
public GroundEffect(float life, float staticLife, EffectRenderer draw) {
|
||||
super(life, draw);
|
||||
this.staticLife = staticLife;
|
||||
this.isStatic = false;
|
||||
}
|
||||
|
||||
public GroundEffect(boolean isStatic, float life, EffectRenderer draw) {
|
||||
super(life, draw);
|
||||
this.staticLife = 0f;
|
||||
this.isStatic = isStatic;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.EffectEntity;
|
||||
import io.anuke.ucore.function.EffectRenderer;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class StaticEffectEntity extends EffectEntity {
|
||||
private boolean once;
|
||||
|
||||
public StaticEffectEntity(StaticEffect effect, Color color, float rotation) {
|
||||
super(effect, color, rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
time += Timers.delta();
|
||||
|
||||
time = Mathf.clamp(time, 0, ((StaticEffect)renderer).staticLife);
|
||||
|
||||
if(!once && time >= lifetime){
|
||||
once = true;
|
||||
time = 0f;
|
||||
}else if(once && time >= ((StaticEffect)renderer).staticLife){
|
||||
remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOver(){
|
||||
if(once) Effects.renderEffect(id, renderer, color, lifetime, rotation, x, y);
|
||||
}
|
||||
|
||||
public static class StaticEffect extends Effect{
|
||||
public final float staticLife;
|
||||
|
||||
public StaticEffect(float life, float staticLife, EffectRenderer draw) {
|
||||
super(life, draw);
|
||||
this.staticLife = staticLife;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
package io.anuke.mindustry.entities.units;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Translator;
|
||||
|
||||
@@ -42,11 +45,23 @@ public abstract class GroundUnitType extends UnitType{
|
||||
|
||||
float ft = Mathf.sin(walktime, 6f, 2f);
|
||||
|
||||
Floor floor = unit.getFloorOn();
|
||||
|
||||
if(floor.liquid){
|
||||
Draw.tint(Hue.mix(Color.WHITE, floor.liquidColor, 0.5f));
|
||||
}
|
||||
|
||||
for (int i : Mathf.signs) {
|
||||
tr1.trns(unit.baseRotation, ft * i);
|
||||
Draw.rect(name + "-leg", unit.x + tr1.x, unit.y + tr1.y, 12f * i, 12f - Mathf.clamp(ft * i, 0, 2), unit.baseRotation - 90);
|
||||
}
|
||||
|
||||
if(floor.liquid) {
|
||||
Draw.tint(Color.WHITE, floor.liquidColor, unit.drownTime * 0.4f);
|
||||
}else {
|
||||
Draw.tint(Color.WHITE);
|
||||
}
|
||||
|
||||
Draw.rect(name + "-base", unit.x, unit.y, unit.baseRotation- 90);
|
||||
|
||||
Draw.rect(name, unit.x, unit.y, unit.rotation -90);
|
||||
|
||||
@@ -76,16 +76,7 @@ public abstract class UnitType {
|
||||
|
||||
unit.status.update(unit);
|
||||
|
||||
unit.velocity.limit(maxVelocity);
|
||||
|
||||
if(isFlying) {
|
||||
unit.x += unit.velocity.x / mass;
|
||||
unit.y += unit.velocity.y / mass;
|
||||
}else{
|
||||
unit.move(unit.velocity.x / mass, unit.velocity.y / mass);
|
||||
}
|
||||
|
||||
unit.velocity.scl(Mathf.clamp(1f-drag* Timers.delta()));
|
||||
unit.updateVelocity(drag, maxVelocity);
|
||||
|
||||
if(unit.target != null) behavior(unit);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user