User Tools

Site Tools


making_your_first_game

Making your first game

Introduction

This tutorial is aimed at anyone interested in developing games for Swinxs, it will show you step by step instruction on how to create your first game.. Before you start making your first game, be sure to read getting started so you know how to set up your first game and create the right folders. This tutorial will show you how to make a simple Hello World game, I have already made the following folders and files:

Game Code

The first folder will contain the game code, the second folder will contain all language specific information such as .wav files and the game.prp.

  • C:\Documents and Settings\<user>\My Documents\SwinxsSource\games\00076\00000 hello world.st
    • Content: This is where we will place the game code.
  • C:\Documents and Settings\<user>\My Documents\SwinxsSource\eng\games\00076\00000 hello world.st
    • Content: append "..\..\..\games\00076\00000 hello world.st"
Text files

The following two files contain text and will be automatically converted to .wav files by the emulator. These .wav files contain the text from the text file spoken by a computer voice. This is an easy alternative to speaking the

  • C:\Documents and Settings\<user>\My Documents\SwinxsSource\eng\games\00076\00000.txt
    • Content: Hello World!
  • C:\Documents and Settings\<user>\My Documents\SwinxsSource\eng\games\00076\00001.txt
    • Content: Press the green button to make Swinxs say Hello World!

Variables

We start by declaring all global variables, for this game we will only need one; the first (and only) state. We will name it HELLO_WORLD_STATE_1, add the following code:

variables
{
    const HELLO_WORLD_STATE_1 := 1;
}

Startup

We begin be declaring the finite state machine, all our code will be placed here.

machine
{
 
}

The first state in a state machine is the startup state, this is where the execution of the state begins, we will make Swinxs explain how to play the game via a sound.play command and then move on to the first state. Add the following code to the machine:

startup
{
    sound.play("SOUND", 00001);        //Say: "Press the green button to make Swinxs say hello world!"
    state.move(HELLO_WORLD_STATE_1);   //Enter state HELLO_WORLD_STATE_1
}

It should now look like this:

machine
{
    startup
    {
        sound.play("SOUND", 00001);        //Say: "Press the green button to make Swinxs say hello world!"
        state.move(HELLO_WORLD_STATE_1);   //Enter state HELLO_WORLD_STATE_1
    }
}

State

Our game will only have one state, we named it HELLO_WORLD_STATE_1 in our variables list. To create the state we place the following code after the startup:

state(HELLO_WORLD_STATE_1)
{
 
}

When Swinxs enter this state it will still be playing the explanation sound or the “Hello World” sound, we must turn the sound off when he stops playing it or he will keep repeating himself. To do this, add the following code to the state:

if ( ! sound.playing )     //If there is no sound playing
{
    sound.off;             //Turn the sound off
}

The state should now look like this:

state(HELLO_WORLD_STATE_1)
{
    if ( ! sound.playing )     //If there is no sound playing
    {
        sound.off;             //Turn the sound off
    }
}

Now that Swinxs is not making any sound we can make him do what we want, which is saying “Hello World” when someone presses the green button. To do this, add the following code to the state:

if ( button.green.short )               //If the green button is shortly pressed
{
    sound.play ("SOUND", 00000); 	//Say: "Hello World!"
}

Complete Code

The game is now finished! This is what the complete code looks like:

variables
{
    const HELLO_WORLD_STATE_1 := 1;
}
 
machine
{
    startup
    {
        sound.play("SOUND", 00001);         //Say: "Press the green button to make Swinxs say hello world!"
        state.move(HELLO_WORLD_STATE_1);    //Enter state HELLO_WORLD_STATE_1
    }
 
    state(HELLO_WORLD_STATE_1)
    {
        if ( ! sound.playing )              //If there is no sound playing
        {
            sound.off;                      //Turn the sound off
        }
 
        if ( button.green.short )           //If the green button is shortly pressed
	{
	    sound.play ("SOUND", 00000);    //Say: "Hello World!"
	}
    }
}
making_your_first_game.txt · Last modified: 30-03-2009 23:19 by mark.ruys@swinxs.com