About Store Forum Documentation Contact



Post Reply 
DEMO in progress. Code
Author Message
kaito Offline
Member

Post: #1
DEMO in progress. Code
This is the code of the demo that I'm done with ESENTHEL

http://www.mediafire.com/?nzztmhqzndm

Included:
-Programming Code
-Game Resources.
-All .cpp Esenthel tutorials in one .html file.


[Image: captura1c.png]


Tasks:

-Sound.
-HUD
-Intro, menu.
-Create more types of enemies. smile
-...

Any suggestions are welcome.
04-10-2009 05:34 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: DEMO in progress. Code
Quite nice smile

for me the ground is too dark, and you could make the game harder, more enemies, more shooting and action :>
04-10-2009 05:48 PM
Find all posts by this user Quote this message in a reply
kaito Offline
Member

Post: #3
Menu
Regards,

[Image: captura1z.png]

This is the code of menu part of demo in progress. First, you should run the tutorial "Advanced\2 - Animation, Physics, Rendering\Rendering\20 - Volumetric Clouds.cpp", and generate textures and create a file with the parameters selected.:

Code:
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/

// Global Variables

Mesh meshPlane;
Matrix matrixPlane;
CChar8 *ccText[7]={"Player","Difficulty","Start","Easy","Normal","Expert","Insert Name"};
Flt PosicionTexto[6][4]={0.514f,0.357f,0.885f,0.235f,   0.443f,0.058f,0.952f,-0.06f,   0.552f,-0.243f,0.855f,-0.354f,   0.55f,0.357f,0.847f,0.239f,   0.495f,0.056f,0.912f,-0.052f,    0.498f,-0.243f,0.906f,-0.357f};
Str Name;
I8 indiceMenu(0),difficulty(0);

Flt IncX, IncY, IncZ;

// General Functions

void ActualizarRaton(Vec2 pos) {

    switch (indiceMenu) {
                        case 0 : {
                                    FREP(3) if ((pos.x>PosicionTexto[i][0])&&(pos.x<PosicionTexto[i][2])&&(pos.y<PosicionTexto[i][1])&&(pos.y>PosicionTexto[i][3])) indiceMenu=i+1;
                                    break;
                                 }
                        case 2 : {
                                    FREP(3) if ((pos.x>PosicionTexto[i+3][0])&&(pos.x<PosicionTexto[i+3][2])&&(pos.y<PosicionTexto[i+3][1])&&(pos.y>PosicionTexto[i+3][3])) difficulty=i;
                                 }
                        }

}



/******************************************************************************/
void InitPre()
{
   App.name("Volumetric Clouds");
   App.flag=APP_FULL_TOGGLE;
   IOPath("../data");
   PakAdd("engine.pak");

   D.full(true).ambMode(AMB_HIGH4).ambPower(0.3).hdr(true).hdrMaxBright(1.5).hdrExp​osure(0.7);
}
/******************************************************************************/
Bool Init()
{
   Sky.set();
  
   Sun &sun=Suns.New();               // create a new sun in 'Suns' container
   sun.set(*Gfxs("gfx/sky/sun.gfx")); // set image
   sun.pos=!Vec(-20000,-5800,-5000);  // set custom position
   sun.rays.color.set(0.3f,0.2f,0.1f);
   sun.size=0.2f;
   sun.rays.mode=SUN_RAYS_HIGH;

   Clouds.volumetric.set(Gfxs("LocalData/cloud.gfx"),Gfxs("LocalData/detail.gfx"));
   Clouds.volumetric.load("LocalData/volumetric_clouds");

   meshPlane.load("LocalData/Obj/glider/glider.mesh");
   meshPlane.mirrorY()
            .setRender();
   matrixPlane.setScale(1)      
              .move(Vec(-62,76,34))
              .orn.setRotateY(-1.7f)
              .scale(40);

   Cam.matrix.move(Vec(0,65,0));    
   Cam.setAngle(Cam.matrix.pos,1.57f,0.2f,3.1415f).updateVelocities().set();

   IncX=RandomF()/10; IncY=RandomF()/10; IncZ=RandomF()/10;

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
   if(Kb.bp(KB_ESC)) if (indiceMenu==0) {return false;} else {indiceMenu=0; return true;}

   if ((Kb.bp(KB_BACK)) && (indiceMenu==1) && (Name.length()>0)) {Name.removeLast(); return true;}
  
   if((Kb.c()) && (indiceMenu==1) && (Name.length()<15)) {Name+=Kb.c(); return true;}

   if (Ms.b(0)) ActualizarRaton(Ms.pos);

   // if (indiceMenu==3) RUN_GAME;

   Clouds.volumetric.update(Vec2(4,4));

   return true;
}
/******************************************************************************/
void Render()
{
   switch(Renderer())
   {
      case RM_SOLID:
          matrixPlane.move(Vec(IncX,IncY,IncZ));
          if ((matrixPlane.pos.x>-42) || (matrixPlane.pos.x<-82)) IncX=-IncX;
          if ((matrixPlane.pos.y>96) || (matrixPlane.pos.y<56)) IncY=-IncY;
          if ((matrixPlane.pos.z>54) || (matrixPlane.pos.z<20)) IncZ=-IncZ;
          meshPlane.draw(matrixPlane);
      break;
   }
}
void Draw()
{
   Renderer(Render);

   TextDS tds;

   tds.color=GREY_DARK;
   tds.scale*=2;
   tds.shadow=64;


   switch (indiceMenu) {
       case 0 : {
                FREP(3) D.text(tds,0.7f,0.3f-i*0.3f,ccText[i]);
                break;
                }
       case 1 : {
                D.text(tds,0.75f,0.25f,ccText[6]);
                tds.align.set(1,0);
                tds.color=GREY_DARK2;
                tds.shadow=0;
                if ((int)Tm.time()%2==0) D.text(tds,0.25f,0,S+Name+'_'); else D.text(tds,0.25f,0,Name);
                break;
                }
       case 2 : {
                FREP (3)    {
                            if (difficulty==i) {tds.color=GREY_DARK2;} else {tds.color=GREY;}
                            D.text(tds,0.7f,0.3f-i*0.3f,ccText[i+3]);
                            }
                }


   }

   //D.text(0,-0.8,S+Ms.pos);
}
/******************************************************************************/
04-13-2009 07:24 PM
Find all posts by this user Quote this message in a reply
kaito Offline
Member

Post: #4
Re: DEMO in progress. Code
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


[Image: capturaz.png]

--------------------------------------------

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
05-10-2009 12:42 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
Re: DEMO in progress. Code
great progress, the screen looks alot better smile keep up the good work.
05-10-2009 12:58 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
Re: DEMO in progress. Code
As for the world continuous loop:
you can do this only if you're manually drawing the terrain.

Something like this
having terrain chunks A,B,C, render them like this:

A
B
C
A
B
C

but you'd need to make sure that C chunk matches the A chunk at the edges

EDIT: but generally in this kind of games you have a limited terrain, and mostly fight bossess on the end smile
05-10-2009 01:00 PM
Find all posts by this user Quote this message in a reply
Post Reply