So let's get started. Download and start Eclipse (or whatever IDE you're most familiar with) and start up a new project. I'm calling mine "rltut". Download the AsciiPanel jar file and add that to your project.
We'll start with something very simple: just a window with some text on it.
package rltut;
import javax.swing.JFrame;
import asciiPanel.AsciiPanel;
public class ApplicationMain extends JFrame {
private static final long serialVersionUID = 1060623638149583738L;
private AsciiPanel terminal;
public ApplicationMain(){
super();
terminal = new AsciiPanel();
terminal.write("rl tutorial", 1, 1);
add(terminal);
pack();
}
public static void main(String[] args) {
ApplicationMain app = new ApplicationMain();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setVisible(true);
}
}
![]() |
If you're using Eclipse, your project should look something like this |
The serialVersionUID is suggested by Eclipse and helps to prevent show-stopping failures when serializing different versions of our class. We won't be doing that in this tutorial but it's almost always a good idea to take care of compiler and IDE warning as soon as possible; It will save much trouble down the line.
The ApplicationMain constructor has all the set up code. So far that's just creating an AsciiPanel to display some text and making sure the window is the correct size. The AsciiPanel defaults to 80 by 24 characters but you can specify a different size in it's constructor - go ahead and try it. Play around with the write method while you're at it.
The main method just creates an instance of our window and show's it, making sure that the application exits when the window is closed. Simple as can be.
For extra awesomeness you can make your roguelike run from the users browser as an applet. Just add a file like this to your project:
package rltut;
import java.applet.Applet;
import asciiPanel.AsciiPanel;
public class AppletMain extends Applet {
private static final long serialVersionUID = 2560255315130084198L;
private AsciiPanel terminal;
public AppletMain(){
super();
terminal = new AsciiPanel();
terminal.write("rl tutorial", 1, 1);
add(terminal);
}
public void init(){
super.init();
this.setSize(terminal.getWidth() + 20, terminal.getHeight() + 20);
}
public void repaint(){
super.repaint();
terminal.repaint();
}
}
It's a good start. You don't have much but anyone can play it since it runs on any modern computer either from the user's browser or downloaded and run from the user's machine.
download the code
No comments:
Post a Comment