Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
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: vastrolorde (posted 2014-07-04 18:45:44, viewed 69 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   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235   236   237   238   239   240   241   242   243   244   245   246   247   248   249   250   251   252   253   254   255   256   257   258   259   260   261   262   263   264   265   266   267   268   269   270   271   272   273   274   275   276   277   278   279   280   281   282   283   284   285   286   287   288   289   290   291   292   293   294   295   296   297   298   299   300   301   302   303   304   305   306   307   308   309   310   311   312   313   314   315   316   317   318   319   320   321   322   323   324   325   326  
package com.me.mygdxgame;

import java.util.ArrayList;

import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;

public class World {
   
   private Player player;
   public static ArrayList<Bullet> bullets = new ArrayList<Bullet>();
   
   public World(int midPointX, Touchpad touchpad){
   //   player = new Player(midPointX-6,333 - 50,12,12, touchpad);
      player = new Player(midPointX-6,333 - 50,12,12);
   }
   
   public void update(float delta){
       player.update(delta);
       
       for(Bullet b: bullets){
          b.update(delta);
       }
   }
   
   public Player getPlayer(){
      return player;
   }
   
   public ArrayList<Bullet> getBullets(){
      return bullets;
   }
   
}

package com.me.mygdxgame;

import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;

public class Renderer {
   
   private World myWorld;
   private int gameHeight;
   private OrthographicCamera cam;
   private ShapeRenderer shapeRenderer;
   private List<Bullet> bullets = new ArrayList<Bullet>();
   
   public Renderer(World world, int gameHeight){
      myWorld = world;
      
      this.gameHeight = gameHeight;
      
      cam = new OrthographicCamera();
      cam.setToOrtho(true,272,gameHeight);
      
      shapeRenderer = new ShapeRenderer();
      shapeRenderer.setProjectionMatrix(cam.combined);
   }
   
   public void render(float runTime){
      Gdx.gl.glClearColor(0/255.0f, 0/255.0f, 0/255.0f, 1f);
       Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
       
       bullets = myWorld.getBullets();
       
       shapeRenderer.begin(ShapeType.Filled);

        shapeRenderer.setColor(87 / 255.0f, 109 / 255.0f, 120 / 255.0f, 1);

        shapeRenderer.rect(myWorld.getPlayer().getX(), myWorld.getPlayer().getY(),
                myWorld.getPlayer().getWidth(), myWorld.getPlayer().getHeight());

        shapeRenderer.end();

        shapeRenderer.begin(ShapeType.Line);

        shapeRenderer.setColor(255 / 255.0f, 109 / 255.0f, 120 / 255.0f, 1);

        shapeRenderer.rect(myWorld.getPlayer().getX(), myWorld.getPlayer().getY(),
                myWorld.getPlayer().getWidth(), myWorld.getPlayer().getHeight());

        for(Bullet b: bullets){
           shapeRenderer.rect(b.getX(), b.getY(), 5, 5);
        }
        
        shapeRenderer.end();
   }
}

package com.me.mygdxgame;

import com.badlogic.gdx.math.Vector2;

public class Bullet {
   private Vector2 position;
   private Vector2 velocity;
   
   public Bullet(Vector2 position, float vx, float vy){
      this.position = position;
      this.velocity = new Vector2(vx, vy);
   }
   
   public void update(float delta){
      position.add(velocity.cpy().scl(delta));

   }
   
   public float getX(){
      return position.x;
   }
   
   public float getY(){
      return position.y;
   }
}

package com.me.mygdxgame;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;

public class Player {
   private Vector2 position;
   
   private int width;
   private int height;
   private float runtime;

   private Touchpad touchpad;
   
   public Player(float x, float y, int width, int height){
      this.width = width;
      this.height = height;
      position = new Vector2(x,y);
      //this.touchpad = touchpad;

   }
   
   public void update(float delta){
      runtime += delta;
/*      position.x = position.x + touchpad.getKnobPercentX()*10;
      position.y = position.y - touchpad.getKnobPercentY()*10;*/

      if(position.x< 0){
         position.x = 0;
      }
      if(position.x+width > 272){
         position.x = 272 - width;
      }
      if(position.y < 0){
         position.y = 0;
      }
      if(position.y + height-1 > 333){
         position.y = 333 - height-1;
      }
      
      if(runtime > 0.5){
         runtime = 0;
         shot Shot = new shot(position.x, position.y);
      }
   }
   
   public float getX(){
      return position.x;
   }
   
   public float getY(){
      return position.y;
   }
   
   public float getWidth(){
      return width;
   }
   
   public float getHeight(){
      return height;
   }

}

package com.me.mygdxgame;

import java.util.ArrayList;

import com.badlogic.gdx.math.Vector2;

public class shot {
   private Vector2 position;
   private ArrayList<Bullet> bullets = new ArrayList<Bullet>();
   private Vector2 velocity;
   
   public shot(float x, float y){
      velocity = new Vector2(20,50);
      position = new Vector2(x,y);
      for(int i = 0; i<32; i++){
         velocity.setAngle(i*11.25f);
         World.bullets.add(new Bullet(position, velocity.x, velocity.y));
      }
   }
   
   public void update(float delta){
      for(Bullet b: bullets){
         b.update(delta);
      }
   }
   
   public float getX(){
      return position.x;
   }
   
   public float getY(){
      return position.y;
   }
   
   public ArrayList<Bullet> getBullets(){
      return bullets;
   }
}

package com.me.mygdxgame;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

public class Main {
   public static void main(String[] args) {
      LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
      cfg.title = "Test";
      cfg.width = 272;
      cfg.height = 408;
      
      new LwjglApplication(new TestGame(), cfg);
   }
}

package com.me.mygdxgame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;


public class Screens implements Screen{
   
   private World world;
   private Renderer renderer;
   private float runTime;
   
   private Stage stage;
   private Touchpad touchpad;
   private Skin touchpadSkin;
   
   public Screens(){
      float screenWidth = Gdx.graphics.getWidth();
        float screenHeight = Gdx.graphics.getHeight();
        float gameWidth = 272;
        float gameHeight = screenHeight / (screenWidth / gameWidth);
        int midPointX = (int) (gameWidth/2);
        
/*        touchpadSkin = new Skin(Gdx.files.internal("data/uiskin.json"));

        touchpad = new Touchpad(5, touchpadSkin);
        touchpad.setBounds(0, 0, 75, 75);
        
        stage = new Stage(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        stage.addActor(touchpad);*/
      
        world = new World(midPointX, touchpad);
      renderer = new Renderer(world,(int)gameHeight);
      
      //Gdx.input.setInputProcessor(new InputHandler(world.getPlayer()));
      Gdx.input.setInputProcessor(stage);
   }
   @Override
   public void render(float delta) {
       world.update(delta);
       renderer.render(runTime);
/*       stage.act();
       stage.draw();*/
   }

   @Override
   public void resize(int width, int height) {
      // TODO Auto-generated method stub
      
   }

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

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

   @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.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
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!