Hello everyone and welcome to my world. This is my first entry on my journal. I do want to talk about a few things I am working on. Lets start.
Game Engine Development
Well, I have been working on a 2D DirectX game engine. So far it is looking pretty good. I did have one problem with it. I created the engine in a C++ class and that made it difficult for many reasons to actually use the engine.
My goal in this engine is to have the user of the engine not have to worry about DirectX code. All they would have to do is just include the header file of the game engine and start coding. I remade the engine so it wouldn't use C++ classes. Instead it uses C style functions such as the #define and many other things. I have not released the engine to the public yet, because I am still adding things to it. I am thinking, though, about putting up some articles on GameDev.net on how I created the engine. I think that would be pretty cool. Let me now show you a bit of how easy it is to use this game engine of mine.
First, after you added the game engine files to your project (I used Visual C++ .Net 2003 for my projects), you add a source file and include the header "lage.h" at the top of the source file. There are three main functions you have to use here:
- void GameInit()
- void GameLoop()
- void GameEnd()
The GameInit() function is for when the game or program first starts. It is only called once. In here is where you initialize the Game Engine and load up your resources, such as sprites and backgrounds (more on that later).
The GameLoop() function is where the meat of your code goes. This function is constantly called.
The GameEnd() function is where you release the resources you loaded up in the GameInit() function. I made this process especially easy so I know I released my images right.
Game Initialization and Resource loading
To initialize DirectX and set up the window, you would use this function I created in the GameInit() function to do that:
int InitD3D(int width, int height, bool fullscreen);
This function takes as parameters the width and the height of the window. The last parameter is a boolean value determining whether the application is run full-screen or windowed. "true" means fullscreen and "false" means windowed. I believe you would be able to run this application with only the InitD3D() function. All you would see is a black screen, but it is a DirectX app.
To load images, I defined two DirectX variables and gave them a new name. For instance, LPDIRECT3DSURFACE9 can be called by the variable name SURFACE. The second variable was LPDIRECT3DTEXTURE9, but I later defined it as SPRITE. You should declare the image variables globally. Here is an example:
SURFACE will mainly be used for just backgrounds. The SPRITE though is obviously going to be used for sprites with support for transparency.
In the GameInit() function, here is an example of how you would load up a SURFACE and a SPRITE:
background = LoadBmp("background.bmp");
sprite1 = LoadSprite("sprite1.bmp",255,0,255);
The LoadBmp() function is only used for surfaces and takes as a parameter the filename. The LoadSprite() function is only used to load sprites and takes as parameters the filename and the RGB color value for transparency. In the example above I used RGB(255, 0, 255) which is a sort of pink color for transparency.
Well, my hands are getting tired now. Most likely in the next post I will show you how I would draw the sprites and the background. I also want to put updates on my game projects here. So till next time, have an excellent day. Bye bye.