Last code of demo in progress.
http://www.speedyshare.com/195238708.html
- Added terrain created with World Editor
- Create and destroy game structures copy using memory container.
- Added small hud.
- Improved code
--------------------------------------------
Creating terrain in .mshg file format (support some materials applied): First, we create world scenery from World Editor, and after, build the world created (menu Main-->Build). If the scenery created is made up of several areas or fields, in the build process will be generated some .mshg files. For this reason, I've created a scenario with a single area.
The World Editor detect materials in mtrl work folder, in this case LocalData\mtrl, but also, I had to copy the materials applied in the mesh (.mshg) in the engine Data/mtrl folder, to use the .mshg file in the program.
---------------------------------------------
The demo in progress is small code formed by four structures that contain the game elements. I think it is not very complicated, and will help anyone who wants to begin programming in C++ using a professional tool like Esenthel.
---------------------------------------------
Parts of code:
Code:
// Header Files
#include ....
// Define Macro-names
#define ...
// Global Variables
.....
// Structures or Class DECLARATION. You can create structure copies in this process (static memory)
.....
// Create structure copies (static memory) or Create Memory Container of structures (dynamic memory)
.....
// General Functions.
.....
// Structures or Class DEFINITION
.....
// Functions Esenthel Engine
// void InitPre() { ... }
// Bool Init () { Here, make construction of structures or class copies that used static memory)}
// void Shut {}
// Bool Main { Here, Create and destroy structures o class copies that used dynamic memory (memory container) }
// void Draw() {}
To create memory container, I have used Memx memory container. Memx features:
ADVANTAGES:
fast (slightly slower than Memb)
low memory fragmentation
fast access to i-th element
immediate calculation of elements index
removing any elements is simple
removing elements doesn't change memory address of other elements
DISADVANTAGES:
manual inserting elements before others isn't implemented
Declaration memory container Memx:
Code:
Memx <variable-type> NameContainer;
Create new node with New(). Also, we added construction function name (in this case active()):
Code:
NameContainer.New().active();
Update container and destroy node if is necessary. We used REPA to run all nodes and update function (in this case actualize()). We added condition if Inactive boolean variable is true, to destroy node.
Code:
REPA (NameContainer) {
NameContainer[i].actualize();
if (NameContainer[i].Inactive) NameContainer.removeValid(i);
}
Draw in Render function that use Render Modes, using draw function (in this case draw())
Code:
REPA (NameContainer) {
NameContainer[i].draw();
}
Also, I added some code lines in Shut engine function
Code:
NameContainer.clear();
I have not used virtual functions because I have to run actualize() function individually to can destroy a node in memory container, or some elements have to render in several render modes.
--------------------------------------------------------------------------------------
To calculate the enemy shoot movement, use:
Vec dir = ( Vec Objetive position - Vec Initial position ) * Tm.d() * _SPEED_ / Dist ( Vec Objetive position , Vec Initial position )
where _SPEED_ is a macro-name that represent speed value. 'Dist' is a engine function that calculate the distance between two points. This is the best formula I know to calculate the displacement of the object (in this case enemy shoot). After, we apply the dir vector to enemy shoot matrix using move.
Code:
matrixEnemyShoot.move(dir);
--------------------------------------------------------------------------------------
The player's energy bar is formed by two images. These images were converted from .png to .gfx using Converter tool of Esenthel. Converter tool use some pixel format:
DXT3: (compressed, 4-bit nonpremultiplied alpha)
DXT5: (compressed, interpolated nonpremultiplied alpha)
A8R8G8B8: (32 bits per pixel, A:8, R:8, G:8, B:8)
X8R8G8B8: (32 bits per pixel, A:x, R:8, G:8, B:8)
A8: (8 bits per pixel, alpha:8)
L8: (8 bits per pixel, luminance:8)
A8L8: (16 bits per pixel, A:8, L:8)
More info:
http://msdn.microsoft.com/en-us/library/bb322854.aspx
Mipmap parameter specifies the way of saving resulting files: either with mipmap levels or without them
If mipmap parameter value is "yes", the sizes of saved images must be equal to the power of two (128, 256, 512, 1024 etc.).
The mipmap option is set initially in Converter tool. To convert image in gfx format, I have disabled this option and selected A8R8G8B8 pixel format that save the image together alpha channel. You must drag and drop image file from windows explorer to Converter tool window. Then, you can render the image from RM_BLEND mode.
-----------------------------------------------------------
Incidence:
-The player's energy bar is shining at the beginning of the game, but after an explosion left shining.
-Use
Code:
gfxBar2.drawPart(-0.9f,-0.9f,0.8f*player.Life/100,0.09f,0,0,1,1);
to draw part of player's energy bar, but the drawPart function make a scale.
- Is possible create a world continuos loop?
Regards