back to the main tutorial guide page .
Reference: This is the first tutorial on how to work with the GTCS1Lib library. It is assumed you have some working knowledge of C# (or Java, or C++) and understand the concepts of "objects" in an object-oriented language.
Goals : The following are the important points to note from this tutorial:
you
should be able to follow the first two tutorials and begin programming simple
game-like applications with the library.
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:
|
2. The Source Code Files/Structure
Take a look at the ExampleProgram folder that you have unzipped and you will see:
Folders/Files
|
Purposes
|
ClassExample.csproj |
project description file. We will not need to edit or change this
file. |
Game1.cs
|
This
is is the file that contains the source code to our
project. This document will only refer to the source code in from this file. |
Program.cs |
A
dummy container. We do not need to be concerned with the content of this
file. |
Icon.ico
|
Image
of the top-left corner of the title bar of the application window and when
the application window is iconized. |
Properties
/AssemblyInfo.cs |
Contains
miscellaneous information on the application. We will not work with this
file. |
Content/Resources/Fonts/
Arial.spritefont |
The
font used by our application. This folder and the font file must exist
for all of the XGCS1Lib projects. |
You
will also see the MonoGameLib
folder, this folder contains all of the MonoGame
support files (for PC), and XGCS1Lib DLL file. This folder is a necessary part
of your source code system, without which, your project will not compile!
3. Content Build Action:
In order to ensure assets (fonts, images, audio files) get compiled and copied over to the execution area, it is essential that you set the build action for each asset files accordingly. For example, for the font file, in the Solution Explore, open the Content/Resources/Fonts folders, and bring up the properties page of the Arial.xnb file:
|
Notice that:
This is an absolutely
essential step to go through after adding
any new asset (image, audio, etc.) into the project!! Without this step, none
of the assets will show up in your game!
4. Examine Game1.cs:
Now double click on the Game1.cs file in the SolutionExplorer , and you will see this structure:
#region Reference to system libraries
// Label A: Reference to GTCS1Lib namespace GTCS1Lib_Start
{
// Label C: InitializeWorld()
function
// Label D: UpdateWorld()
function
} |
5. The InitializeWorld() function:
If
we examine the InitializeWorld() function,
this is what we will observe:
// Label C: InitializeWorld() function
// 1. Set the coordinate system to work with
// 2. Set the background color |
Three
tasks are accomplished:
|
pos = (World.WorldMax
+ World.WorldMin)
/ 2.0f;
XNACS1Circle
center = new XNACS1Circle(pos, 1.0f);
in
this way, the first circle being defined is located at the x- and y-middle of
the application window and has a radius of 1.0f. Recall that the coordinate
system we define has a width of 15 unites. Notice that the radius of the circle
occupies 1/15 of the width of the application window.
pos = new Vector2(0, 0);
XNACS1Circle
LowerLeft = new XNACS1Circle(pos, 1.0f);
is
centered at (0,0) position with radius of 1.0f. Given that the coordinate
system we defined has lower-left corner of (-1, -1), we know the
circumference of this second circle will touch the lower and left boundaries of
the application window. The second circle created is the one located at the
lower left corner.
pos = World. WorldMax;
XNACS1Circle
UpperRight = new XNACS1Circle(pos, 1.0f);
is
centered at WorldMax , or
top-left corner of the application window with radius of 1.0f. This is the
top-left quarter-circle where the center is the top-left corner with
three-quarter of this circle outside of the application window.
6. The UpdateWorld() function:
If
we examine the InitializeWorld() function,
this is what we will observe:
// Label D: UpdateWorld() function
EchoToTopStatus("Top
Status: " + World.WorldMax);
|
Notice
that:
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. |
|