Questions from the forum

Top  Previous  Next

Q: I want to modify the surveillance camera code from aum10. When the player stands in front of a monitor and presses the action key, the code should switch between the cameras.

A: Here's an example which works with 3 different surveillance cameras - use it as a base for your code.

 

view surv_camera {}

 

function initcam_startup()

{

       surv_camera.size_x = screen_size.x; // surv_camera has the same size and position

       surv_camera.size_y = screen_size.y; // like the original "camera"

       surv_camera.pos_x = 0;

       surv_camera.pos_y = 0;

}

 

action camera_trigger // place several entities in the level and attach them this action

{

       while (!player) {wait (1);}

       while (1)

       {

               my.skill10 = abs(ang(player.pan) - ang(my.pan)); // angle between the player and the camera trigger

               if ((vec_dist(player.x, my.x) < 100) &&  (my.skill10 > 150) && (my.skill10 < 210)) // if the player looks at the trigger

               {

                       camera.visible = off; // hide the default "camera"

 

                       surv_camera.x = 100; // use your own x, y, z, pan, tilt, roll values here

                       surv_camera.y = 200;

                       surv_camera.z = 300;

                       surv_camera.pan = 50;

                       surv_camera.tilt = -30;

                       surv_camera.roll = 0;

                       surv_camera.visible = on; // and make it visible

                       while (!key_ctrl)  // press the "Ctrl" key to switch to the second camera

                       {

                               if (vec_dist (player.x, my.x) > 150) {break;}

                               wait (1);

                       }

                       while (key_ctrl) {wait (1);} // now wait until the "Ctrl" key is released

 

                       surv_camera.x = 400; // use your own x, y, z, pan, tilt, roll values here

                       surv_camera.y = -100;

                       surv_camera.z = 230;

                       surv_camera.pan = 150;

                       surv_camera.tilt = -10;

                       surv_camera.roll = 0;

                       surv_camera.visible = on;

                       while (!key_ctrl)  // press the "Ctrl" key to switch to the second camera

                       {

                               if (vec_dist (player.x, my.x) > 150) {break;}

                               wait (1);

                       }

                       while (key_ctrl) {wait (1);} // now wait until the "Ctrl" key is released

 

                       surv_camera.x = 1200; // use your own x, y, z, pan, tilt, roll values here

                       surv_camera.y = -500;

                       surv_camera.z = 50;

                       surv_camera.pan = 30;

                       surv_camera.tilt = 40;

                       surv_camera.roll = 0;

                       surv_camera.visible = on;

                       while (!key_ctrl)  // press the "Ctrl" key to switch to the second camera

                       {

                               if (vec_dist (player.x, my.x) > 150) {break;}

                               wait (1);

                       }

                       while (key_ctrl) {wait (1);} // now wait until the "Ctrl" key is released

 

               }

               else // the player has moved away from the camera trigger

               {

                       surv_camera.visible = off;

                       camera.visible = on;        

                       my.skill11 += 1;

                       while (!key_ctrl) {wait (1);}

                       while (key_ctrl) {wait (1);}

               }

               wait (1);

       }

}

 

 

Q: How can I make an object orbit around a specified xyz point from my level?

A: Place the entity that is supposed to orbit at the desired xyz in Wed, and then attach it the following action.

 

action object_orbits

{

       var orbit_radius = 200; // use your own value here

       var orbit_speed = 4; // and here

       var temp_angle;

       var orbit_center;

       vec_set (orbit_center.x, my.x); // store the orbit center position

       while(1)

       {

               my.x = orbit_center.x + sin(temp_angle) * orbit_radius;

               my.y = orbit_center.y + cos(temp_angle) * orbit_radius;

               my.z = orbit_center.z;

               temp_angle += orbit_speed * time_step;

               wait(1);

       }

}

 

 

Q: How can I attach particles to the mouse pointer?

A: Use this example.

 

BMAP arrow_pcx = "arrow.pcx";

BMAP snow_tga = "snow.tga";

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = arrow_pcx;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function fade_part()

{

       my.ALPHA -= 15 * time_step;

       if (my.ALPHA < 0) {my.LIFESPAN = 0;}

}

 

