Game Programming at scriptedfun

Game Programming for Beginners: Video Tutorials, Source Code, and Articles

Subscribe via e-mail!

Enter your email address:

Delivered by FeedBurner

Transcript 3 – Arinoid – The Paddle

Hello and welcome to screencast number 3. Today, we will continue building our game Arinoid by adding a paddle. We will use the paddle to deflect the ball, and we want to be able to control it using the mouse.

paddle image in the sprite sheet

The paddle image is contained in our sprite sheet. However, the image spans two tiles, which means that we cannot just extract the paddle image from the sprite sheet and use it as is. We have to get rid of the boundary at the middle. We can do this by extracting the left and right halfs of the paddle image, and joining them together. We will do these things without resorting to manual image editing. Since we want to be able to use the sprite sheet without manually editing it, we will do all the image manipulations within our program.

[Read the rest of this entry…]

Video Tutorial 3 – Arinoid – The Paddle

Finally! Today, we will be adding the first sprite in our game, the paddle, which is controlled using the mouse. At this point, we will be able to benefit from the setting-up that we have done in the first two screencasts.

paddle sprite

[Read the rest of this entry…]

Transcript 2 – Using Sprite Sheets and Drawing the Background

Hello again and welcome to screencast number 2. Today, we are going to look into using sprite sheets and drawing the background for the game Arinoid.
arinoid sprite sheet
The graphics for Arinoid were all taken from a single bitmap file called a sprite sheet. We have to find a way to extract the graphics that we need from this file and use them in our games.

[Read the rest of this entry…]

Video Tutorial 2 – Using Sprite Sheets and Drawing the Background

To run the code for this screencast, you will need to have a data subdirectory containing the Arinoid sprite sheet file. You can easily fulfill this requirement by downloading the arinoid source from the post on Arinoid. Also, this will be needed for most, if not all, of the upcoming screencasts.

tiled background

[Read the rest of this entry…]

Transcript 1 – Making a Barebones Pygame Program

When I posted the second screencast, I mentioned that I haven’t been able to post this transcript yet. Thanks to the Post Timestamp feature of WordPress, I was able to position this entry earlier than the said screencast, even though I posted that first :). For the record, this was posted later than the second screencast ;).
The code highlighting was made possible by the Code Snippet WordPress Plugin.
I would like to know what you think about the transcripts :)! Please leave a comment on the site so that I would know how this site can better serve your needs. The transcript for the second screencast should follow shortly ;).

[Read the rest of this entry…]

Video Tutorial 1 – Making a Barebones Pygame Program

I think that it could be easier to learn game programming through a video tutorial – you’re actually able to see the code unfold before your eyes, with audio explanations – rather than through reading – although I think that reading is great and won’t be replaced anytime soon. Probably 90% of what I know about programming I learned through reading.

barebones pygame program

[Read the rest of this entry…]

Arinoid – an Arkanoid clone

For our first game, let’s try to write an Arkanoid clone. The graphics in the game were taken from the freely available Spritelib by Ari Feldman.

arinoid screenshot

[Read the rest of this entry…]

Torque X Notes

Torque X Notes at

Version 0.1 – June 13, 2007

This is a very rough guide/outline that I put together for my personal use to help me understand TGBX better and faster – you may or may not find this useful :). I don’t claim to have come up with all of this – most, if not all of this material, is derived from:

This document assumes knowledge of the contents of the first two sources, and actually depends heavily on them :). It’s basically just the Blaster/Microbes tutorials minus specifics. I thought that it might be helpful to lay out the things described there more generally.

I’d love to hear what you think about this document – feel free to leave a comment ;).

Thank you so much to GarageGames and Microsoft for this amazing product, and to the GarageGames and XNA communities for all the help that you continue to give! 😀

How To Use This Document

Personally, I like everything on one big page, and if there’s anything I need, I just hit Ctrl+F from within Firefox then type in the keyword I’m looking for, then press Ctrl+G as needed. Very primitive, but it works for me ;).

GUI Matters

First Steps
  1. Make a new project using the StarterGame template in Visual C# Express, and build the solution.
  2. Start TGBX and load StarterGame.txproj.
  3. Save the scene as sceneNameHere.txscene.
  4. Materials may be imported simply by dragging images into TGBX.
Setting-up Animated Sprites
  1. Click on the Animation check box.
  2. Adjust the cell fields as appropriate.
  3. Click Create a new Animation.
  4. Click Add all frames from the image (green button)
  5. Change the Cycle Animation checkbox as appropriate.
  6. Adjust the Frames Per Second.
  7. Save the animation.
