First Step Pascal

From SwinGame

This tutorial guides you through the process of really getting started with the SwinGame SDK. In this tutorial you will learn to open a window, draw images, draw sprites and move, play sounds, and have some interactivity within your game. At the end of the tutorial you should be much more comfortable using the SwinGame SDK and ready to start working on your own game.

OK so at this stage you have:

Now it is time for your first program in Swingame: "Hello World".

Hello World

Follow these steps to get a "Hello World" program working with SwinGame.

  1. Extract the files you get from the SDK into a folder of your choosing, e.g. "c:\temp\HelloWorld" on Windows
  2. Open a console window (run cmd on Windows) and move into the folder above, e.g. "cd c:\temp\HelloWorld"
  3. You can compile the game using winbuild.cmd HelloWorld.exe on Windows or ./build.sh HelloWorld on Mac or Linux.
  4. Open the "GameLogic" file. You should be presented with the following code:
///
/// GameLogic.pas
///
/// --------------------------------------
///	 This file contains the logic for your
///  game. The Main procedure is called from
///  the game launcher. 
/// --------------------------------------
unit GameLogic;
 
interface
  procedure Main();
 
implementation
uses
  GameResources,
  SysUtils,
  SGSDK_Core, SGSDK_Font, SGSDK_Audio, SGSDK_Graphics, SGSDK_Input, SGSDK_Physics,
  SGSDK_KeyCodes;
 
  //The main procedure that controlls the game logic.
  //
  // SIDE EFFECTS:
  // - Creates the screen, and displays a message
  procedure Main();
  begin
    OpenGraphicsWindow('My Game', 640, 480);
    
    LoadResources();
      
    repeat
      ProcessEvents();
  
      //Draw screen
	  ClearScreen(ColorBlack);
 
      FillRectangle(ColorRed, 20, 200, 200, 100);
      FillRectangle(ColorGreen, 220, 200, 200, 100);
      FillRectangle(ColorBlue, 420, 200, 200, 100);
 
      DrawText('Hello World', ColorRed, GameFont('Courier'), 20, 310);
      DrawText('Hello World', ColorGreen, GameFont('Courier'), 220, 310);
      DrawText('Hello World', ColorBlue, GameFont('Courier'), 420, 310);
 
 	  DrawFramerate(0, 0, GameFont('Courier'));
      DrawText('Hello World', ColorWhite, GameFont('ArialLarge'), 50, 50);
  
      RefreshScreen();
    until WindowCloseRequested();
    
    FreeResources();
  end;
 
end.

The purpose of this code is to create a starting point for your project. You can run this program by executing the application from the bin directory of your project. Navigate there with your file explorer and double click the application to execute it. Alternatively you can run it from the command line. After you have had a look close the window.

You can basically read what it is doing
//comments are in grey, and start with a two forward slashes at the start like this sentence 

See if you can find the parts of the code that are doing the following things:

  • Loading all the resources you need for the game
  • Opening up a blank screen 640 pixels wide (x axis) by 480 tall (y axis). You should change this to 800, 600 for this project - see picture below
  • Starting a Loop, inside which it does the following:
    • Clearing the window
    • Drawing 3 filled rectangles, setting their sizes and different colours width height and position
    • Putting the game's "Frame rate" up on the screen in the top right hand corner
    • Writing the words "Hello World" 3 times in different colours below the rectangles
    • Writing the words "Hello World" once at the top in large letters
  • Telling the loop to stop when someone closes the window
Screen Layout

Now you do this...

To help your understanding of what is going on in this code do the following:

  • Change it to an 800 by 600 window
  • Change the big "Hello World" to your name
  • Move the Red Rectangle so it is in the bottom right hand corner
  • Make the Red Rectangle twice as big

And that is it! You have completed your "Hello World" next we look at adding an image.