package fm.ak.client.twod;
import fm.ak.client.Local;
import fm.ak.client.Main;
import fm.ak.otse.font.Font;
import fm.ak.client.StaticFont;
import fm.ak.otse.Otse;
import fm.ak.otse.font.Text;
import java.util.Random;
import fm.ak.otse.twod.Component;
import fm.ak.otse.twod.ComponentRenderer;
import fm.ak.otse.twod.Sprite;
/**
* a cute little icon, floating around thank you
*/
public final class Datagram extends Component {
public enum Type {
TILE,
ABC,
FADE_IN_SLOW
}
private static final String witty[] = {"drinks", "spam :c", "ammo", "goodies"};
/*"package", "ear", "soup", "beer", "wine", "ak-47", "ak-74",
"Artefact", "Glowing Artefact", "stuff", "things", "litter",
"nothing"*/
private static final Font font = StaticFont.SegoeUILight14;
private static final int space = 20;
private static final Random XD = new Random();
private static float shifter = 0.75f;
private static float riser = 0.01f;
private static Datagram last = null;
private static boolean lifted = false;
public static float lifter = (Main.height / 2) - (12 / 2) - 40;
boolean upOrDown;
float preciseX;
float preciseY;
private String quote;
private Text text = null;
private static final int R = 132;
private static final int G = 144;
private static final int B = 188;
private static int quoteCount = 0;
private Sprite sprite;
private Component shadow;
private int shadowZ = 0;
Datagram(String sprite) {
super("$a datagram", 0, 0, 12, 12);
visibile = false;
sheet = Main.main.sheet1;
//RGBA(119, 133, 172, 1);
//setTexture(t);
setSheetSprite(sheet, sprite);
this.sprite = sheet.sprite(sprite);
repeat = true;
if ( null == last || quoteCount++ > 5 && XD.nextInt(4) == 1 ) { // 1 in 3
//quote(witty[XD.nextInt(witty.length)]);
quoteCount = 0;
}
Sprite s2 = sheet.sprite("puzzleshadow");
shadow = new Component("$datagram shadow", 50, 50, s2.w(), s2.h());
shadow.setSheetSprite(sheet, "puzzleshadow");
shadow.index = 5;
//shadow.visibile = false;
//Component.queue.add(shadow);
Fader(Fades.IN);
float LastPreciseX = 0;
if (Local.getStage() == Local.Stages.FIRSTSCREEN) {
LastPreciseX = (last != null) ? (last.preciseX > (Main.width / 2) - 180) ? (Main.width / 2) - 180 - this.sprite.w() : (last.preciseX - space) : (Main.width / 2) - 180;
} else if (Local.getStage() == Local.Stages.FIRSTSCREEN) {
// this line is fucking inert
LastPreciseX = (last != null) ? (last.preciseX > 0) ? -this.sprite.w() : (last.preciseX - space) : -this.sprite.w();
}
upOrDown = XD.nextBoolean();
preciseX = LastPreciseX;
preciseY = XD.nextFloat() * (this.sprite.w() / 2);
shadowZ = XD.nextInt(15);
preciseY = (XD.nextBoolean()) ? -preciseY : preciseY;
//tw = getTexture().getWidth();
//th = getTexture().getHeight();
last = this;
index = 4;
}
@Override
public POST reindeer() {
preciseX += shifter;
int framestofade = (int) ((1f / Fades.OUT.Intensity()) * shifter);
if ( Local.getStage() == Local.Stages.FIRSTSCREEN ) {
if (preciseX > (Main.width / 2) + 180 - this.sprite.w() - this.sprite.w()) {
if ( null != quote ) {
text.markDispose();
}
return POST.DISPOSE;
} else if (preciseX > (Main.width / 2) + (180 - framestofade) - this.sprite.w() - this.sprite.w()) {
if (faded() && Fader() != Fades.OUT) {
Fader(Fades.OUT);
}
}
} else if ( Local.getStage() == Local.Stages.GAME ) {
if (preciseX > Main.width) {
if ( null != quote ) {
text.markDispose();
}
return POST.DISPOSE;
} else if (preciseX > Main.width - framestofade) {
if (faded() && Fader() != Fades.OUT) {
Fader(Fades.OUT);
}
}
}
if ( (Local.getStage() == Local.Stages.FIRSTSCREEN && preciseX > (Main.width / 2) - 180 )
|| (Local.getStage() == Local.Stages.GAME && preciseX > -this.sprite.w())) {
visibile = true;
shadow.visibile = true;
float r = 177;
float g = 185;
float b = 213;
if ( null != quote && text == null ) {
text = Text.create(
font,
quote,
50,
50,
0,
Text.ZERO_WIDTH,
Text.NORMAL_ANGLE,
Text.Fades.NONE,
R, G, B, 1);
//text.rgba(0, 0, 0, text.a());
}
preciseY += (upOrDown) ? -riser : riser;
int Uitwijk = (Local.getStage() == Local.Stages.FIRSTSCREEN) ? this.sprite.w() * 3 : this.sprite.w();
if (preciseY < -Uitwijk) {
preciseY = -Uitwijk;
upOrDown = false;
} else if (preciseY > Uitwijk) {
preciseY = Uitwijk;
upOrDown = true;
}
if (text != null) {
text.x = (int) preciseX;
text.y = (int) preciseY + (int) lifter;
}
position((int) preciseX, (int) preciseY + (int) lifter, sprite.w(), sprite.h());
shadow.position((int) preciseX - 5, (int) lifter + 20 + shadowZ, shadow.sprite.w(), shadow.sprite.h());
render();
}
return POST.RETAIN;
}
/**
* util for adding to queue
* @param sprite
* @return
*/
public static Datagram create(String sprite) {
Datagram d = new Datagram(sprite);
ComponentRenderer cr = Otse.getInstance().getComponentRenderer();
//synchronized (Component.queue) {
cr.queue.add(d);
//}
return d;
}
/**
* adds Datagram d to {@link Component#queue}
*
* @deprecated not useful. Sometimes we want to do more in the synchronized
* block, or add more than one Component
*/
public static void collect(Datagram d) {
ComponentRenderer cr = Otse.getInstance().getComponentRenderer();
//synchronized (Component.queue) {
cr.queue.add(d);
//}
}
/**
* global y for animation
*/
public static void lift() {
if (!lifted && Local.getStage() == Local.Stages.GAME) {
lifter -= (12 / 2);
if (lifter < (12 * 2)) {
lifter = (12 * 2);
lifted = true;
}
}
//System.out.println("lifter: " + lifter);
}
/**
* util called when there is a change of stage
*
* @deprecated don't like
*/
public static void changedStage() {
if (Local.getStage() == Local.Stages.GAME) {
shifter = 1.5f;
riser = 0.025f;
}
}
public final void quote(String t) {
quote = t;
}
public final String quote() {
return quote;
}
@Override
public void destroy() {
super.destroy();
shadow.markDispose();
}
}