Temple of The Roguelike Forums
Development => Programming => Topic started by: Brigand on July 17, 2011, 04:38:51 PM
-
Are there any Java roguelikes out there that are open source? I've been learning Java at school, but they focus on pesky data structures and how to write white papers. I'm specifically interested in how the display elements are implemented. I downloaded Jcurses but it's hard to understand everything just reading the javadoc.
-
At the moment I am writing a rogue in java. How I am doing it is creating a class that extends JPanel which has char[][] and Color[][] Buffers. Writing the map to the screen all you need to do is override the JPanel's paintComponent(Graphics g) method:
public class MyJPanel extends JPanel
{
private Color[][] cColors; //The Colors of the map
private char[][] chChar; //The characters of the map
public MyJPanel()
{
cColors = new Color[20][20];
chChar = new char[20][20];
for(int iy = 0; iy < 20; iy++)
for(int ix = 0; ix < 20; ix++)
{
cColor[ix][iy] = Color.WHITE;
chChar[ix][iy] = '#';
}
}
//This overrides JPanel's paintComponent method
public void paintComponent(Graphics g)
{
super.paintComponent(g); //Always do this first when overriding paintComponent
for(int iy = 0; iy < 20; iy++)
for(int ix = 0; ix < 20; ix++)
{
g.setColor(cColors[ix][iy];
g.drawString(String.valueOf(chChar[ix][iy]),
StartX + (CharSpace * ix),
StartY + (LineSpace * iy));
}
}
}
In the g.drawString method:
StartX: is the pixel you wish to start drawing on the X axis,
StartY: is the pixel you wish to start drawing on the Y axis
CharSpace: is how I create spacing between each character - X axis spacing
LineSpace: is how I create spacing between each Line - Y axis spacing
Now if you wish to use tile graphics instead g has a many drawImage methods.
g has many methods in it to draw graphics onto a JPanel.
I hope this helps
Taffer
-
There's a bunch of Open Source Java roguelikes here: http://slashie.net/openxrl
You might also want to check libjcsi for console output in java, it might be just what you need: http://slashie.net/libjcsi/
-
You might also want to check libjcsi for console output in java, it might be just what you need: http://slashie.net/libjcsi/
Must...resist...writing engine...for jvm....
Damn you Slashie!!!