mjbWorld program - Building a game

This a is a tutorial about how to build a simple 'asterids' type game using the program.

More information about this.

First start up the program (if you have not loaded the program go here)

The game starts with two large 'rocks' moving slowly around the screen. If you were building a realistic game you would probably want to build a rock shape using an Indexed Face Set, but since the aim here is just to demonstrate the principles, I have used a simple box shape.

Since we require a variable number of these, then we will put them under a 'multiple' node.

Press '+' button to bring up an 'add view' window.

Drag 'multipleBean' from 'add view' to 'tree view'

In the properties view set initialInstances to 2 and maximumInstances to 10.

set the name of this node to 'large'.

Create a box under the multiple bean. The easyest way to do this is to use the 'quick shape view' (under the view menu). Drag boxBean (or whatever shape you wan) from the Quick Shape view to the 'large' node in the tree view.

Set the parameters of the shape to suitable values.

Under the TransformGroup add a kinematics node. Set its randomMinMax parameter to (0.0 , 0.01).

This will cause each of the 2 instances to move in different, random directions.

Also undet the TransformGroup node, add collisionDetect and collisionAction nodes.

Set the parameters of the collisionAction bean to the following values:

The collideWith parameter is set to 'bullet' (set it by hitting the edit button.

Also add a constraint node with the following values. This makes sure it moves around in the viewable area.

Create a similar structure for a medium sized rock. The easyest way to do this is to select the 'large' node and then do a duplicate (from the edit menu).

And again for a small rock.

Now create a space ship, only one of these required so it does not need to be under a multiple node. But we want the space ship to be able to fire bullets or missiles of some sort. So we can create a multiple node under the ship TransformGroup. Set initialInstances and maximumInstances to 20.

Add a suitable shape for the bullet and change the name of the transformGroup node to bullet.

Add kinematics and contraints nodes under the transform group.

We want the bullets to appear to be continously fireing, to do this set the constraint bean as follows. The restart option causes the bullets to start again after they reach a the boundary.

To allow us to fire the bullets add a touch sensor to the ship.

Use a route node to link the touchSensor to the enable property of the kinematics node.

To display a score use a score node, put this under a transform node and set the scale to (0.002,0.002,0.002) and position to (0.25,0.04,0.8) to put it in the top right of the screen.

Add a route node to link the count parameter of the collisionAction of the large rock to the count parameter of the score node.

metadata block
see also:


Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover The Art of 3-D Computer Animation and Effects. This is a nice glossy colour book, it is for those starting out using 3D graphics programs rather than those who write them.

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.


This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2018 Martin John Baker - All rights reserved - privacy policy.