Spent about 6 days to build a small game library for myself.
Features:
- Text resource loading
- UI components
- Parsing UI from xml
- Using javascript and Nashorn to handle button clicks
- Gravity handling
- Collision detection with callback handling
- Simple networking API with packet header storage
- Entity management system with cached rendering of layered vbo sprites, JavaScript AI parsing (wip)
- Font rendering
- Texture drawing
- Everything is rendered with VAOs that are often even batched in display lists
Turns this:
public class Game {
public static void main(String[] args) throws LWJGLException {
new Game(1280, 720, "Game").start();
}
private HashMap<String, Screen> screens = new HashMap<String, Screen>();
private String screen = "menu";
public Game(int width, int height, String title) throws LWJGLException {
Display.setTitle(title);
Display.setDisplayMode(new DisplayMode(width, height));
}
private static Game game;
public static Game getGame() {
return game;
}
public void start() throws LWJGLException {
Display.create();
GL11.glOrtho(0, 1280, 720, 0, 1, -1);
GL11.glClearColor(0.7f, 0.7f, 0.7f, 1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
InputSystem.HEIGHT = 720;
InputSystem.TARGET_DISPLAY_FPS = 90;
screens.put("menu", Screen.getScreen(new File("main-menu.xml")));
for (Screen screen : screens.values()) {
InputSystem.getSystem().addComponent(screen.getUI());
}
while (!Display.isCloseRequested()) {
game = this;
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
InputSystem.getSystem().collectInput();
screens.get(screen).render();
Display.update();
Display.sync(90);
}
}
}
<?xml version="1.0"?>
<!-- scale : 1.08333 -->
<screen>
<ui x="15" y = "15" width="650" height="475" background="main box.png">
<theme source="output.jar" />
<button layer="1" x="324" y="418" width="145" height="36" source="battle button.png" action="builder.js:printOutput()" />
<button layer="2" x="49" y="54" width="90" height="90" source="heal button.png" action="builder.js:printOutput()" />
</ui>
</screen>
function printOutput() {
print("Hello");
}
into a UI with two buttons and a background that prints “Hello” to the console when either button is clicked.
Such fun (but not very impressive)
CopyableCougar4