Defining Object Types
  1. Make sure that no objects are selected in the scene.
  2. Go to the Edit Pane‘s Scene Data tab.
  3. Type a name in the Object Types text box, then click the green button to make it register.
Defining Templates
General Directions
  1. From the Create pane, drag the material for the template into the scene (may be outside the camera area if you don’t want it to appear immediately at the start of the game).
  2. You may manipulate the material as needed using the Edit Pane‘s Scene Object tab.
  3. Give the template a name using the Scripting tab of the Edit pane.
  4. You may mark the template using one of the object types you have defined.
  5. Check the Template box in the Scripting tab.
  6. You may change the template’s collision detection polygon or its world limits.
  7. If appropriate, enable/disable Pool With Components
  8. You may add/adjust the components from the Edit pane. Items of particular interest:
    • WorldLimitResolveCollision in T2DWorldLimitComponent
    • CollidesWith in T2DCollisionComponent
For animations

You may want to check the Remove On Finished checkbox.

C# Matters

In Game.cs…

…you may want to add the following piece of code:

static public Game GameInstance
	get { return _myGame; }
Putting Scene Objects in Variables
  1. In the region Private, protected, internal fields, add:
    T2DSceneObject _gameObject;
  2. In the region Public properties, operators, constants, and enums, add:
    public T2DSceneObject GameObject
    	get { return _gameObject; }
    	set { _gameObject = value; }
  3. Typically, one would access _gameObject from a method within the region Public Methods, whose contents are typically called from the Private, protected, internal methods region’s BeginRun method, where, VERY simply speaking, game code execution starts. Usage of _gameObject would probably work like this:
    public void SomePublicMethod()
    	// look up the template for the object;
    	// here, SceneObjectTemplate would correspond to the name we gave to the template earlier in TGBX
    	T2DSceneObject sceneObjectTemplate = TorqueObjectDatabase.Instance.FindObject("SceneObjectTemplate");
    	if (sceneObjectTemplate != null)
    		// clone the template to create the object
    		_gameObject = (T2DSceneObject)sceneObjectTemplate.Clone(); 
    		// process _gameObject further here...
    		// register our object with the TorqueObjectDatabase

    Alternatively, one can also write (NOT TESTED YET and COULD BE INCORRECT):

    public void SomePublicMethod()
    	// clone the template to create the object
    	_gameObject = TorqueObjectDatabase.Instance.CloneObject("sceneObjectTemplate");
    	// process _gameObject further here...
    	// register our object with the TorqueObjectDatabase

    Note that sceneObjectTemplate.Clone() returns an Object object, so it needs a cast, while TorqueObjectDatabase.Instance.CloneObject returns a T2DSceneObject.

Manipulating Scene Objects from Code

For this, the Torque X API.chm help file is your best source of information. Basically, this will allow you to do in code the changes you make to scene objects within the TGBX editor.

Setting a scene object’s position

