Pulsar 2D Documentation

About

Pulsar 2D is the successor of EGSL. It has some extensive game making features which will be covered in this documentation. I will start with the basics so everyone can (probably) follow. I will - however - give no introduction to Lua, there is a lot of material on the web.

Now let’s start with some of Pulsar’s features:

How to start

Download your package from the Pulsar2D site. At the time of writing this document P2D comes as a command line interpreter only. Extract the archive to your desired directory and you can start. A syntax highlighting file for Geany is part of the download. In Geany you can set pulsar2d[.exe] as the preferred Lua interpreter. If you want to use P2D with Free Pascal you should download the source of the engine.

First Test

Now it’s time for a first test. Type the following script into your preferred Editor/IDE:

    win=openwindow ("First Test",-1,-1,800,600)
    setactivewindow (win)
    color (255,255,0,255)
    fillcircle (400,300,250)
    sync()
    inkey()
    closewindow (win)
    closeapplication()

The result should look like this:

Now I will show what each line of the script means.

    win=openwindow ("First Test",-1,-1,800,600)

This opens obviously a new window with the caption “First Test” and the dimension 800 x 600. What are the -1 for? It says Pulsar2D to center the window on the screen once it opens. Instead of -1 you can specify a x and y value for the screen placement. Please take notice of that you don’t have to specify a depth value. This does Pulsar for you which takes the best value according to the desktop preferences.

    setactivewindow (win)

This is a rather important line. If you forget it nothing will happen except maybe an exception. ;-) So bear in mind to set an active window.

    color (255,255,0,255)
    fillcircle (400,300,250)

Ok, I take two lines at once. Color sets the drawing colour for graphics primitives in RGBA mode. So there is no extra function for the alpha channel anymore like it used to be in EGSL. The function fillcircle draws a filled circle at 400,300 with the radius 250.

sync()

It’s the same as in EGSL: sync() makes all your drawings (primitives, sprites, animations etc.) visible and includes also the correct frame timer. Like in ancient times we could have written wait (timeleft()) followed by a redraw().

inkey()

This waits until a key is being pressed. Usually one saves the result into a variable.

closewindow (win)

This closes the window. Please notice that we have to tell Pulsar2D which window shall be closed because there can be more than one window opened.

closeapplication()

This is important to end the program because it tells Pulsar2D that no new window will be opened anymore. The script can go on but only with pure Lua functions.

A first interactive example

Now the first example wasn’t really exciting, was it? We will now go on to a more advanced example where we will load an image convert it to a sprite and handle the players input.

Function reference

Video

openwindow (“caption”, xscreen, yscreen, width, height)

This opens a window and returns an integer for window handling. Xscreen and yscreen sets the position of the window on the screen. A value of -1 centers the window. If used in windowed mode an appropriate width and height is required. If changing to fullscreen mode immediately width and height should be set to 0.

Example:

win = openwindow ("AstroRocks, -1, -1, 1024, 768)

setactivewindow (windowID)

This sets the active window. After opening a window this should be the next function called if you wish to show output on the opened window. Also notice that the window must be set active before you load images or sprites since they are bound to the window and its render context.

Example:

setactivewindow (win)

closewindow (windowID)

This closes the given window. No output is possible anymore on that window.

Example:

closewindow (win)

closeapplication

color

redraw

circle

clearwindow

cls

backcolor