package ru.vagrant_ai.questionmarkgame.obj.particle;
import java.util.Random;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Vector2f;
import ru.vagrant_ai.questionmarkgame.util.Util;
import ru.vagrant_ai.questionmarkgame.util.list.PT;
public class PoisonCloud extends Particle {
private int x_c, y_c;
private float[] x = new float[5], y = new float[5];
private float[] x_off = new float[5], y_off = new float[5];
private short[] rotation = new short[5];
private boolean[] direction = new boolean[5];
private Image util_img;
private byte util_iter = 25;
public PoisonCloud(int x, int y)
{
id = PT.POISON_CLOUD;
x_c = x;
y_c = y;
util_img = Util.loadImage("particle/smoke");
util_img = util_img.getScaledCopy(5f);
this.x[0] = (short) (x-18 - 4);
this.y[0] = (short) y;
this.x[1] = (short) (x-18 - 4);
this.y[1] = (short) (y - 4);
this.x[2] = (short) (x-18);
this.y[2] = (short) (y - 4);
this.x[3] = (short) (x-18 + 4);
this.y[3] = (short) (y - 4);
this.x[4] = (short) (x-18 + 4);
this.y[4] = (short) y;
Vector2f vector;
for (int i = 0; i < 5; i++) //[10..90] - 75/5
{
rotation[i] = (short) new Random().nextInt(360);
direction[i] = new Random().nextBoolean();
vector = new Vector2f(x,y);
vector.normalise();
vector.setTheta(new Random().nextInt(32)-170+32*i);
x_off[i] = vector.getX();
y_off[i] = vector.getY();
}
}
public void update()
{
util_iter--;
if (util_iter < 1)
alive = false;
for (int i = 0; i < 5; ++i)
{
rotation[i] += 2*(direction[i]?1:-1);
x[i] += x_off[i]*4.6;
y[i] += y_off[i]*3.6;
}
}
public void render(Graphics g)
{
util_img.setImageColor(0, 255, 0, 0.75f-(20/25*util_iter));
for (int i = 0; i < 5; ++i)
{
util_img.setRotation(rotation[i]);
util_img.draw(x[i], y[i]);
}
g.setColor(new Color(0, 0.55f, 0, 0.83f-(0.68f/25*(25-util_iter))));
g.setLineWidth(3);
g.drawOval(x_c-(75-util_iter*3), y_c-(75-util_iter*3), 30+(150-util_iter*6), 30+(150-util_iter*6));
g.setColor(new Color(0, 0.25f, 0, 0.83f-(0.48f/25*(25-util_iter))));
g.setLineWidth(2);
g.drawOval(x_c-(70-util_iter*3)+5, y_c-(70-util_iter*3)+5, 20+(140-util_iter*6), 20+(140-util_iter*6));
}
}