Conitec 3d gamestudio-source development 사용자 설명서

다운로드
페이지 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       7
Particle functions
DLL functions can also be used for particles, using the
A4_PARTICLE
struct defined in a5dll.h.
They can be used the same way as C-Script defined particle functions. A pointer to the particle
is the sole argument of a DLL particle function. Example:
  // examples for a particle effect function
  // dllfunction DLLEffect_Explo(particle);
  // dllfunction DLLPart_Alphafade(particle);
  // start the particle effect by
  // effect(DLLEffect_Explo,1000,my.x,nullvector);
  fixed *var_time = NULL;
  long func_alphafade = 0;
  // helper function: fades out a particle
  DLLFUNC fixed DLLPart_Alphafade(long particle)
  {
    if (!var_time || !particle) return 0;
    A4_PARTICLE* p = (A4_PARTICLE*) particle;
    p->alpha -= *var_time * 2;
    if (p->alpha <= 0) p->lifespan = 0;
    return 0;
  }
  // helper function: return a random float
  float random(float max)
  {
    return (float)(rand()*max)/(float)RAND_MAX;
  }
  // particle effect: generate a blue explosion
 
 DLLFUNC fixed DLLEffect_Explo(long particle)
  {
    if (!particle) return 0;
  // initialize time var and alphafade function (must only be done once)
    if (!var_time)
      var_time = (fixed *)a5dll_getwdlobj("time");
    if (!func_alphafade)
      func_alphafade = a5dll_getscript("DLLPart_Alphafade");
    A4_PARTICLE* p = (A4_PARTICLE*) particle;
  // initialize particle parameters
    p->flags |= EPF_STREAK|EPF_MOVE|ENF_FLARE|ENF_BRIGHT;
    p->vel_x = FLOAT2FIX(random(10) - 5);
    p->vel_y = FLOAT2FIX(random(10) - 5);
    p->vel_z = FLOAT2FIX(random(10) - 5);
    p->red = 0;
    p->green = 0;
    p->blue = INT2FIX(255);
    p->alpha = FLOAT2FIX(50 + random(50));
    p->function = func_alphafade;
    return 0;
  }
Programming a game in C++
Using the
A4_ENTITY
object (see below), a DLL can implement complex AI functions that
would be harder to code in C-Script. Even the whole gameplay could be written in a DLL. The
following example shows how to change entity parameters through a DLL function.