Most asked questions

Top  Previous  Next

Q: I'd like to have a tv that turns itself on / off depending on how close the player is to it. Can you help?
A: Attach the action below to your tv (a sprite):

 

var tv_handle;

 

action tv_sprite
{
       while (player == null) {wait (1);}
       while (1)
       {
               if (vec_dist(player.x, my.x) < 200) // the player has come closer than 200 quants?
               {
                       if (tv_handle == 0) // the movie isn't playing
                       {
                               tv_handle = media_play ("globe.avi", bmap_for_entity (my, 0), 100); // then start playing it!
                       }
               }
               else
               {
                       media_stop (tv_handle);
                       tv_handle = 0; // reset the handle manually
               }
               wait (1);
       }
}

 

aum46_shot4

 

 

Q: I need to display a picture when the player approaches an invisible object at the end of the game.
A: Use the code below:

 

bmap gameover_pcx = <gameover.pcx>;

 

panel gameover_pan
{
       bmap = gameover_pcx;
       flags = overlay, refresh;
}

 

action invisible_object
{
       my.invisible = on;
       while (player == null) {wait (1);}
       while (vec_dist(player.x, my.x) > 100) {wait (1);} // wait until the player has come closer than 100 quants to this object
       gameover_pan.visible = on; // show the panel
       while (key_any == on) {wait (1);} // wait until the player releases the any key (if this is the case)
       while (key_any == off) {wait (1);} // now wait until the player presses a key (any key!)
       exit; // shut down the engine
}

 

aum46_shot5

 

 

Q: I was wondering if you could tell me how to create a star wars lightsaber effect.
A: Use the code below:

 

bmap flare_pcx = <flare.pcx>;

 

var sword_vertex;

var ray_size;
var temp_left;

 

function remove_flares()
{
       my.lifespan = 0; // remove the particle
}

 

function attach_rays()
{
       my.bmap = flare_pcx;
       my.flare = on;
       my.bright = on;
       my.size = 7;
       my.function = remove_flares;
}

 

action monster_with_sword
{
       while (1)
       {
               ray_size = 1;
               ent_cycle("stand", my.skill1); // play "stand" frames animation
               my.skill1 += 0.4 * time; // animation speed
               my.skill1 %= 100; // loop animation
               vec_for_vertex (sword_vertex, my, 333); // set the vertex that will be used for the base of the sword here
               effect (attach_rays, 1, sword_vertex, normal);
               while (ray_size > 0)
               {
                       vec_for_normal (temp_left, my, 235);
                       vec_normalize (temp_left, ray_size);
                       vec_add (sword_vertex, temp_left);
                       effect (attach_rays, 1, sword_vertex, normal);
                       ray_size -= 0.01;
               }
               wait (1);
       }
}

 

aum46_shot6

 

 

Q: I use the starfield code from your "Planet Survivor" series. Is it possible to modify the code so that the starfield is always in front of my spaceship, even if I change its pan and tilt and I move it?

A: Sure. Use the code below:

 

bmap star_tga = <star.tga>;

 

string gibbit_mdl = <gibbit.mdl>;

 

var starfield_speed = 2; // controls the global speed of the starfield

 

function size_particles()

{

  my.size += 0.01 * time;

}

 

function particle_init()

{

  temp.x = -(2 + random (15)) * starfield_speed;

  temp.y = 0;

  temp.z = 0;

  vec_add (my.vel_x, temp);

  my.bmap = star_tga;

  my.alpha = 40 + random(60); // play with this value

  my.size = 5 + random(5);

  my.bright = on;

  my.move = on;

  my.lifespan = 500;

  my.function = size_particles;

}

 

function init_starfield()

{

  my.invisible = on;

  my.passable = on;

  while (1)

  {

     vec_set(temp, vector(1000, 0, 0)); // keep the starfield generator 1000 quants in front of the camera all the time

     vec_rotate(temp, camera.pan);

     vec_add(temp, camera.x);

     vec_set(my.x, temp);

     temp.x = my.x + 500 - random(1000);

     temp.y = my.y + 500 - random(1000);

     temp.z = my.z + 500 - random(1000);

     effect (particle_init, 15 * time, temp, normal);

     wait (1);

  }

}

 

