Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 139 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
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (35 views)
2014-09-24 16:13:29

Pippogeek (28 views)
2014-09-24 16:12:22

Pippogeek (17 views)
2014-09-24 16:12:06

Grunnt (40 views)
2014-09-23 14:38:19

radar3301 (23 views)
2014-09-21 23:33:17

BurntPizza (58 views)
2014-09-21 02:42:18

BurntPizza (29 views)
2014-09-21 01:30:30

moogie (34 views)
2014-09-21 00:26:15

UprightPath (47 views)
2014-09-20 20:14:06

BurntPizza (51 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!