Jump to content

  • Log In with Google      Sign In   
  • Create Account


[Help] Grid Based Dungeon Generator


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Heez   Members   -  Reputation: 103

Like
0Likes
Like

Posted 09 May 2014 - 05:56 AM

Hello everyone,

 

I am new to game development and to be honest I am an intermediate - beginner in the language of JAVA. I want to build a dungeon generator, based on rougelike techniques, such as the grid based dungeon generator. I read the instructions on the following site http://www.roguebasin.com/index.php?title=Grid_Based_Dungeon_Generator but I am not sure how I am able to implement all the data structures needed there.

 

I know how the floodfill algorithm works and I also know how to implement it later, but the first things I did do not work.

 

I have to create a grid of cells on an array and store four dimensions for each cell. If I have a cell of the size 5 on my array, the four dimensions would be (0,0) (4,0) (0,4) and (4,4) so the corner points of the cell, and the numbers are the locations on my two dimensional array.

 

The first thing I did was creating a datastructure which can hold a pair (2tupel) of Integers, called IntPair. Now I have to iterate over the array and store for each cell the four dimensions. How am I able to do this? If my description sucks, which it does, since I am confused at the moment, please visit the link and you get a clear idea of what I want to have.

 

All advice is welcome. I know that this is some basic stuff for most of you guys, but if you never have been into game development and such algorithms, its quite hard to write specifications into code right away.

 

Thank you in advance.



Sponsor:

#2 Glass_Knife   Moderators   -  Reputation: 3474

Like
0Likes
Like

Posted 09 May 2014 - 08:13 AM

First, these will help you with the Java game framework.

 

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-active-rendering-r2418

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-keyboard-and-mouse-r2439

 

As for your question, a simple solution is to create a custom object that contains all the data you need for the algorithm.  Then create a 2D array of your custom objects.


public class MyObject {

   private int data;
   
   public MyObject( int data ) {
      this.data = data;
   }
}

// elsewhere
  MyObject[][] grid = new MyObject[ROW_COUNT][COL_COUNT];
  for( int i = 0; i < grid.length;  ++i ) {
     for( int j = 0; j < grid[i].length;  ++j ) {
         grid[i][j] = new MyObject(i*j);  // just an example
     }
  }

I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#3 krinosx   Members   -  Reputation: 481

Like
0Likes
Like

Posted 09 May 2014 - 09:30 AM

Humm you may also take some time to study Java core classes.

 

You may use the java.awt.Point as your coordinate class and or a java.awt.Rectangle to represent your '4 coords'.

 

If you want to build your own classes from scratch, at least take a look in Point and Rectangle implementations to 'get inspired':

 

http://developer.classpath.org/doc/java/awt/Point-source.html

http://developer.classpath.org/doc/java/awt/Rectangle-source.html

 

After that you may create a 'java.util.List'  ( ArrayList, or any other lists that fit your algorithm ) and store the objects in it. Something like that:

    List<Rectangle> myCoords = new ArrayList<Rectangle>();	
		
		
    for (Rectangle rectangle : myCoords) {
	// Do what you want with your rectangle
			
	
    }

 It will serve to hold your 'grid' coordinates, you still need to create an array to hold your 'cell' data, so its up to you to decide if you will use an array of integers or build your custom 'Cell' object to hold your Data.

 

If you are a OO programmer and want to use OO to model your problem, so you will build your own Cell class... otherwise, just follow with integer and primitive types.



#4 Heez   Members   -  Reputation: 103

Like
0Likes
Like

Posted 09 May 2014 - 10:51 AM

 

First, these will help you with the Java game framework.

 

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-active-rendering-r2418

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-keyboard-and-mouse-r2439

 

As for your question, a simple solution is to create a custom object that contains all the data you need for the algorithm.  Then create a 2D array of your custom objects.


public class MyObject {

   private int data;
   
   public MyObject( int data ) {
      this.data = data;
   }
}

// elsewhere
  MyObject[][] grid = new MyObject[ROW_COUNT][COL_COUNT];
  for( int i = 0; i < grid.length;  ++i ) {
     for( int j = 0; j < grid[i].length;  ++j ) {
         grid[i][j] = new MyObject(i*j);  // just an example
     }
  }

This is exactly how I created my IntPair class. In the constructor of this class I said that it has to have to parameters. So public void IntPair(int x, int y) {this.x = x; this.y=y} . After this I created an IntPair Array in my Cell Class (also in its constructor) and then I got stuck since I am not sure how to write it that it will save two Integers in an array of Int pair..

 

So IntPair intpair = new IntPair[4] // Since I only need 4 places per cell. Now I dont know how to assign ints to them. If I would create a single IntPair I would type: IntPair intp = new IntPair(3,3) . As I said, this is basic stuff. But I am confused at the moment.

 

//Edit : I got it, nevermind guys. Now I know how to safe a Pair of Ints, I wrote my own class. The next thing is to put a bunch of cells on an array. Thanks for your help.

 

 


Edited by Heez, 09 May 2014 - 11:16 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS