Graphics Programs Reference
In-Depth Information
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// create the game objects
// set the number of objects to be created
var numberOfObjects:Number = 31;
// create the cones and cacti and place them in 3D space
for (var i:Number = 0; i < numberOfObjects; i++)
{
if ( i < numberOfObjects - 1)
{
duplicateMovieClip(object_mc,"object"+i,i);
thisObj = this["object"+i];
thisObj.id = i
thisObj.gotoAndStop(Math.round(Math.random()+1));
placeObj(thisObj,i);
} else
{ duplicateMovieClip(finish_mc,"object"+i,i);
this["object"+i].x = 0;
this["object"+i].y = -250;
this["object"+i].z = 30000;
this["object"+i].id = i;
}
}
previously with the Poser puppies. As a last object in 3D space, we added the finish line
and placed it way back in the z-direction. For each object, an id number is assigned.
This will be used to test for crossing the finish line.
This displayObj() function is pretty standard fare with a few new additions. A blur
filter is applied to objects far away, again replicating the Poser puppies. Some additional
coding was used to check whether the z-value of the object is too close to the player.
There are two cases to consider. If we are too close to an object and that object is the
finish line, then the game is over.
On the other hand, if the object is not the finish line, then the object is given new
coordinates in the placeObj() function, and we check to see whether the x-value of
the object is close to the viewer. If it is, then we have run over an obstacle. The score
is increased by 1, and the camspeed of the car is reduced. Since the speed is reduced,
the angle of rotation of the needle on the speedometer is also reduced.
Search WWH ::




Custom Search