package ru.vagrant_ai.questionmarkgame.obj.mob;
import java.util.Random;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import ru.vagrant_ai.questionmarkgame.main.Game;
import ru.vagrant_ai.questionmarkgame.main.GameplayState;
import ru.vagrant_ai.questionmarkgame.util.list.ML;
import ru.vagrant_ai.questionmarkgame.util.list.MS;
public class Whacker extends Monster {
/* CONSTRUCTOR ZONE */
private int opt_charge = 85;
private float charge_multi = 1f;
private int opt_dead = 55;
private int opt_walk = 90;
/**
* "Whacker" specification:
* First and most basic walking monster
* Performs charge, when near player
* HP = 100
* SPEED = [0.65..0.75]
* SIZE = [0.9..1.1]
*/
public Whacker() {
id = ML.WHACKER;
hp_default = 100;
power = 1;
y = ground_level;
speed = (float)(new Random().nextInt(10))/100+0.65f;
size = (float)(new Random().nextInt(200))/1000+0.9f;
height = 45*size;
width = 25*size;
state = MS.WALK;
performDefault();
}
/* UPDATE ZONE */
@Override
public void perform()
{
if (state == MS.WALK)
{
x += speed*((GameplayState.player.getY() > GameplayState.ground_level) ? -1.25f : (getDirection() ? -1 : 1));
if (x < -50 && x > Game.getAppX()+55) Suicide(1);
if (getDistance() < 70 && getDistance() > 50 && GameplayState.player.getY() >= GameplayState.ground_level)
{
state = MS.CHARGE;
updateFacing();
charge_multi = 1;
power = 5;
opt_charge = 35; //CHARGE is 35 frames long
}
opt_walk--;
if (opt_walk == 0)
{
opt_walk = 90; //WALK is 90 frames long (before the checkFacing())
updateFacing();
}
}
else if (state == MS.CHARGE)
{
if (charge_multi != 1.5)
{
charge_multi += 0.12f;
if (charge_multi > 5.5) charge_multi = 5.5f;
}
x += speed*charge_multi*(getDirection() ? -1 : 1);
opt_charge--;
if (opt_charge == 0)
{
power = 1;
state = MS.WALK;
opt_walk = 90;
updateFacing();
}
}
else if (state == MS.DEAD)
{
opt_dead--;
if (opt_dead == 0) state = MS.NULL;
}
}
/* RENDER ZONE */
@Override
public void renderMain(Graphics g) throws SlickException
{
switch(state)
{
case NULL: break;
case DEAD:
for (int i = 0; i < 6; i++)
{
g.setLineWidth(9);
g.setColor(new Color(0,90,0)); //poison green
g.drawRect(x-death_rects_x[i], y-death_rects_y[i], 15+opt_dead/2, 15+opt_dead/2);
g.setColor(new Color(13,142,19)); //poison green
g.fillRect(x-death_rects_x[i], y-death_rects_y[i], 15+opt_dead/2, 15+opt_dead/2);
}
break;
default:
g.setLineWidth(6);
g.setColor(new Color(0,90,0)); //poison green
g.drawRect(x-width, y-height, width, height);
g.setColor(new Color(13,142,19)); //poison green
g.fillRect(x-width, y-height, width, height);
break;
}
}
/* EXTERNAL ZONE */
public void onAttackSuccess()
{
if (state == MS.CHARGE)
opt_charge = 1;
}
}