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 (568)
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: davedes (posted 2013-06-03 20:18:52, viewed 500 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   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126  
package mdesl.line2dx.test;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20;
import com.badlogic.gdx.math.MathUtils;

public class ProgressBarTest implements ApplicationListener{

   Texture lookup;
   OrthographicCamera cam;
   SpriteBatch batch;
   
   float percent;
   ImmediateModeRenderer renderer;

   float p = 0f;
   float v = 1f;
   
   @Override
   public void create() {
      cam = new OrthographicCamera();
      batch = new SpriteBatch();
      lookup = new Texture("data/lookup.png");
      lookup.setFilter(TextureFilter.Linear, TextureFilter.Linear);
      
      if (Gdx.graphics.isGL20Available())
         renderer = new ImmediateModeRenderer20(false, true, 1);
      else
         renderer = new ImmediateModeRenderer10(5000);
   }

   @Override
   public void resize(int width, int height) {
      cam.setToOrtho(false);
      batch.setProjectionMatrix(cam.combined);
   }

   
   @Override
   public void render() {
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      
      float r = 25f;
      float cx = 250f;
      float cy = 50f;
      float thickness = 12f;
      
      //increase percentage
      p += v * 0.75f * Gdx.graphics.getDeltaTime(); 
      if (p>1f) {
         p = 1f;
         v *= -1f;
      } else if (p<0f) {
         p = 0f;
         v *= -1f;
      }
      progress(cx, cy, r, thickness, 1f, Color.GRAY, lookup);
      progress(cx, cy, r, thickness, p, Color.WHITE, lookup);
      
      
   }
   
   public void progress(float cx, float cy, float r, float thickness, float amt, Color c, Texture lookup) {
      //start and end angles
      float start = 0f;
      float end = amt * 360f;
      
      lookup.bind();
      renderer.begin(cam.combined, GL10.GL_TRIANGLE_STRIP);
      Gdx.gl.glEnable(GL10.GL_BLEND);
      Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
      int segs = (int)(12 * Math.cbrt(r));
      end += 90f;
      start += 90f;
      float halfThick = thickness/2f;
      float step = 360f / segs;
      for (float angle=start; angle<(end+step); angle+=step) {
         float tc = 0.5f;
         if (angle==start)
            tc = 0f;
         else if (angle>=end)
            tc = 1f;
         
         float fx = MathUtils.cosDeg(angle);
         float fy = MathUtils.sinDeg(angle);
         
         float z = 0f;
         renderer.color(c.r, c.g, c.b, c.a);
         renderer.texCoord(tc, 1f);
         renderer.vertex(cx + fx * (r + halfThick), cy + fy * (r + halfThick), z);
         
         renderer.color(c.r, c.g, c.b, c.a);
         renderer.texCoord(tc, 0f);
         renderer.vertex(cx + fx * (r + -halfThick), cy + fy * (r + -halfThick), z);
      }
      renderer.end();
   }

   @Override
   public void pause() {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void resume() {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void dispose() {
      // TODO Auto-generated method stub
      
   }

}





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 (39 views)
2014-09-24 16:13:29

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

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

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

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

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

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

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

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

BurntPizza (54 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!