Package ru.vagrant_ai.questionmarkgame.obj.proj

Source Code of ru.vagrant_ai.questionmarkgame.obj.proj.LightningProjectile

package ru.vagrant_ai.questionmarkgame.obj.proj;

import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Line;
import org.newdawn.slick.geom.Point;
import org.newdawn.slick.geom.Vector2f;

import ru.vagrant_ai.questionmarkgame.main.Game;
import ru.vagrant_ai.questionmarkgame.main.GameplayState;
import ru.vagrant_ai.questionmarkgame.util.Text;
import ru.vagrant_ai.questionmarkgame.util.Util;

public class LightningProjectile extends Projectile {
 
  private Line bullet;
  private Graphics g;
  private Color col;
  private int alpha = 0;
  private int size = 45;
  private int beam_quantity = 6;
  private float[] curr_x = new float[beam_quantity+1];
  private float[] curr_y = new float[beam_quantity+1];
  private float n_x;
  private float n_y;
  private Vector2f vector_pl;
  private Vector2f vector_end;

  double debug;
  float length_deb;
  float deb = 0;
 
  public LightningProjectile(Point gun_point)
  {
    bullet_iter = 50;
    curr_x[0] = (int) gun_point.getX();
    curr_y[0] = (int) gun_point.getY();
    boolean direction = new Random().nextBoolean();
    boolean size_penalty_annigilator = false; //to prevent ray stuck intro the ground
    vector_pl = new Vector2f(curr_x[0], curr_y[0]);
    vector_end = new Vector2f(Util.MouseX(), Util.MouseY());
    vector_end.sub(vector_pl);
    vector_end.normalise();
    for (int i = 0; i < 2; i++)
    {
      float rand;
      if (i == 0)
      {
        rand = new Random().nextFloat()*20-8; //first time [-10..10]
        vector_end.setTheta(vector_end.getTheta()+rand);
      }
      else
      {
        //Vector2f vector_pl = new Vector2f(curr_x[i], curr_y[i]);
        //vector_end.sub(vector_pl);
        //vector_end.normalise();
        if (direction
          //rand = new Random().nextFloat()*10+85; //[120..160]
          rand = 180;
        else
          //rand = new Random().nextFloat()*10+20; //[10..50]
          rand = 180;
        vector_end.setTheta(vector_end.getTheta()+rand);
        debug = vector_end.getTheta();
      }
      direction = !direction;
      n_x = vector_end.x;
      n_y = vector_end.y;
      g = Game.app.getGraphics();
      bullet = new Line(curr_x[0], curr_y[0], curr_x[0], curr_y[0]);
      int generated_length = new Random().nextInt(45)+size-(size_penalty_annigilator?0:25);
      if (size_penalty_annigilator)
        size_penalty_annigilator = false;
      curr_x[i+1] = curr_x[i]; //lightning special code
      curr_y[i+1] = curr_y[i];
      while(true)
      {
        curr_x[i+1] += n_x; curr_y[i+1] += n_y;
        bullet.set(curr_x[i], curr_y[i], curr_x[i+1], curr_y[i+1]);
//        if (curr_x[i+1] > GameplayState.ground_level+47 && direction == true && i > 0)
//        {
//          deb = curr_x[i+1];
//          size_penalty_annigilator = true;
//          break;
//        }
        if (checkCollision())
        {
          deb = 2;
          break;
        }
        else if (bullet.length() > generated_length)
        {
          deb = 1;
          break;
        }
       
      }
      length_deb = bullet.length();
    }
  }

  public void render()
  {
    Text.drawDebug("stop:"+deb+" len:"+String.format("%.2f", length_deb)+" deg:"+String.format("%.2f", debug));

    col = new Color(0, 111, 255, alpha);
    g.setLineWidth(4);
    g.setColor(col);
    for (int i = 0; i < 2; i++)
      g.drawLine(curr_x[i], curr_y[i], curr_x[i+1], curr_y[i+1]);
  }
 
  public void update()
  {
    bullet_iter--;
    if (bullet_iter > 0)
    {
      alpha = 255/20*bullet_iter; 
    }
  }
 
  private boolean checkCollision()
  {
    if (bullet.intersects(GameplayState.border))
      return true;
    return false;
  }

}
TOP

Related Classes of ru.vagrant_ai.questionmarkgame.obj.proj.LightningProjectile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.