Merged wall classes

This commit is contained in:
Anuken 2020-07-02 10:44:31 -04:00
parent fd2deb0a82
commit 0a7e40bd23
6 changed files with 80 additions and 105 deletions

View file

@ -749,26 +749,30 @@ public class Blocks implements ContentList{
size = 2;
}};
phaseWall = new DeflectorWall("phase-wall"){{
phaseWall = new Wall("phase-wall"){{
requirements(Category.defense, with(Items.phasefabric, 6));
health = 150 * wallHealthMultiplier;
flashWhite = deflect = true;
}};
phaseWallLarge = new DeflectorWall("phase-wall-large"){{
phaseWallLarge = new Wall("phase-wall-large"){{
requirements(Category.defense, ItemStack.mult(phaseWall.requirements, 4));
health = 150 * 4 * wallHealthMultiplier;
size = 2;
flashWhite = deflect = true;
}};
surgeWall = new SurgeWall("surge-wall"){{
surgeWall = new Wall("surge-wall"){{
requirements(Category.defense, with(Items.surgealloy, 6));
health = 230 * wallHealthMultiplier;
lightningChance = 0.05f;
}};
surgeWallLarge = new SurgeWall("surge-wall-large"){{
surgeWallLarge = new Wall("surge-wall-large"){{
requirements(Category.defense, ItemStack.mult(surgeWall.requirements, 4));
health = 230 * 4 * wallHealthMultiplier;
size = 2;
lightningChance = 0.05f;
}};
door = new Door("door"){{

View file

@ -114,8 +114,7 @@ public class Build{
return type.bounds(x, y, Tmp.r1).grow(0.01f).contains(tile.block.bounds(tile.centerX(), tile.centerY(), Tmp.r2));
}
//TODO should water blocks be placeable here?
if(/*!type.requiresWater && */!contactsShallows(tile.x, tile.y, type)){
if(!type.requiresWater && !contactsShallows(tile.x, tile.y, type)){
return false;
}
@ -142,7 +141,7 @@ public class Build{
return true;
}else{
return tile.interactable(team)
&& contactsShallows(tile.x, tile.y, type)
&& (contactsShallows(tile.x, tile.y, type) || type.requiresWater)
&& (!tile.floor().isDeep() || type.floating || type.requiresWater)
&& tile.floor().placeableOn
&& (!type.requiresWater || tile.floor().liquidDrop == Liquids.water)

View file

@ -1,69 +0,0 @@
package mindustry.world.blocks.defense;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.gen.*;
import static mindustry.Vars.tilesize;
public class DeflectorWall extends Wall{
public static final float hitTime = 10f;
protected float maxDamageDeflect = 10f;
protected Rect rect = new Rect();
protected Rect rect2 = new Rect();
public DeflectorWall(String name){
super(name);
}
public class DeflectorEntity extends Building{
public float hit;
@Override
public void draw(){
super.draw();
if(hit < 0.0001f) return;
Draw.color(Color.white);
Draw.alpha(hit * 0.5f);
Draw.blend(Blending.additive);
Fill.rect(x, y, tilesize * size, tilesize * size);
Draw.blend();
Draw.reset();
hit = Mathf.clamp(hit - Time.delta() / hitTime);
}
@Override
public boolean collision(Bullet bullet){
super.collision(bullet);
//doesn't reflect powerful bullets
if(bullet.damage() > maxDamageDeflect) return true;
//translate bullet back to where it was upon collision
bullet.trns(-bullet.vel().x, -bullet.vel().y);
float penX = Math.abs(x - bullet.x()), penY = Math.abs(y - bullet.y());
if(penX > penY){
bullet.vel().x *= -1;
}else{
bullet.vel().y *= -1;
}
bullet.owner(this);
bullet.team(team);
bullet.time(bullet.time() + 1f);
hit = 1f;
return false;
}
}
}

View file

@ -1,28 +0,0 @@
package mindustry.world.blocks.defense;
import arc.math.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
public class SurgeWall extends Wall{
public float lightningChance = 0.05f;
public float lightningDamage = 20f;
public int lightningLength = 17;
public SurgeWall(String name){
super(name);
}
public class SurgeEntity extends Building{
@Override
public boolean collision(Bullet bullet){
if(Mathf.chance(lightningChance)){
Lightning.create(team(), Pal.surge, lightningDamage, x, y, bullet.rotation() + 180f, lightningLength);
}
return super.collision(bullet);
}
}
}

View file

@ -1,15 +1,29 @@
package mindustry.world.blocks.defense;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class Wall extends Block{
public int variants = 0;
public float lightningChance = -0.001f;
public float lightningDamage = 20f;
public int lightningLength = 17;
public float maxDamageDeflect = 10f;
public boolean flashWhite;
public boolean deflect;
public Wall(String name){
super(name);
solid = true;
@ -43,6 +57,7 @@ public class Wall extends Block{
}
public class WallEntity extends Building{
public float hit;
@Override
public void draw(){
@ -51,6 +66,60 @@ public class Wall extends Block{
}else{
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], x, y);
}
//draw flashing white overlay if enabled
if(flashWhite){
if(hit < 0.0001f) return;
Draw.color(Color.white);
Draw.alpha(hit * 0.5f);
Draw.blend(Blending.additive);
Fill.rect(x, y, tilesize * size, tilesize * size);
Draw.blend();
Draw.reset();
hit = Mathf.clamp(hit - Time.delta() / 10f);
}
}
@Override
public boolean collision(Bullet bullet){
super.collision(bullet);
hit = 1f;
//create lightning if necessary
if(lightningChance > 0){
if(Mathf.chance(lightningChance)){
Lightning.create(team(), Pal.surge, lightningDamage, x, y, bullet.rotation() + 180f, lightningLength);
}
}
//deflect bullets if necessary
if(deflect){
//doesn't reflect powerful bullets
if(bullet.damage() > maxDamageDeflect) return true;
//translate bullet back to where it was upon collision
bullet.trns(-bullet.vel().x, -bullet.vel().y);
float penX = Math.abs(x - bullet.x()), penY = Math.abs(y - bullet.y());
if(penX > penY){
bullet.vel().x *= -1;
}else{
bullet.vel().y *= -1;
}
bullet.owner(this);
bullet.team(team);
bullet.time(bullet.time() + 1f);
//disable bullet collision by returning false
return false;
}
return true;
}
}
}

View file

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=95c135917655b61d636292ba9dfd05766019c1d8
archash=5e12ee82715df10aa81012c6b9db0865d47ceb16