starter particle_generator()

{

  while (player == null) {wait (1);}

  ent_create (gibbit_mdl, player.x, init_starfield);

}

 

 

Q: I'd like to be able to go back and forth in my levels, while keeping the initial player pan angle. How can I do that?

A: Use the code below:

 

var players_pan; // global variable

 

string level1_wmb = <office.wmb>;

string level2_wmb = <level2.wmb>;

 

function change_levels_12

{

  players_pan = player.pan; // store the initial pan

  wait (1);

  if (you != player) {return;} // the entity that collided with me isn't the player?

  me = null; // keep this function running even after load_level

  level_load (level2_wmb); // load the new level

  sleep (0.1); // wait a bit

  player.pan = players_pan; // restore the initial pan

}

 

function change_levels_21

{

  players_pan = player.pan; // store the initial pan

  wait (1);

  if (you != player) {return;} // the entity that collided with me isn't the player?

  me = null; // keep this function running even after load_level

  level_load (level2_wmb); // load the new level

  sleep (0.1); // wait a bit

  player.pan = players_pan; // restore the initial pan

}

 

action level_12 // place an entity in the level and attach it this action

{

  my.enable_impact = on; // this entity is sensitive to impact

  my.event = change_levels_12; // changes the level when the player runs into it

}

 

action level_21 // place an entity in the level and attach it this action

{

  my.enable_impact = on; // this entity is sensitive to impact

  my.event = change_levels_21; // changes the level when the player runs into it

}

 

 

Q: How can I create a cylinder of particles?

A: Use the code below:

 

var cylinder_radius = 20;

var cylinder_height = 40;

var temp_angle = 0;

 

bmap effect_tga = <effect.tga>;

 

function particle_cylinder();

function fade_particles();

 

action cylinder

{

  my.invisible = on;

  my.passable = on;

  while(1)

  {

     temp.x = my.x + cylinder_radius * cos(temp_angle);

     temp.y = my.y + cylinder_radius * sin(temp_angle);

     temp.z = my.z + random(cylinder_height);

     effect(particle_cylinder, 100 * time, temp.x, nullvector);

     temp_angle += 31; // experimental value

     wait(1);

  }

}

 

function particle_cylinder()

{

  temp.x = 0;

  temp.y = 0;

  temp.z = random(2) + 2;

  vec_set(my.vel_x,temp);

  my.bmap = effect_tga;

  my.size = 2;

  my.flare = on;

  my.bright = on;

  my.move = on;

  my.streak = on; // if your engine version supports it

  my.alpha = 50 + random(50);

  my.lifespan = 50;

  my.function = fade_particles;

}

 

function fade_particles()

{

  my.alpha -= 2 * time;

  if(my.alpha < 0)

  {

     my.lifespan = 0;

  }

}

 

aum46_shot7

 

 

Q: If I have a panel with 3 buttons, can I hide one or two of them at times and show them again at another time?

A: Hide the buttons by moving them outside the screen with pan_setpos:

 

bmap test_pcx = <test.pcx>;

bmap confirmyes1_pcx = <confirmyes1.pcx>;

bmap confirmyes2_pcx = <confirmyes2.pcx>;

bmap confirmyes3_pcx = <confirmyes3.pcx>;

 

panel test_pan

{

  bmap = test_pcx;

  button = 90, 136, confirmyes3_pcx, confirmyes1_pcx, confirmyes2_pcx, null, null, null;

  flags = refresh, visible;

}

 

function hide_button()

{

  pan_setpos(test_pan, 3, 0, vector(1000, 1000, 0)); // moving a button (=3) to (1000, 1000) pixels (outside the screen)

}

 

on_h = hide_button; // press the "H" key to hide the button

 

 

 

Q: Can you show us how to use the mouse wheel in order to zoom in and out smoothly?

A: Use this example:

 

starter wheel_zoom()

{

  while (1)

  {

     if (mickey.z > 1)

     {

        camera.arc += 10 * time; // play with "10"

     }

     if (mickey.z < -1)

     {

        camera.arc -= 10 * time; // play with "10"

     }

     camera.arc = min (max (camera.arc, 10), 120); // limit camera.arc to 10..120

     wait (1);

  }

}