Within a method (maybe within // process _gameObject further here...),

_gameObject.Position = new Microsoft.Xna.Framework.Vector2(desiredX, desiredY);


_gameObject.Position = SceneObject.Position;

where SceneObject refers to the scene object to which the component is attached to.

Setting a scene object’s layer
_gameObject.Layer = SceneObject.Layer + n;	// n an integer
Setting a scene object’s rotation
_gameObject.Rotation = 180.0f;
Enabling/disabling collisions
_gameObject.CollisionsEnabled = true;
_gameObject.Collision.CollidesWith = TorqueObjectDatabase.Instance.GetObjectType("objectType");
_gameObject.Collision.ResolveCollision = T2DPhysicsComponent.KillCollision; 
_gameObject.Physics.Velocity = new Vector2(0.0f, -80.0f); 
_gameObject.Physics.VelocityY = TorqueUtil.GetRandomFloat(5.0f, 15.0f);
Loading Levels

Within the BeginRun method in the region Private, protected, internal methods in Game.cs:


This line may be followed by Public Methods that initialize the level (probably concerning Scene Objects).

Adding Components
  1. Add a new T2DComponent called ComponentNameHere.cs from Game Studio Express.
  2. Add fields such as float _fieldName; relevant to the component in the region Private, protected, internal fields.
  3. Add methods in the region Private, protected, internal methods.
  4. If you want your component to accept input, you may want to add code similar to the following in the Private, protected, internal methods region, in the _OnRegister method, before the return true statement:
    	InputMap inputMap = PlayerManager.Instance.GetPlayer(0).InputMap; 
    	int gamepadId = InputManager.Instance.FindDevice("gamepad0");
    	if (gamepadId >= 0)
    		inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.A, MoveMapTypes.Button, 0);
    	int keyboardId = InputManager.Instance.FindDevice("keyboard");
    	if (keyboardId >= 0)
    		inputMap.BindMove(keyboardId, (int)Keys.Space, MoveMapTypes.Button, 0);
    	// tell the engine to call our ProcessTick method every clock tick.
    	ProcessList.Instance.AddTickCallback(Owner, this); 

    Again, I highly recommend that you refer to the Torque X API.chm help file – it will really help in understanding the inputMap.BindMove method.

  5. To make the game to actually react to the user input, you will need to add the following to the ProcessTick method in the Public Methods region:
    	if (move != null && move.Buttons[0].Pushed == true)
  6. We can make properties for the fields defined earlier, and make them editable in TGBX using code similar to the following within the Public properties, operators, constants, and enums region:
    	public float FieldName
    		get { return _fieldName; }
    		set { _fieldName = value; }
    	public float AnotherField
    		get { return _anotherField; }
    		set { _anotherField = value; }
  7. In order to make templates using this component clonable, we will need to modify the CopyTo method in the Public Methods region as follows:
    	public override void CopyTo(TorqueComponent obj)
    		ComponentNameHere obj2 = (ComponentNameHere)obj;
    		obj2.FieldName = FieldName;
    		obj2.AnotherField = AnotherField;

    A more complete discussion on this matter is available in the Torque X Forums.

Working Within Components
  1. To access public properties defined in Game.cs from within a component, you may use Game.GameInstance. For example, if the T2DSceneObject GameObject property is defined in Game.cs, you may use the following code:
    float GameObjectX = Game.GameInstance.GameObject.Position.X;
  2. To access the scene object to which the component is attached to, you may use SceneObject.

Subpixel Rendering for Pygame

Will McGugan has just posted some Pygame code that will allow subpixel rendering, which should allow Pygame developers to render smooth looking graphics using software rendering only. I haven’t tried the code yet, although it says in the post that the rendering should be as fast as ordinary blits, but more memory will be taken up – I think that the trade off is more than worth it.

I learned about subpixel rendering only very recently after playing the amazing physics-based game BreakQuest, which utilizes the technique to allow great-looking particle effects to be implemented through software rendering. BreakQuest’s author Fèlix Casablancas explains the concept of subpixel rendering very well in a forum thread on his website, and I think it’s a good read for anyone who wants a clear explanation of the concept of subpixel rendering.

Will has other Pygame stuff on his website, and I’m sure there’s a lot more on the way – he’s the author of an upcoming Pygame book from Apress :). I’m excited already!

David Perry’s Project Top Secret

I’m trying to beat a deadline, and need the space to submit an entry, so I made this entry for me to be able to upload something.

I’m sorry if that previous paragraph didn’t make sense – I’ll add details later. 😀

Microsoft XNA Game Studio Contest

Ready to make your dream of creating video games come true? The Dream-Build-Play Challenge is your chance! Design and build an original game for Windows XP SP2 or Xbox 360™ using XNA Game Studio Express, a new tool from Microsoft®. Besides worldwide fame and recognition, your entry could also win you some fantastic prizes.

I’ve talked about XNA Game Studio Express before, and here’s another reason for you to consider this game development option – you can learn game programming, and possibly win something at the same time :). The first prize winner will get:

  • An invitation to enter into an Xbox Live™ Arcade Publishing Contract on terms and conditions applicable to such offer
  • $10,000 USD
  • Alienware Aurora® 7500 desktop system with AMD Athlon™ 64 FX-62 Dual Core Processor, courtesy of Alienware PC and AMD
  • Retail copy of Windows Vista Ultimate operating system
  • Autographed Xbox 360 Premium SKU retail console
  • 2-year subscription to the XNA Creators Club
  • 25 four-month subscription tokens to the XNA Creators Club, to share your masterpiece with friends and family
  • Choice of Softimage®|XSI® Advanced 6.0, Autodesk® 3ds Max® 9, or Autodesk® Maya® Complete 8.5

The runner-up prizes are quite attractive as well! Just like in the Intel contest, GarageGames plays a special role here with their product Torque X.

Entries are due on July 2, so that should give you plenty of time to learn how to code games with XNA. If you’re looking for a project to work on, this should serve as an excellent motivation! 😀