Hello World
From Victory Engine
Below is a simple Hello World game using the Victory engine with the Java 2D Display.
package org.victoryengine.tutorials.helloworld;
import org.victoryengine.geom.Point;
import org.victoryengine.graphics2d.Display2D;
import org.victoryengine.graphics2d.DisplayListener;
import org.victoryengine.graphics2d.DrawableAdapter;
import org.victoryengine.graphics2d.GC;
import org.victoryengine.graphics2d.Image;
import org.victoryengine.graphics2d.j2d.JDisplay;
import org.victoryengine.graphics2d.j2d.JDisplayParameters;
/**
* Simple game which loads an image of the world and displays it.
* Example of the Victory Engine.
* @author Bart van Heukelom
*/
public class HelloWorldGame extends DrawableAdapter implements DisplayListener {
private Image world;
private Display2D display;
public static void main(String[] args) {
new HelloWorldGame().start();
}
/**
* Set up the display.
*/
public HelloWorldGame() {
// set up a 2d window of 150 x 150 pixels
display = new JDisplay(new JDisplayParameters(150, 150));
// set this as listener, so the game can be exited
// when the window is closed. see windowClosed()
display.addListener(this);
// add this to the drawing loop, to draw the world
// see draw()
display.addDrawable(this);
// load a 150x150 image of the world
// which is placed directly in the classpath
world = display.getImageIO().loadImage(
ClassLoader.getSystemResource("world.png")
);
}
/**
* Start the display.
*/
public void start() {
display.start();
}
/**
* Draw the earth.
*/
public void draw(GC context) {
context.drawImage(world, new Point());
}
/**
* Exit the game when the window is closed.
*/
public void windowClosed() {
System.exit(0);
}
public void frameStart(GC context) {
// not used, but neccessary to implement DisplayListener
}
}
