Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
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: Vladiedoo (posted 2012-10-14 13:06:59, viewed 338 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  
// This is a incomplete basic example for Delinitor.

// - Main Class -
package george.game.cells;

import net.indiespot.media.test.TestGameLoop;

import org.lwjgl.LWJGLException;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

public class PrisionIsYourFriend extends StateBasedGame {

   private static final String GAME_NAME = "Prision Is Your Friend v0.0001";
   
   // If you're doing 600x600, I recommend 800x600 instead.
   private static final int WIDTH = 600, HEIGHT = 600;
   
   private static final int SCALE = 2;

   public static AppGameContainer appgc;

   public PrisionIsYourFriend(String GAME_NAME) {
      super(GAME_NAME);
   }

   public void initStatesList(GameContainer gc) throws SlickException {
      long startTime = System.currentTimeMillis();
      
      addState(new World(World.CURRENT_LEVEL));
      enterState(World.CURRENT_LEVEL);
      
      long endTime = System.currentTimeMillis();
      
      System.out.println("Total time to initialize took " + (endTime - startTime) + " milliseconds.");
   }

   public static void main(String[] args) throws LWJGLException {
      try {
         appgc = new AppGameContainer(new PrisionIsYourFriend(GAME_NAME));
         appgc.setDisplayMode(WIDTH, HEIGHT, false);
         // You can set the icon of your window.
         //appgc.setIcon("res/image/logos/logo.png");
         appgc.setTargetFrameRate(60);
         appgc.setVSync(true);
         appgc.setAlwaysRender(false);
         appgc.setUpdateOnlyWhenVisible(true);
         appgc.setShowFPS(false);
         appgc.start();

      } catch (SlickException e) {
         e.printStackTrace();
      }
   }
}

// World Class

package george.game.cells;

public class World {

   public static final byte CURRENT_WORLD = -1;
   public static final byte WORLD_ZERO = 0;
   public static final byte WORLD_TWO = 1;
   public static final byte WORLD_THREE = 2;
   public static final byte WORLD_FOUR = 3;
   
   // Other useful methods here.
}

// World Zero

package george.game.cells;

import org.lwjgl.input.Mouse;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tiled.TiledMap;

public class WorldZero extends BasicGameState {

   // ID for this state.
   private final byte THIS_STATE = World.WORLD_ZERO;

   private Polygon player;
   
   private int playerMovementSpeed = 2;
   
   private int playerX = 50, playerY = 50;

   private Polygon pressurePlate;

   private TiledMap map;

   private int tileWidth, tileHeight, mapWidth, mapHeight;
   
   private int mapX, mapY;
   
   private boolean activaed;

   // This is based on the tiles you used. If this tile is the second tileset in your Tiled program, it's ID will probably be 2.
   private int PRESSURE_PLATE_ID;

   public WorldZero() {
   }

   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
      long startTime = System.currentTimeMillis();

      map = new TiledMap("res/map");

      tileWidth = map.getWidth();
      tileHeight = map.getHeight();
      mapWidth = map.getWidth() * map.getTileWidth();
      mapHeight = map.getHeight() * map.getTileHeight();

      // Makes the player a 32x32 square
      player = new Polygon(new float[] { 0, 0, 32, 0, 32, 32, 0, 32 });
      // Makes the player start at (50, 50)
      player.setX(playerX);
      player.setY(playerY);

      for (int x = 0; x < mapWidth; x++) {
         for (int y = 0; y < mapHeight; y++) {
            // The third variable in "map.getTiledId(x, y, 0)" is the layer, if you don't know what this is just put 0.
            if (map.getTileId(x, y, 0) == PRESSURE_PLATE_ID) {
               Polygon pressurePlate = new Polygon(new float[] { 0, 0, tileWidth, 0, tileWidth, -tileHeight, 0, -tileHeight });
               pressurePlate.setX(x * tileWidth);
               pressurePlate.setY(y * tileHeight);
            }
         }
      }

      long endTime = System.currentTimeMillis();
      System.out.println("WorldZero loaded in " + (endTime - startTime) + " milliseconds.");
   }

   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
      map.render(mapX, mapY);
      g.setColor(Color.red);
      g.fill(player);
      g.setColor(Color.magenta);
      g.fill(pressurePlate);
      
   }

   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

      // A very basic version that could be updated.
      Input input = gc.getInput();
      if (input.isKeyDown(Input.KEY_W)) {
         playerY -= playerMovementSpeed * delta;
      }
      if (input.isKeyDown(Input.KEY_A)) {
         playerX -= playerMovementSpeed * delta;
      }
      if (input.isKeyDown(Input.KEY_S)) {
         playerY += playerMovementSpeed * delta;
      }
      if (input.isKeyDown(Input.KEY_D)) {
         playerX += playerMovementSpeed * delta;
      }
      player.setX(playerX);
      player.setY(playerY);
      
      
      if (pressurePlate.intersects(player) || pressurePlate.contains(player)){
         // Set the blocking tile one higher and it's previous posion to a default walking tile.
         map.setTileId(x, y, layerIndex, tileid);
         map.setTileId(x, y, layerIndex, tileid);
      } else {
         // Set the blocking tile to be in the way again.
         map.setTileId(x, y, layerIndex, tileid);
         map.setTileId(x, y, layerIndex, tileid);
      }

   }

   public int getID() {
      return THIS_STATE;
   }
}





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.

TehJavaDev (37 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (43 views)
2014-10-26 19:37:11

Luminem (24 views)
2014-10-26 10:17:50

Luminem (29 views)
2014-10-26 10:14:04

theagentd (35 views)
2014-10-25 15:46:29

Longarmx (63 views)
2014-10-17 03:59:02

Norakomi (61 views)
2014-10-16 15:22:06

Norakomi (50 views)
2014-10-16 15:20:20

lcass (45 views)
2014-10-15 16:18:58
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!