Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (702)
Games in Android Showcase (203)
games submitted by our members
Games in WIP (775)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Cero (posted 2014-07-16 00:42:17, viewed 734 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99  
package whitealchemy;

import game.Content;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

public class GFX
{
   //do a default of thickness = 3f
   //default number of bolts = 3
   
   private static Vector2 tempSphereVector = new Vector2(0,0);
   
   public static void drawLine(SpriteBatch batch, float _x1, float _y1, float _x2, float _y2, float thickness)
   {
      float length = Trigonometrics.getDistanceAccurate(_x1, _y1, _x2, _y2);
      float dx = _x1;
      float dy = _y1;
       dx = dx - _x2;
      dy = dy - _y2;
      float angle = MathUtils.radiansToDegrees*MathUtils.atan2(dy, dx);
      angle = angle-180;
      batch.draw(Content.texWhite, _x1, _y1, 0f, thickness*0.5f, length, thickness, 1f, 1f, angle, 0, 0, 1, 1, false, false);
   }
   
   public static void drawLine(SpriteBatch batch, float _x1, float _y1, float _x2, float _y2, float thickness, Texture tex)
   {
      float length = Trigonometrics.getDistanceAccurate(_x1, _y1, _x2, _y2);
      float dx = _x1;
      float dy = _y1;
       dx = dx - _x2;
      dy = dy - _y2;
      float angle = MathUtils.radiansToDegrees*MathUtils.atan2(dy, dx);
      angle = angle-180;
      batch.draw(tex, _x1, _y1, 0f, thickness*0.5f, length, thickness, 1f, 1f, angle, 0, 0, tex.getWidth(), tex.getHeight(), false, false);
   }
   
   public static void drawSphereLightning(SpriteBatch batch, Vector2 point, float thickness, int numberOfBolts, int radius, int circleSegments)
   {
      for (int i=0;i<360f;i+=(360f/circleSegments))
      {
         tempSphereVector = Trigonometrics.getOrbitLocationDeg(point.x, point.y, i, radius);
         drawP2PLightning(batch, point.x, point.y, tempSphereVector.x, tempSphereVector.y, Util.getRandom(60f, 140f), Util.getRandom(0.8f, 3.8f), thickness, numberOfBolts);
      }
   }
   
   public static void drawChainLightning(SpriteBatch batch, Vector2[] points, float thickness, int numberOfBolts)
   {
      for (int i = 0;i<points.length-1;i++)
      {
         drawP2PLightning(batch, points[i].x, points[i].y, points[i+1].x, points[i+1].y, Util.getRandom(60f, 140f), Util.getRandom(0.8f, 3.8f), thickness, numberOfBolts);
      }
   }
   
   public static void drawP2ALightning(SpriteBatch batch, float x1, float y1, float x2, float y2, float displace, float detail, float thickness, float noise, int numberOfBolts)
   {
      batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
      for (int i=0;i<numberOfBolts;i++)
      {
         batch.setColor(Util.getRandom(14f, 54f)/255f, Util.getRandom(100f, 210f)/255f, Util.getRandom(200f, 239f)/255f, 1f);
         drawSingleP2PLightning(batch, x1, y1, x2+Util.getRandom(-noise, noise), y2+Util.getRandom(-noise, noise), 117, 1.8f, thickness);
      }
      batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
   }
   
   public static void drawP2PLightning(SpriteBatch batch, float x1, float y1, float x2, float y2, float displace, float detail, float thickness, int numberOfBolts)
   {
      batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
      for (int i=0;i<numberOfBolts;i++)
      {
         batch.setColor(Util.getRandom(14f, 54f)/255f, Util.getRandom(100f, 210f)/255f, Util.getRandom(200f, 239f)/255f, 1f);
         drawSingleP2PLightning(batch, x1, y1, x2, y2, 117, 1.8f, thickness);
      }
      batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
   }
   
   public static void drawSingleP2PLightning(SpriteBatch batch, float x1, float y1, float x2, float y2, float displace, float detail, float thickness)
   {
     if (displace < detail)
     {
        drawLine(batch, x1, y1, x2, y2, thickness, Content.texElec);
     }
     else
     {
       float mid_x = (x2+x1)*0.5f;
       float mid_y = (y2+y1)*0.5f;
       mid_x += (Math.random()-0.5f)*displace;
       mid_y += (Math.random()-0.5f)*displace;
       drawSingleP2PLightning(batch, x1,y1,mid_x,mid_y,displace*0.5f, detail, thickness);
       drawSingleP2PLightning(batch, x2,y2,mid_x,mid_y,displace*0.5f, detail, thickness);
     }
   }
   
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
Lunch (80 views)
2016-12-06 16:01:40

ral0r2 (305 views)
2016-11-23 16:08:26

ClaasJG (440 views)
2016-11-10 17:36:32

CoffeeChemist (527 views)
2016-11-05 00:46:53

jay4842 (577 views)
2016-11-01 19:04:52

theagentd (601 views)
2016-10-24 17:51:53

theagentd (583 views)
2016-10-24 17:50:08

theagentd (527 views)
2016-10-24 17:43:15

CommanderKeith (523 views)
2016-10-22 15:22:05

Roquen (473 views)
2016-10-22 01:57:43
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!