Nicol Tutorial

Welcome to the first draft of my Nicol Tutorial. We will cover some basic ideas here, like how to get started, use the Scenes, get user input and draw stuff.

This Tutorial assumes you are familiar with Scala and SBT. If you don't know what either is, you should probably get somewhere else and return when you know.

Getting Started

Nicol is based on SBT and I recommend that you will use it, too. This tutorial assumes that you do, and also know Github.

Using the Template

For Nicol, we need to have LWJGL correctly set up, which can be always a bit tricky. Fortunately, my friend philcali provides us with a plugin and a template for giter8. Just follow the instructions there to install giter8, then you can start a new project with the template.

$> g8 philcali/nicol-project.g8

This will ask a few things from you, you should know what to answer.

The Created Project

The result will be a simple Nicol project with usual SBT file structure. Before you can get started, you must call

$> sbt update

at least once, to pull in all necessary .jars. Then you may try to run with

$> sbt run

Which should give you a nice little window with simple text. Congrats and welcome to Nicol!

The Scenes

In the file Stub.scala, the only source file of you project thus far, you see this code:

import nicol._
import input.Key._

object App extends Game(Init("Nicol Project", 800, 600) >> Main)

object Main extends GameScene with SyncableScene with StandardRenderer {
  def update = {
    draw("Hello Nicol Project! Thank you for using Nicol", position = (300, 300))

    if (escape) End else None
  }
}
				

But what do these mean? Well, the imports are clear. And App seems to be the game entry point.

The Game Class

The Game class is probably one of the simples in the Framework. Basically, it is a startup for our Scenes and takes as only parameter the startup scene.

What is a Scene in Nicol and why does it have a captitalised S? Basically any closed section of the game. Scenes may be as small as you like, or as big as you need. Nicol gives you a couple of pre-defined Scenes for your convenience.

Init is one of them. Init takes a window size and a title for the window, and opens it. And then... the Scene ends. And so does the game. Not very good.

Scene Combination

Init needs a follow-up Scene, so the game can go on. The Scene trait provides us with an operator, >>, which combines two Scenes to a new one. They get executed in order.

So we combine the Init Scene with our own follow-up scene. For example, Main.

A GameScene

Main inherits from GameScene, among others. A GameScene is a Scene with a game loop in it, and one that provides its own follow-up. Any GameScene has to provide an update method which represents one frame in the loop. It is of the type () => Option[Scene] and returns a new Scene if this one is done, or None.

As a little side note, the returned Scene of this method is always executed before the one specified with >>.

The End

Another special provided Scene is End. This little Scene closes the window and cleans up the LWJGL subsystem, so it is a good idea to always make it the end of your game, too.