back to the main tutorial guide page .
Reference: This is the third tutorial on how to work with the GTCS1Lib library. It is assumed you have read and understand the previous two tutorials:
Goals : This tutorial concentrates on illustrating working with PrimitiveSet for controlling the visibility (membership with AutoDrawSet) of any related set of primitives, and on the Random number utilities:
1. Obtain the example code
Download
and unzip the zip file and you will see an ExampleProgram
folder. Open the ExampleProgram folder, the
EXE folder contains the compiled program and you can double click on the .sln file to work with the source code.
If
you double click and run the executable program, you will observe:
|
This
application is almost identical to that from the second tutorial, except two
important points:
In
this tutorial, we will examine the details of implementing these functionality.
2. The Source Code Files/Structure
Take a look at the ExampleProgram folder that you have unzipped and you will see a structure identical to that of previous tutorials. Once again, you can double click on the *.sln file to launch the IDE, we will concentrate on the Game1.cs file where all the relevant source code are located.
3. Examine Game1.cs Structure:
When you open the Game1.cs file in the IDE, you will see source code
structure that is very similar to that of the second tutorial:
#region Reference
to libraries public class Game1 : XNACS1Base { #region Instance Variables protected override void InitializeWorld() protected override void UpdateWorld()
} |
Once again, we will examine each of : Instance Variables, InitializeWorld() , and UpdateWorld() in details and understand how to implement the behaviors we have observed.
4. Examine Instance Variables of Game1.cs
When you expand the Instance Variable region, you will observe:
#region Instance
Variables |
The five sets of instance variables: A to E where variable sets A to D are identical to previous tutorial. E: ( m_VisibleSet ) is a logical set that lets us insert related Primitives and control the visibility of the Primitives as a set.
5. Examine InitializeWorld() function of Game1.cs
The InitializeWorld() function is
once again very similar to previous tutorial:
protected override void InitializeWorld()
{ |
At label E , after allocating the memory for the m_VisibleSet , we inserted the RightThumbCircle and the RotatingLadder to be members of the m_VisibleSet , and record the fact that current the m_VisibleSet is visible by setting m_SetIsVisibl e to true.
6. Examine UpdateWorld() function of Game1.cs
Now in the UpdateWorld() function, we control the
visibility of the m_VisibleSet and the
speed of the soccer ball after collision:
protected override void UpdateWorld() { #region A. Update the Rotating ladder #region C. ... #region D. ... # region E. toggle VisibleSet
by the X-Button
# region F. Collide the soccer with the rotating
ladder EchoToTopStatus(...); |
Project
home page: The
Game-Themed Introductory Programming Project.
Kelvin Sung |
Michael Panitz |
|
This work is supported in part by a grant from Microsoft
Research under the Computer Gaming Curriculum in Computer Science RFP, Award
Number 15871 and 16531. |
|