3

I am a beginning Java Game Developer. For my first game, I'm making something along an advanced version of Minicraft by Notch. However I have absolutely clue how to make a 2D Tile-Based World Generator.

Would anyone mind explaining how I would do this and maybe a link or two to some YouTube Videos?

I am using Eclipse EE for Java Developers.

Also I can't seem to resize my window to make the pixels larger. The image is 16 x 16 pixels, however I'd like to display it larger like minicraft (link above)

Here is the code for Skeleton.java (which is the framework ('Skeleton') of the game)`

 package code;

 import java.awt.Graphics;

public class Skeleton extends Loop{ //Should extend Applet?
public void init(){
Thread th= new Thread(this);
th.start();
offscreen = createImage(120,160); // 120, 160
d = offscreen.getGraphics();
addKeyListener(this); //15:43
}
public static final int HEIGHT = 120; //Original Height/Width= "120 x 160"
public static final int WIDTH = 160;
public static final String TITLE= "Test Game BETA";
public static final int SCALE = 3;

public void paint(Graphics g) {
d.clearRect(0, 0, 160, 120); //Error Here, Scale perhaps? -Disregard //0,0,160,120      
d.drawImage(him, x, y, this);     //12:17 http://www.youtube.com/watch?v=XmRD0PlAXEY
g.drawImage(offscreen, 0, 0, this);
}
public void update(Graphics g){
    paint(g);
} //Finished at 15:33 ERROR w/ the circle -Fixed
   } 
   //2D Tile Engine Must be Created
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Kultid_Games
  • 311
  • 1
  • 3
  • 10
  • Please don't forget to click on the link! – Kultid_Games Jan 07 '14 at 20:34
  • pixels are based on the display density. You cant really make a pixel *larger* persay. ALSO: for game maps that are random, you will also want to make an algorithm for likelihood of the adjancent blocks to be a different type. you like, like 80% chance that dirt is next to dirt with a 5% chance that stone is next to dirt. That way your map isnt random, but infact has a flow about it. – Fallenreaper Jan 07 '14 at 20:37
  • 4
    JAVA IS NOT JAVASCRIPT!!! – PitaJ Jan 07 '14 at 20:37
  • Everything I have learned about 2D world gen, I learned from RogueBasin. Here is a nice set of articles on the topic: http://www.roguebasin.com/index.php?title=Category:WorldGeneration – zero298 Jan 07 '14 at 22:50
  • I know its not javascript, but unfortunately I accidentally clicked it, sorry. – Kultid_Games Jan 07 '14 at 23:08
  • I know it's not 2D, but take a look at Infinite Mario Bros since the main point of this project was level generation: http://mojang.com/notch/mario/ – Daniel Jan 07 '14 at 23:22
  • Please format your code (ctrl+shift+F in Eclipse) – Joren Oct 15 '14 at 19:26

2 Answers2

0

I am working on a project that is almost identical to this. The way I generate the worlds, I have a two-dimensional array of tiles, and a method that populates the array with tiles. The way the world is generated, I place a grass tile in each column, followed by a randomly determined number of dirt tiles, followed by stone tiles until the bottom of the world. Then, for the next column, I place a grass tile at a y-coordinate that is between -2 and +2 tiles from the previous grass's y-coordinate, and fill the rest of the column as before. Continue until you get to the end of the array.

Epiglottal Axolotl
  • 1,048
  • 8
  • 17
  • Thank you for the advice and I'll try to do the same, roughly anyway. – Kultid_Games Jan 07 '14 at 23:22
  • For ores you can do an random coordinates below what ever level you want and then use more random numbers determine wether or not the vein spreads on. – Moddl Aug 06 '14 at 03:40
0

To rescale images, I use this method

public void drawRezizedImage(Graphics g, Image image, int x, int y, int sizeX, int sizeY){

    image.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
    g.drawImage(image, 0, 0, null);

}

This will simply draw a rescaled version of your, in this case 16 by 16px image. Hope this was, what you were looking for.

Oliver
  • 7
  • 7