103 lines
2.5 KiB
Java
Executable File

package zero1hd.polyjet.entity;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;
public class VoidCircle extends Actor implements Entity, Poolable {
float timer;
float endRadius;
private float currentRadius;
Rectangle hitBox;
ShapeRenderer shapeRenderer;
float growthRate;
boolean done;
public VoidCircle(ShapeRenderer shapeRenderer) {
hitBox = new Rectangle();
this.shapeRenderer = shapeRenderer;
}
public void init(float endRadius, float x, float y, float growthRate, float warningTime) {
timer = warningTime;
this.endRadius = endRadius;
setSize(2*endRadius, 2*endRadius);
setX(x);
setY(y);
this.growthRate = growthRate;
}
@Override
public void act(float delta) {
hitBox.setPosition(getX(), getY());
if (timer > 0) {
timer -= delta;
} else {
if (currentRadius < endRadius) {
growCurrentRadius(delta*growthRate);
} else {
endRadius = -1f;
if (currentRadius > 0) {
growCurrentRadius(delta*-3*growthRate);
} else {
done = true;
}
}
}
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
if (timer <= 0) {
shapeRenderer.set(ShapeType.Filled);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.circle(getX(), getY(), currentRadius);
}
shapeRenderer.set(ShapeType.Line);
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(getX(), getY(), endRadius);
super.draw(batch, parentAlpha);
}
@Override
public void reset() {
hitBox.set(0, 0, 0, 0);
currentRadius = 0;
growthRate = 0;
timer = 0;
endRadius = 0;
done = false;
}
public void setCurrentRadius(float currentRadius) {
this.currentRadius = currentRadius;
hitBox.setSize(2*(currentRadius*currentRadius));
hitBox.setCenter(getX(), getY());
}
public void growCurrentRadius(float currentRadius) {
this.currentRadius += currentRadius;
hitBox.setSize(2*(currentRadius*currentRadius));
hitBox.setCenter(getX(), getY());
}
@Override
public Rectangle getHitZone() {
return hitBox;
}
@Override
public Entities getEntityType() {
return Entities.VOID_CIRCLE;
}
@Override
public void collided(Entity entity) {
}
}