A Simple Game

Chapter I

Well, you made the project on your IDE, know PowerHigh works. Now let's do a very simple game!

First of all, i assume you know how to use java 9 modules. Since you know how to do it, make your module-info requires powerhigh.core and powerhigh.swing

Now let's create a new class, extending SimpleGame:

MyGame.java
public class MyGame extends SimpleGame {
    public static void main(String[] args) {
        new MyGame().start();
    }
}

You will see that since SimpleGame is an abstract class, you need to extend some methods, they will be explained later, overriding them should give the following:

MyGame.java
public class MyGame extends SimpleGame {

    public static void main(String[] args) {
        new MyGame().start();
    }
    
    @Override
    public void update(Interface win, double delta) {
    }
    
    @Override
    public void exit(Interface win) {
    }
    
    @Override
    public void init(Interface win) {
    }
    
}

The update(Interface, double) method takes in input an interface, it's purpose is for update (physics, movements) and input of the game.

The exit(Interface) will be automatically called by SimpleGame when the Interface is disposed (in most cases, closed).

The init(Interface) is called once just before the Interface is showed up on screen. It's mostly where we're gonna set size, viewports, attributes, etc.

If you understood all that, you know that to set the title, size, and resizability, it's to do in the init(Interface) method, it is very easy to do it!

MyGame.java:init(Interface)
win.setTitle("Hello PowerHigh");
win.setSize(640, 480);
win.setResizable(true);

Not hard to understand what thoses methods do! Now you arleady can run the project, and you will see a black window with "Hello PowerHigh" as title! Congratulations!

Last updated