function mouse_particles()

{

       var particle_direction;

       particle_direction.x = 0.2 * (random(1) - 2);

       particle_direction.y = 0.2 * (random(1) - 2);

       particle_direction.z = 0.1 * random(1);

       vec_add(my.VEL_X, particle_direction);

       my.ALPHA = 30 + random(65);

       my.FLARE = ON;

       my.BMAP = snow_tga;

       my.SIZE = 0.5;

       my.BRIGHT = ON;

       my.MOVE = ON;

       my.FUNCTION = fade_part;

}

 

function particles_startup()

{

       var particle_origin;

       while (1)

       {

               particle_origin.x = mouse_pos.x;

               particle_origin.y = mouse_pos.y;

               particle_origin.z = 40;

               vec_for_screen (particle_origin, camera);

               effect(mouse_particles, 1, particle_origin.x, normal);

               wait (1);

       }

}

 

aum65_faq1

 

 

Q: I want to capture a movie from my game and play it on my PSP game console. How do I tell Acknex to run at the needed resolution?

A: Use the following sample. Then, use a screen capturing application to capture your movie.

 

function switch_psp()

{

       video_set(480, 272, 32, 2); // switch to 480x272 pixels, 32 bits, window mode

}

 

on_p = switch_psp; // press the "P" key to switch to PSP mode

 

 

Q: I want to make the camera follow a path in a loop. How can I do that?

A: Create a path in Wed, place a model named dummy.mdl inside your game folder, and then attach it the action named dummy_target.

 

var cam_speed = 1; // initial speed

var dist_to_node;

var current_node = 1;

var angle_difference = 0;

var temp_angle;

var pos_node; // stores the position of the node

 

ENTITY* dummy_ent;

 

function move_dummy()

{

       my.PASSABLE = ON;

       my.INVISIBLE = ON;

       while (1)

       {

               vec_set (my.x, you.x);

               wait (1);

       }

}

 

function move_target()

