Saturday 6 September 2014

Kilvish Game Engine - Getting Started

Prerequisites:
  • Java Development Kit - the Java language and runtime system
  • Eclipse - a development environment for Java. (you can use another IDE if you like, but this tutorial assumes an Eclipse environ)
Setting up the environment
(make sure you have Java and Eclipse installed before continuing)
    A game-engine is a framework for writing games. Kilvish Game Engine is such a system that is simple to learn, use, and modify. We'll start with setting up a Kilvish project in Eclipse.
  • Download the zipped version of the engine from the project's site (top-right)
  • In eclipse, go to File -> Import -> General -> Existing Projects into Workspace
  • Choose select archive file and click Browse
  • Select the downloaded zip file, and click Finish
You should now see the Kilvish project in your Package Explorer (on the left).

Let's start!
    Go to KILVISH -> examples -> clouddemo -> CloudDemo.java.
This should be what you see
    Now click the Run button. (green play-button on the top panel)
The cloud demo

    The cloud looks pretty still and boring, doesn't it? Let's animate it!
    Note: The setFPS(60) method call tells Kilvish to update the game 60 times every second.
    Modify the constructor to look like this:
CloudDemo(){
 super(600, 400);
 this.setFPS(60);
  
 cloud = new Sprite("cloud");
 cloud.addImage(cloudImg1, 10);
 cloud.addImage(cloudImg2, 10);
 this.add(cloud);
}
 
    What this will do is display the two added images in a loop, with each image being displayed for 10 frames at a time. Save the file, and hit Run again. Easy, right?

    But what if we want the cloud to move? Add this method above main:
public void update(){
 cloud.moveBy(1, 0);
}

    This method is called by Kilvish every time the game is updated, and we have overridden it to move the cloud one pixel to the right. Save and Run again. Pretty neat!

    Now add this line to the constructor:
new DragAdapter(cloud);

    You should now be able to drag the cloud around the screen!

What Now?
    Believe me, this covers most of what you need to know to make a game. Now that you know the absolute basics, it would be a good time to check out the other examples that come bundled with the engine. The code is as simple as this for the most part.
    If there is anything at all that you have trouble understanding, you can leave a comment and I'll be happy to explain. Happy coding!