Empty Your Mind Tutorial 3

From SwinGame

This tutorial will teach you how to use the SwinGameSDK to develop a simple danmaku game which looks cool. At the end of this tutorial you should be able to use pascal to implement your own space invaders or scrolling shooter style game which makes use of Vectors, animated Sprites, SoundEffects, and Music.

This page contains a Tutorial. Tutorials are designed to walk you through the development of a small game.
Warning: You must have completed the previous tutorial(s) to go through this tutorial

Contents

Preparing The Background Sprites

Background image in a scrolling shooter game is very important. I want a single seamless image scrolling in the game we will be making. I will be using this image in this tutorial. To create a scrolling effect, we will need to setup two sprites. This will be explained later in this tutorial. The following code should go into your LoadGame procedure. As you can see, we are creating sprites and adding it to the list of images. We will be using this array of bitmap to manage images such as HUD.

game.images[0] := CreateSprite(GameImage('Map'));
game.images[1] := CreateSprite(GameImage('Map'));

This will create two sprites which contains the same image. Do not forget to set the length of the images array.

Note: The map image must be loaded from the Game Resources

Drawing The Background

The following steps must be taken to draw the seamless background.

  • Move the Sprite 1 (10 pixel down)
  • Check if the Sprite 1 has disappeared from the screen
    • If the Sprite 1 is off the screen, reset the position of the Sprite 1 (i.e. set the coordinate to 0, 0)
  • Move the Sprite 2 on the Sprite 1 (therefore, the bottom of the Sprite 2 will attach to the top of the Sprite 1)
  • Draw Sprite 1
  • Draw Sprite 2

The implementation of the steps:

procedure UpdateBackground(var images : Array of Sprite);
const
	BACKGROUNDSPEED = 10;
begin
	//Slide the first background sprite by the background speed
	images[0].yPos := images[0].yPos + BACKGROUNDSPEED;
	//Reset the position of the first background sprite if it has
	//reachead the bottom
	if images[0].yPos >= ScreenHeight() then
		images[0].yPos := 0;
	//Set the second background position so the background is seamless
	images[1].yPos := images[0].yPos - ScreenHeight();
	//Draw background sprites
	DrawSprite(images[0]);
	DrawSprite(images[1]);
end;
Note: This must be called before drawing the ship or you will not see the ship!

Summary

In this tutorial, I have gone through:

  • The algorithm to scroll the background

The current project files can be downloaded from here.

List Of Tutorials

  1. Introduction
  2. Player Ship
  3. Background
  4. Bullet pt.1
  5. Bullet pt.2
  6. Music and SoundEffect
  7. Enemies pt.1
  8. Enemies pt.2
  9. Collision Detection
  10. Further Extensions