{

       while(1)

       {

               cam_speed = minv(15, cam_speed + 5 * time_step); // 15 gives the movement speed

               c_move(my, vector(cam_speed * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

               vec_to_angle (dummy_ent.pan, vec_diff (temp_angle, pos_node, my.x));

               if(my.pan != dummy_ent.pan)

               {

                       angle_difference = ang(dummy_ent.pan - my.pan);

                       my.pan += angle_difference * 0.2 * time_step;

               }

               vec_set (camera.x, my.x);

               camera.pan = my.pan;

               camera.tilt = my.tilt;

               wait(1);

       }

}

 

action dummy_target()

{        

       dummy_ent = ent_create ("dummy.mdl", nullvector, move_dummy);

       move_target();

       result = path_scan(me, my.x, my.pan, vector(360, 180, 1000));

       if (!result) {return;}

       path_getnode (my, 1, pos_node, NULL);

       vec_to_angle (my.pan, vec_diff (temp_angle, pos_node, my.x)); // rotate towards the node

       vec_to_angle (dummy_ent.pan, vec_diff (temp_angle, pos_node, my.x)); // rotate dummy_ent towards the node as well

       while (1)

       {

               dist_to_node = vec_dist(my.x, pos_node);

               if(dist_to_node < 300) // close to the node?

               {

                       current_node = path_nextnode(my, current_node, 1);

                       if (!current_node) {current_node = 1;} // reached the end of the path? Then start over!

                       path_getnode (my, current_node, pos_node, NULL);

               }

               wait(1);

       }

}

 

 

Q: In a 3rd person environment where you want the model to display what they are carrying, how do you go about giving a model different things? Weapons, armor, hair, clothes, etc. Better still, what's the best way to manage them all?

A: Check out the Morrowing series from Aum46... 50 to see a simple, working inventory system. Animate your character together with the items that it is supposed to carry, wear, etc and then save them (the player and the items) as separate models - this method will guarantee that they're always in sync.

 

 

Q: My educational game uses 227 panels, but I don't use them all at the same time. How could I save some video memory? Right now my game needs about 160 MB.

A: Use pan_create to create the panels when you need them and pan_remove to remove the panels when you don't need them anymore.

 

PANEL* new_panel1;

PANEL* new_panel2;

 

function panels_startup()

{

       sleep (5); // wait for 5 seconds

       // now create and display the first panel; its layer is set to 10

       new_panel1 = pan_create("bmap = test1.pcx; pos_x = 150; pos_y = 40; flags = OVERLAY | VISIBLE;", 10);

       sleep (3); // display the first panel for 3 seconds

       pan_remove (new_panel1); // now remove the panel from the memory

       sleep (2); // wait for 2 seconds

       // now create and display the second panel; its layer is set to 15

       new_panel2 = pan_create("bmap = test2.pcx; pos_x = 50; pos_y = 140; flags = OVERLAY | VISIBLE;", 15);

       sleep (4); // display the second panel for 4 seconds

       pan_remove (new_panel2); // now remove the panel from the memory

}

 

 

Q: Is there a possibility to change the mouse pointer bitmap if it is hovering over a certain panel?

A: Sure! Let's suppose that the panel is placed at x = 600, y = 20 pixels, has a width of 100 pixels and a height of 50 pixels. Under these conditions, the code would look like this:

 

BMAP arrow1_pcx = "arrow1.pcx";

BMAP arrow2_pcx = "arrow2.pcx";

 

function mouse_startup()

{

       mouse_mode = 2;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               if ((mouse_pos.x > 600) && (mouse_pos.x < 700) && (mouse_pos.y > 20) && (mouse_pos.y < 70))

               {

                       mouse_map = arrow2_pcx;

               }

               else

               {

                       mouse_map = arrow1_pcx;

               }

               wait(1);

       }

}

 

 

Q: I was wondering if anyone could tell me how to put a looping wav file in a splash screen script. I want it to play over and over until the space bar is pressed to start the game.

A: Use something like this.

 

var intro_playing;

 

PANEL splash_pan =

{

       bmap = "splash.pcx";

       pos_x = 0;

       pos_y = 0;

       layer = 15;

       flags = VISIBLE;

}

 

function splash_startup()

{

       intro_playing = media_loop("intro.wav", NULL, 80); // play intro.wav in a loop

       while (!key_space) {wait (1);} // wait until the "space" key is pressed

       while (key_space) {wait (1);} // wait until the "space" key is released

       media_stop (intro_playing); // now stop the music

       splash_pan.VISIBLE = OFF; // and hide the splash screen panel

       // put the rest of your game code here

}

 

 

Q: I want to display a question on the screen, accept the answer given by the user and store it.

A: Use the following snippet.

 

var filehandle;

 

STRING answer1_str = "                    "; // accept up to 20 characters

STRING answer2_str = "                    "; // accept up to 20 characters

 

TEXT name_txt =

{

       layer = 15;

       pos_x = 250;

       pos_y = 50;

       string ("What is your name?");

}

 

TEXT answer1_txt =

{

       layer = 15;

       pos_x = 380;

       pos_y = 50;

       string (answer1_str);

}

 

TEXT age_txt =

{

       layer = 15;

       pos_x = 250;

       pos_y = 50;

       string ("How old are you?");

}

 

TEXT answer2_txt =

{

       layer = 15;

       pos_x = 380;

       pos_y = 50;

       string (answer2_str);

}

 

function answers_startup() // gets the user's data and stores it inside the answers.txt file

{

       sleep (3);

 

       name_txt.visible = ON;

       answer1_txt.visible = ON;

       inkey(answer1_str);

       name_txt.visible = OFF;

       answer1_txt.visible = OFF;

 

       age_txt.visible = ON;

       answer2_txt.visible = ON;

       inkey(answer2_str);

       age_txt.visible = OFF;

       answer2_txt.visible = OFF;

 

       // the answers are stored inside answer1_str and answer2_str, so let's save them

       filehandle = file_open_write ("answers.txt"); // open the file for writing

       file_str_write (filehandle, answer1_str); // write the first answer (the name)

       file_asc_write (filehandle, 13); // write the second answer on a separate row

       file_asc_write (filehandle, 10); // using these 2 lines of code

       file_str_write (filehandle, answer2_str); // now write the second answer (the age)

       file_close (filehandle); // close the file

}