package ru.vagrant_ai.questionmarkgame.obj.add;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Rectangle;
import ru.vagrant_ai.questionmarkgame.main.Game;
import ru.vagrant_ai.questionmarkgame.main.GameplayState;
import ru.vagrant_ai.questionmarkgame.obj.Elements;
import ru.vagrant_ai.questionmarkgame.obj.mob.Monster;
import ru.vagrant_ai.questionmarkgame.util.MonsterHandler;
import ru.vagrant_ai.questionmarkgame.util.Particle;
import ru.vagrant_ai.questionmarkgame.util.Util;
import ru.vagrant_ai.questionmarkgame.util.list.ITEM;
import ru.vagrant_ai.questionmarkgame.util.list.MS;
import ru.vagrant_ai.questionmarkgame.util.list.PT;
public class Light {
private Rectangle zone;
private float x;
private byte type;
private float width = 65;
private byte damage = 1;
private float speed = 8;
private float util_speed;
private List<Animation> light_anim = new ArrayList<Animation>();
public Light(int x, int type)
{
this.x = x;
this.type = (byte) type;
width += 40*(type-1);
if (x-width/2 < 5) //stabilize x //deprecated, but can be still in use
{
this.x = width/2+(type==3?25:5);
}
else if (x+width > Game.getAppX()-10)
{
this.x = Game.getAppX()-width-10;
}
damage += type;
speed -= type;
util_speed = speed;
zone = new Rectangle(this.x+5,GameplayState.ground_level+15,width+5,30);
while(true)
{
if (light_anim.size() == 0)
{
width -= 5;
light_anim.add(addCornerLightAnimation(false));
}
else if (width > 5)
{
width -= 5;
light_anim.add(addLightAnimation());
}
if (width <= 5)
{
light_anim.add(addCornerLightAnimation(true));
break;
}
}
switch(type) //adding particle
{
case 1:
Particle.addNew(PT.LIGHT_SOURCE_LOW, (int)this.x+26, GameplayState.ground_level-28);
break;
case 2:
Particle.addNew(PT.LIGHT_SOURCE_MID, (int)this.x+28, GameplayState.ground_level-57);
break;
case 3:
int rand = new Random().nextInt(6);
Particle.addNew(PT.LIGHT_SOURCE_STRONG, (int)this.x-11, GameplayState.ground_level-270+rand);
Particle.addNew(PT.LIGHT_SOURCE_STRONG_ADD, (int)this.x-8, GameplayState.ground_level-255+rand);
break;
}
}
private Animation addCornerLightAnimation(boolean flip)
{
Image[] img = new Image[5];
for (int i = 0; i < 5; ++i)
{
img[i] = Util.loadImage("particle/light/light_corner_000"+i+".png").getFlippedCopy(flip, false);
img[i].setAlpha(0.6f+(0.15f/6*damage));
img[i].getScaledCopy(1.0f+(1.5f/((1/speed)*7)));
}
return new Animation(img, 240, true);
}
private Animation addLightAnimation()
{
Image[] img = new Image[5];
float rand = new Random().nextFloat()*0.4f;
for (int i = 0; i < 5; ++i)
{
img[i] = Util.loadImage("particle/light/light_000"+i+".png");
img[i].setAlpha(0.6f+(0.25f/10*damage));
img[i].getScaledCopy(1.0f+1.5f-(1.5f/30*(1/speed))+rand);
}
Animation anim = new Animation(img, 240, true);
anim.setCurrentFrame(new Random().nextInt(5));
return anim;
}
public void update()
{
util_speed--;
byte add = (type == 1?Elements.extractLevel(ITEM.P_UPG_SMALL_LIGHT):0);
add = (type == 2?Elements.extractLevel(ITEM.P_UPG_LIGHT):0);
add = (type == 3?Elements.extractLevel(ITEM.P_UPG_STRONG_LIGHT):0);
if (util_speed < 0+add*2)
{
util_speed = speed;
for (int i = 0; i < MonsterHandler.monster_array.size(); ++i)
{
Monster monster = MonsterHandler.monster_array.get(i);
MS state = monster.state;
if ((zone.intersects(monster.hitbox) || zone.contains(monster.hitbox)) && state != MS.NULL && state != MS.DEAD)
{
monster.onDamage(damage+(type == 1?(int) (Elements.extractLevel(ITEM.P_UPG_SMALL_LIGHT)*2):0)+(type == 2?Elements.extractLevel(ITEM.P_UPG_LIGHT)*2:0)+(type == 3?(int) (Elements.extractLevel(ITEM.P_UPG_STRONG_LIGHT)*2.5f):0), false, false);
}
}
}
}
public void render(Graphics g)
{
for (int i = 0; i < light_anim.size(); ++i)
{
Animation anim = light_anim.get(i);
anim.draw(x-width/2+(i==0?9:9+i*5), GameplayState.ground_level+19+(i==0||i==light_anim.size()-1?0:11));
}
}
}