3D Theory - Games Generation Example

Here are some proposed nodes to exten x3d to allow physics animation.

As an example of how to use this for a games generator, here is a very simple 'asteroids type' game.

It starts off with a few large rocks moving about the screen, when the large rocks hit something then it splits into two medium objects, when the medium object hits something then it splits into two smaller objects. If something hits a small object then it just disappears.

If something hits the ship then the game ends.

 

Listing

#VRML V2.0 utf8
DEF large Multiple {
initialInstances 2
maximumInstances 10
children [
Transform {
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 0.0 1.0 1.0
}
}
geometry
Box {
size 0.2 0.2 0.2
}
}
Kinematics {
randomMinMax 0.0 0.01
enable TRUE
}
CollisionDetect {
}
DEF largeCollision CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew medium
createNumber 2
createAt collide
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -1.0 -1.0 -1.0
maxTranslation 1.0 1.0 1.0
action bounce
}
]
}
]
}
DEF medium Multiple {
maximumInstances 10
children [
Transform {
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 0.6 1.0 0.0
}
}
geometry
Box {
size 0.1 0.1 0.1
}
}
Kinematics {
randomMinMax 0.0 0.01
enable FALSE
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew small
createNumber 2
createAt collide
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -1.0 -1.0 -1.0
maxTranslation 1.0 1.0 1.0
action bounce
}
]
}
]
}
DEF small Multiple {
maximumInstances 10
children [
Transform {
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 1.0 1.0 0.6
}
}
geometry
Box {
size 0.05 0.05 0.05
}
}
Kinematics {
randomMinMax 0.0 0.01
enable FALSE
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -1.0 -1.0 -1.0
maxTranslation 1.0 1.0 1.0
action bounce
}
]
}
]
}
DEF ship Transform {
translation 0.5 0.0 0.0
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 0.0 1.0 1.0
}
}
geometry
Sphere {
radius 0.02
}
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew medium
createNumber 2
createAt collide
counter 0
}
Multiple {
initialInstances 20
maximumInstances 20
children [
DEF bullet Transform {
rotation 0.0 0.0 1.0 0.0
children [
Shape
{
appearance Appearance
{
material Material {
diffuseColor 1.0 1.0 0.0
}
}
geometry
Box {
size 0.01 0.01 0.01
}
}
DEF moveBullet Kinematics {
randomMinMax 0.0 0.04
enable FALSE
}
CollisionDetect {
}
CollisionAction {
collideWith [bullet,
]
actionThis delete
actionOther delete
createNew medium
createNumber 2
createAt collide
counter 0
}
Constraint {
constrainTranslation moveWithinBounds
minTranslation -0.3 -0.3 -0.3
maxTranslation 0.3 0.3 0.3
action restart
}
]
}
]
}
DEF touch TouchSensor
{
isOver FALSE
}
]
}
Transform {
center 0.0 0.0 0.0
scale 0.0020 0.0020 0.0020
translation 0.25 0.04 0.8
children [
DEF score Score
{
}
]
}
ROUTE
largeCollision.count TO score.count
ROUTE
touch.isOver TO moveBullet.enable

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 Game Programming for Teens.

other games programming books

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.

cover Dark Basic Professional Edition - It is better to get this professional edition

cover This is a version of basic designed for building games, for example to rotate a cube you might do the following:
make object cube 1,100
for x=1 to 360
rotate object 1,x,x,0
next x

cover Game Programming with Darkbasic - book for above software

 

other commercial software

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

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