Advertisement
2002ASP Internet/ HTML #7606

Full Tutorial #1 for the MasterX SDK 1 (found in PSC)

Heres the first tutorial on how to manipulate the MasterX objects to create a 2d video game. Sorry about the formating and spelling and grammer, I didnt spell check was just typed off top of my head. :)

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
<body bgcolor="#000000">
<font face="FixedSys" size="2" color="#BD0000">
<center><table width=450>
<tr>
<font color="#FFFFFF"> Tutorial #1 - Lecture </font><br>
<img src="http://www.lostsidedead.com/gameprog/bar.jpg"><br>
Welcome to the MasterX SDK tutorial page! My name is Jared
and I wrote this , to create a simplified form of writing
2D video games utilizing the DirectX API. The whole purpose
of this is so people who dont know windows programming or
arent to familar with C++ , will have the ability to write
some neat programs. Its a large leap from writing software
in BASIC or using C++ Console app's to
to a game. What I mean by this is, windows
software is event driven programming, things only occour
at different events, and you just put code in certin places.
Video game programming is the complete opposite! Wheter or
not the user is doing anything the program is still going
and is always changing. This requires a much different 
approach when actualy writing the software. If your worrying
about it being hard well dont worry. Nothing in life is easy
or hard, it just takes time and patience. I think that anyone
has the ability to create awesome software, its just a matter
of putting yourself into the situation to let it happen. What
I am hoping to do with this SDK, is create a way for you to
slowly move into the realm of video game programming. It really
kicks. you can make some tight stuff. All I ever wanted
since I was like 3-5 years old was to write video games. Haha
right now on my wall I got a thing from when I was in elementry
school, and it has a question. It says: "What are your favorite subjects"
I answered. "Science, language arts, and math" Another question, 
what is the hardest thing for you to do. I put "Spelling". 
and the final question is, what do you want to do when you grow up.
I responded a "Computer Programmer". Well its 12 years later,
and I have just about fully grasped the languages, and methods
of using them. It is the most accomplishing then I ever have
done and I LOVE it. I am not some super geek with glasses and
a pocket protector. I am just a normal person, ANYONE can do it,
and on that note lets begin:<br><br>
<font color="#FFFFFF"> MasterX Code Structure and Implementation</font><br>
<img src="http://www.lostsidedead.com/gameprog/bar.jpg"><br>
Hopefully you . familar with programming in dos, and possibly some
windows background. If not its not totaly nessicary as long as you
have a good responsible understanding of the C++ programming language
and its use. If you dont first, I really honestly recommend that you
learn C++ and have a good understanding of it before you try to write
anything realistic. Just remember there is a difference between writing
something to do a task, and understanding the underlying causes that
caused that task to occour. If you understand how it works, then you
can use those same concepts, and expand them to create whatever you
so please. Alot of people get upset and confused because they try
to memorize a whole api library in one day, or try to think that
if the programming language just dosent click it one second then
they . a failure and will never obtain the levels of programming
mastery they desire. This enterily untrue, and is you setting your
self up into a negative loop to cause you to fail. Nothing is hard
or easy, just pratice. Pratice makes perfect. I didnt learn 7 computer
languages in 5 minutes. It took years of hard work and study. It is the
same from you. You must give all your effort to produce the truly
amazing new and enriching software you so desire. now when writing a
program you have your entry point. the main() function. When using
the MasterX SDK, you dont have a main(), you use a MasterMain as your entry
point. This is were your code begins its execution, and its prototype
is the following:<br><br>
<font color="blue"> int _stdcall </font> MasterMain(HINSTANCE hInst,LPSTR line);<br><br>
<br> The Parameter List, holds the folllwing values HINSTANCE & LPSTR . some of microsofts evil poorly named variable types, standing for the Instance of the application and a string. (Note for you win32 programmers, I purposely dont use the Microsoft typedefs because I think that there naming and that whole notiation is fairly illogical. I think that you should call something what it is. A windows handle WINDOWHANDLE , so what if it requires more typing, when you read it its pretty much self explanatory. If you cant type fast enough I suggest you learn to type first)<br><br> Now that we now how the program enters, we have
to understand that the 2 more functions that are required within are skeleton. These
functions are callback functions.. Basicly what that means, is that you pass a pointer
to them , and they are called when they are nessicary. These two functions are
the Window Message proccess, and the frame update MasterX, encapuslates all the Microsoft Windows API stuff, and gives you a way to directly have access to both to the
DirectX COM objects, via easy to use class. If you dont know how to directly
manipulate the DirectX COM objects, there are built in class interfaces to 
help simplifiy this process. the two callback function prototypes are the 
following. <br><br>
<font color="blue">long _stdcall </font> MasterProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);<br><br>
this is the windows message process, it is called when certin events happen it based on the event driven programming model. When certine vents happen like when someone presses a key, or when the program starts a certin WM or Windows Message is sent to the application, and proccesing for that event can occour. I left the microsoft typedefenifed variables within this prototype except for the return. I purposley have it this way because it will help 'ease' you into there variables.The parameter list , does the following. HWND hwnd, stands for the window handle that is currently handling message processing. This can be useful in certin situations. UINT msg, is a unsigned integer (positive integer) that holds the index of the current message. The messages always have a WM_PREFIX WM standing for Windows Message _ as the seperator and PREFIX being the message. WPARAM wParam is a parameter used by some of the messages and can be type casted. LPARAM lParam is a parameter used by some of the messages and can be type casted.<br><br>
<font color="blue"> void </font> update(MASTERSCREEN screen); <br><br>
This is the frame update notification callback function. Basicly what it does is every single time the frame changes or updates you must redraw all the elements that will appear on the screen. You also can call other functions that can induce changes to cause the elements on the screen to change. This is how game progrmaming works. Every single 'update' we put together a new frame, and then it is displayed. The parameter list stands for the following. MASTERSCREEN is just a type defined integer that holds the index of the current screen being displayed. You can create integer constants , or use enumerated constants, to create different names for the screens, and then use a switch statement to differ the flow of instruction. This makes it really easy for you to be able to pick out what screen is currently being shown and do the code for it, and change it with ease.<br><br>
<font color="#FFFFFF"> Putting it all together </font> <br><img src="http://www.lostsidedead.com/gameprog/bar.jpg"><br>
Now that we have a intellectual understanding of the code , and functions involved in creating the base of are application we can put it all together. In recogonition of the long followed tradition the first application will simply say hello world. :) After , you will have an explanation on what this does.<br><br>
<br>
<font color="green">// MasterX Sekelton<br>// MasterX Code/SDK written by Jared Bruni<br>
<br>
// include the masterx header file</font><br>
<font color="blue"> #include </font> "masterx.h" <br><br>
<font color="green">
// function prototypes <br>
</font>
<font color="blue"> void </font> update(MASTERSCREEN screen); <br>
<font color="blue"> long _stdcall </font> MasterProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);<br>
<br> <font color="green"> // Declare the Global MasterX Object </font><br>
MasterXHWND mxhwnd; <br>
<br>
<font color="green"> // Program Entry Point </font><br>
<br>
<font color="blue"> int _stdcall </font> MasterMain(HINSTANCE hInst,LPSTR line)<br>
{<br><br>
<font color="blue">if</font>(mxhwnd.CreateMasterX("MasterX_Skeleton",640,480,COLOR_DEFAULT,MasterProc,hInst,LoadIcon(NULL,IDI_APPLICATION),LoadCursor(NULL,IDC_ARROW)))<br>
	{<br>
		<font color="blue">return</font> mxhwnd.InitLoop(update);<br>
	}<br><br>
	<font color="blue">return</font> 0;<br>
}<br>
<br>
<font color="green"> // Window Message Proccess </font><br>
<font color="blue"> long _stdcall </font> MasterProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)<br>
{<br>
<br>
<font color="blue">switch</font>(msg)<br>
{<br>
<font color="blue">case</font> WM_ACTIVATEAPP:<br>
mxhwnd.activeapp = wParam<br>
<font color="blue"> break; <br>
deafult: return </font> DefWindowProc(hwnd,msg,wParam,lParam);<br>
}<br>
<font color="blue">return</font> 0;<br>
}<br><br>
<br>
<font color="green"> // frame update </font><br>
<font color="blue"> void </font> update(MASTERSCREEN screen) <br>
{<br>
mxhwnd.text.printtext("Hello World!",10,10);<br>
}<br>
<br><br>
<font color="#FFFFFF"> Understanding the code </font><br>
<img src="http://www.lostsidedead.com/gameprog/bar.jpg"> <br>
What happens, is when are program enters, we create the Object
and pick out a few options, such as an icon etc. Then afterword
if this creation was succesful, we initlize a loop. This loop
encapsulates and handles all the page flipping and all the
directX stuff that makes it hard for a newbie to use. After this
initilization occours are application then will continue to update
itself via the update callback function. <br>"mxhwnd.text.printtext("Hello World!",10,10);"<br>Means hey, evey single time we update were going to want
to draw the string hello world at cordinates 10,10. <br><br>
within the MasterProc, it handles the initlization or the appactivate.
This basicly informs the MasterX object, wheter or not are program
currently is active within windows. If it is, then it continues to draw
and call the update call back. If not it halts until once agian we have
focus. <br><br>
Thats it!<br><br>
In english it would be <br>
- Start Program<br>
- Initilize MasterX<br>
- On Activation set it as active<br>
- while active update<br>
<br><br>
<a href="http://www.lostsidedead.com/gameprog/tut1.zip"> 
Click here to download the Visual C++ 6 Project Source </a><br><br>
</tr>
</table>
</center>
</body>
Original Comments (3)
Recovered from Wayback Machine