Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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: BurntPizza (posted 2014-08-09 21:09:32, viewed 93 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  
import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class TestScreen implements Screen {
   
   SpriteBatch batch;
   
   Texture cannonBall;
   
   List<Entity> entities;
   
   int frameCount = 0;
   
   {
      batch = new SpriteBatch();
      entities = new ArrayList<Entity>();
      
      { // create cannonBall texture
         Pixmap p = new Pixmap(32, 32, Format.RGBA8888);
         p.setColor(0);
         p.fill();
         p.setColor(.5f, .5f, .5f, 1);
         p.fillCircle(p.getWidth() / 2, p.getHeight() / 2, p.getWidth() / 2);
         cannonBall = new Texture(p);
         p.dispose();
      }
   }
   
   @Override
   public void dispose() {
      batch.dispose();
   }
   
   @Override
   public void hide() {
      
   }
   
   @Override
   public void pause() {
      
   }
   
   @Override
   public void render(float delta) {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      
      // every second or so add another ball
      if (frameCount++ % 60 == 0)
         entities.add(new Entity(cannonBall));
      
      batch.begin();
      
      for (Entity e : entities) {
         e.update(delta);
         e.render(batch);
      }
      
      batch.end();
   }
   
   @Override
   public void resize(int width, int height) {
   }
   
   @Override
   public void resume() {
   }
   
   @Override
   public void show() {
   }
   
}

class Entity {
   
   static final float BULLET_SPEED = 300;
   static final Rectangle screenBounds = new Rectangle(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
   
   Vector2 position, velocity, acceleration;
   Texture sprite;
   
   Vector2 target;
   
   Entity(Texture sprite) {
      reset();
      acceleration = new Vector2(0, -400); // gravity
      this.sprite = sprite;
   }
   
   private void reset() {
      position = new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
      target = new Vector2(Gdx.input.getX(), Gdx.graphics.getHeight() - 1 - Gdx.input.getY());
      velocity = target.cpy().sub(position).nor().mul(BULLET_SPEED); // fire towards target
   }
   
   void render(SpriteBatch batch) {
      batch.draw(sprite, position.x, position.y);
   }
   
   void update(float delta) {
      // if entity leave screen, then in this demo we just reset it.
      if (!screenBounds.contains(position.x, position.y))
         reset();
      
      // simple Euler integration
      position.add(velocity.cpy().mul(delta));
      velocity.add(acceleration.cpy().mul(delta));
      // acceleration will stay constant for this demo
   }
}





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.

toopeicgaming1999 (72 views)
2014-11-26 15:22:04

toopeicgaming1999 (62 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!