Implemented shield hit effects and bullet absorption and powered rturret

This commit is contained in:
Anuken
2017-11-28 01:00:59 -05:00
parent c0d28eca65
commit 63d8aed9a5
13 changed files with 115 additions and 25 deletions
@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.FloatArray;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings;
@@ -28,7 +29,9 @@ public class Shaders{
}
public static class Shield extends Shader{
public static final int MAX_HITS = 3*64;
public Color color = new Color();
public FloatArray hits;
public Shield(){
super("shield", "default");
@@ -38,6 +41,8 @@ public class Shaders{
public void apply(){
float scale = Settings.getBool("pixelate") ? 1 : Core.cameraScale / Core.camera.zoom;
float scaling = Core.cameraScale / 4f / Core.camera.zoom;
shader.setUniform3fv("u_hits[0]", hits.items, 0, Math.min(hits.size, MAX_HITS));
shader.setUniformi("u_hitamount", Math.min(hits.size, MAX_HITS)/3);
shader.setUniformf("u_color", color);
shader.setUniformf("u_time", Timers.time());
shader.setUniformf("u_scaling", scaling);
@@ -1,7 +1,10 @@
package io.anuke.mindustry.entities.effect;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.defense.ShieldBlock;
import io.anuke.ucore.core.Draw;
@@ -14,6 +17,8 @@ import io.anuke.ucore.util.Mathf;
public class Shield extends Entity{
public boolean active;
public boolean hitPlayers = true;
private float uptime = 0f;
private final Tile tile;
//TODO
@@ -30,11 +35,14 @@ public class Shield extends Entity{
@Override
public void update(){
float alpha = 0.1f;
Interpolation interp = Interpolation.fade;
if(active){
uptime += Timers.delta() / 90f;
uptime = interp.apply(uptime, 1f, alpha * Timers.delta());
}else{
uptime -= Timers.delta() / 60f;
if(uptime < 0)
uptime = interp.apply(uptime, 0f, alpha * Timers.delta());
if(uptime <= 0.05f)
remove();
}
uptime = Mathf.clamp(uptime);
@@ -46,14 +54,14 @@ public class Shield extends Entity{
ShieldBlock block = (ShieldBlock)tile.block();
Entities.getNearby(x, y, block.shieldRadius * 2*uptime + 10, entity->{
if(entity instanceof BulletEntity){
BulletEntity bullet = (BulletEntity)entity;
Entities.getNearby(Entities.getGroup(Bullet.class), x, y, block.shieldRadius * 2*uptime + 10, entity->{
BulletEntity bullet = (BulletEntity)entity;
if((bullet.owner instanceof Enemy || hitPlayers)){
float dst = entity.distanceTo(this);
if(Math.abs(dst - block.shieldRadius) < 2){
bullet.velocity.scl(-1);
if(dst < drawRadius()/2f){
((ShieldBlock)tile.block()).handleBullet(tile, bullet);
}
}
});
@@ -65,10 +73,7 @@ public class Shield extends Entity{
return;
}
ShieldBlock block = (ShieldBlock)tile.block();
float rad = block.shieldRadius*2 + Mathf.sin(Timers.time(), 25f, 2f);
rad *= uptime;
float rad = drawRadius();
Graphics.surface("shield", false);
Draw.color(Color.ROYAL);
@@ -78,6 +83,11 @@ public class Shield extends Entity{
Graphics.surface();
}
float drawRadius(){
ShieldBlock block = (ShieldBlock)tile.block();
return (block.shieldRadius*2 + Mathf.sin(Timers.time(), 25f, 2f)) * uptime;
}
public void removeDelay(){
active = false;
}