Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: [Question] Rendering Tiles from an Array of Chunks on: 2013-01-09 19:24:28
Not sure I understand the question exactly, but I would go about it like this.  Let's say your chunks are 32x32 tiles and your world is made up of 100x100 chunks.  You have an area of 3200x3200 to explore. 

Let's say you know that the character is at tile 1000,2000 - the starting point.  You get the chunk that tile is in by Math.floor(1000/32) and Math.floor(2000/32).  Those are the coordinates of the chunk.

You can go in the other direction too.  If you know a tile is at 10,10 in a chunk then its world coordinate is 32*chunkCoordinate + 10.

Note that the coordinates go from 0 - 31 for a chunk with 32x32 tiles.

For rendering you can test if any of a chunk is on the screen before you render it.  This saves you from rendering things that are not visible.  Do this check at the chunk level.  Then for chunks that are partially on the screen run the check again at the tile level.  To improve performance just grab the chunk coordinates around the player to do the tests, rather than all of them.

For debugging, I find it is helpful to insert some code to color the corners of the chunk so that you can see that everything lines up well.  You remove the coloring once it works.  In fact you can render dummy chunks with just corner tiles to test this out.

Ask more questions if that does not help or if I misunderstood the question.

2  Game Development / Newbie & Debugging Questions / Re: ConcurrantModificationException on: 2013-01-07 23:33:31
I would use the standard for loop.  You get very used to the format of it.  I save iterators for hashMaps and other collections that are not easy to traverse with a simple loop. 
3  Game Development / Newbie & Debugging Questions / Re: How to HANDLE collision? on: 2012-12-05 17:54:01
I created a function called collisionDetectedSlide().  When a collision is detected, it does not roll back the players position, it just rolls back the component of the vector that caused the collision.  So it the player only overlapped the object in the Z direction, then it just rolls back the Z movement.  This means that players rolls off objects and slides along them if they hit the object at an angle.  It works much better than just rolling back the movement, which tends to make the player stick to the wall when they hit it.  Basically each time the player moves you store the previous X,Y,Z positions.  Then revert one or more of them if the movement resulted in a collision.

Its as simple as this:

    * Check if the player has intersected with a block and slide along a surface if you hit it at an angle
    * Makes for a better play experience than coming to a dead halt.
    * @param lastX
    * @param lastY
    * @param lastZ
   private void collisionDetectedSlide(float lastX, float lastY, float lastZ) {
      boolean undo=false;
      float x = player.getX();
      float y = player.getY();
      float z = player.getZ();
      float newx, newy, newz;
      if (collisionDetected(x, lastY, lastZ)) {
         newx = lastX;
      } else newx=x;
      if (collisionDetected(lastX, y, lastZ)) {
         newy = lastY;
      } else newy=y;
      if (collisionDetected(lastX, lastY, z)) {
         newz = lastZ;
      } else newz=z;
      if (undo) player.undoMove(newx, newy, newz);
4  Game Development / Newbie & Debugging Questions / Re: LWJGL Loading Progress on: 2012-12-05 17:43:26
I think the key might be that you are missing Display.sync(60).  So Display.update() tries to render the screen at as high a frame rate as possible.  Add that just after you Display.update() and see if it reduces the time.

As the post above says, there are probably ways to reduce the 1.7 seconds, but the extra time for drawing the screen should not be there.
5  Game Development / Newbie & Debugging Questions / Re: Thought process of making a game. Am I doing this right? on: 2012-12-05 17:34:05
Start with something simple, but which progresses you towards the finished game.  I would start with the game board.  See if you can render the board on the screen.

Don't start with an image of the board, you need to store the positions of the walls in a data structure and then render each wall in the right location.  You will need that if the walls can be removed and added by spells. You also need to know where the walls are so that later, the player and monsters are prevented from passing through walls. 

It looks like a 2D tile game, which is a great place to start, so use a 2D array.  Something like

byte[][] maze = new byte[32][32]

would create an empty array.

Write a game loop that does nothing other than draw the screen.  The screen can be a single quad for the "grass" in the background and then small quads where ever you have data in your array.  I suggest using a byte in the data structure, rather than a Boolean, because you could have different wall types in the future.

You will need to fill the array with data of course.  For a test like this you might just put it into the code by hand.  Maybe start with an 8x8 grid.

Once you have a maze, add a Character.  It can be a simple sprite that hops from tile to tile as you press the keys.  Then you can make it move smoothly with more changes to the code. Stop is hitting walls.  Add other entities and so on.

You will not end up with an award winning game this way and the code will be far from optimal.  But you will learn a lot.  And your next game will be better.

6  Game Development / Newbie & Debugging Questions / Re: MAC OSX Fullscreen on: 2012-12-05 16:55:51
Its OSX 10.6 on a laptop. Everything else runs fine.  The mouse is a bit too sensitive, but that is fixable.

Here is the code.  Like I said, I think it is straight from the tutorial:

    * Set the display mode to be used
    * @param width The width of the display required
    * @param height The height of the display required
    * @param fullscreen True if we want fullscreen mode
   private void setDisplayMode(int width, int height, boolean fullscreen) {

      // return if requested DisplayMode is already set
            if ((Display.getDisplayMode().getWidth() == width) &&
         (Display.getDisplayMode().getHeight() == height) &&
         (Display.isFullscreen() == fullscreen)) {
      try {
         DisplayMode targetDisplayMode = null;
         if (fullscreen) {
            DisplayMode[] modes = Display.getAvailableDisplayModes();
            int freq = 0;
            for (int i=0;i<modes.length;i++) {
               DisplayMode current = modes;
               if ((current.getWidth() == width) && (current.getHeight() == height)) {
                  if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) {
                     if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) {
                        targetDisplayMode = current;
                        freq = targetDisplayMode.getFrequency();

                  // if we've found a match for bpp and frequency against the
                  // original display mode then it's probably best to go for this one
                  // since it's most likely compatible with the monitor
                  if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) &&
                      (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) {
                     targetDisplayMode = current;
         } else {
            targetDisplayMode = new DisplayMode(width,height);
         if (targetDisplayMode == null) {
            System.err.println("Failed to find valid mode: "+width+"x"+height+" fs="+fullscreen);

      } catch (LWJGLException e) {
         System.err.println("Unable to setup mode "+width+"x"+height+" fullscreen="+fullscreen + e);
7  Game Development / Newbie & Debugging Questions / MAC OSX Fullscreen on: 2012-12-04 03:56:19
Here's a strange one.  I've developed a game on the PC and just tested it on a MAC.  It works fine, except when I press F1 to toggle into Fullscreen mode, the screen spins around and around like crazy.  Toggling back from fullscreen does not stop the spinning.  You have to stop the game and restart.

Anyone else seen this?  I've basically used the fillscreen code from one of the tutorials.  Is there a fix?


Pages: [1]

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (28 views)
2014-04-15 18:08:23

BurntPizza (25 views)
2014-04-15 03:46:01

UprightPath (40 views)
2014-04-14 17:39:50

UprightPath (22 views)
2014-04-14 17:35:47

Porlus (38 views)
2014-04-14 15:48:38

tom_mai78101 (62 views)
2014-04-10 04:04:31

BurntPizza (121 views)
2014-04-08 23:06:04

tom_mai78101 (221 views)
2014-04-05 13:34:39

trollwarrior1 (188 views)
2014-04-04 12:06:45

CJLetsGame (195 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30 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‑
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!