Questions from the forum

Top  Previous  Next

Q: Is it possible to detect if my bouncing ball has collided with a particular wall?

A: Make that particular wall a wmb entity, and then set one of its skills to a certain value, just like I did in the example below.

 

function bounce_off() // ball's event function

{

       vec_to_angle(my.pan, bounce); // change the direction as expected from a "real" ball

       my.pan += 5 - random(10); // add some randomness at each collision (don't allow the ball to get stuck)

       if (you) // collided with another entity (maybe with our special wall)?

       {

               if (you.skill100 == 13579) // if the entity is our special wall indeed

               {

                       beep(); // do what you need to do here

               }

       }

}

 

action my_ball() // attach this action to your ball

{

       my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); // the object is sensitive to block and entity collisions

       my.event = bounce_off;

       my.skill100 = 13579; // set this skill to a weird value in order to differentiate the object from the others

       while(1)

       {

               c_move(me, vector(5 * time_step, 0, 0), nullvector, 0); // move ahead, in the direction given by the pan angle

               wait(1);

       }

}

 

action special_wall() // attach this action to your special wall

{

       my.skill100 = 13579; // we will test this value in ball's event function

}

 

 

Q: How i can make a weapon switch snippet?

A: Here's an example that uses the mouse wheel and allows you to scroll through 3 different weapons.

 

ENTITY* weapon1 = // first weapon

{

       type = "weapon1.mdl";

       layer = 5;

       x = 145; // place this gun 145 quants ahead of the view

       y = -70; // 70 quants to the right

       z = -30; // and 30 quants below the center of the screen

       pan = 7;

       tilt = 10;

       flags2 = VISIBLE; // the first weapon is visible by default

}

 

ENTITY* weapon2 = // second weapon

{

       type = "weapon2.mdl";

       layer = 5;

       x = 135; // place this gun 135 quants ahead of the view

       y = -30; // 30 quants to the right

       z = -20; // and 20 quants below the center of the screen

       pan = 3;

       tilt = 10;

}

 

ENTITY* weapon3 = // third weapon

{

       type = "weapon3.mdl";

       layer = 5;

       x = 150; // place this gun 150 quants ahead of the view

       y = 20; // 20 quants to the right

       z = 10; // and 10 quants above the center of the screen

       pan = -4;

       tilt = -10;

}

 

function weapons_startup()

{

       var weapon_number = 1;

       while (1)

       {

               if (mickey.z < -1)

               {

                       weapon_number %=3;                

                       weapon_number += 1; // don't allow weapon_number to be smaller than 1 or bigger than 3

                       if (weapon_number == 1)

                       {

                               weapon1.flags2 |= VISIBLE;

                               weapon2.flags2 &= ~VISIBLE;

                               weapon3.flags2 &= ~VISIBLE;

                       }

                       if (weapon_number == 2)

                       {

                               weapon1.flags2 &= ~VISIBLE;

                               weapon2.flags2 |= VISIBLE;

                               weapon3.flags2 &= ~VISIBLE;

                       }

                       if (weapon_number == 3)

                       {

                               weapon1.flags2 &= ~VISIBLE;

                               weapon2.flags2 &= ~VISIBLE;

                               weapon3.flags2 |= VISIBLE;

                       }

               }

               if (mickey.z > 1)

               {

                       weapon_number %=3;                

                       weapon_number += 1; // don't allow weapon_number to be smaller than 1 or bigger than 3

                       if (weapon_number == 3)

                       {

                               weapon1.flags2 |= VISIBLE;

                               weapon2.flags2 &= ~VISIBLE;

                               weapon3.flags2 &= ~VISIBLE;

                       }

                       if (weapon_number == 2)

                       {

                               weapon1.flags2 &= ~VISIBLE;

                               weapon2.flags2 |= VISIBLE;

                               weapon3.flags2 &= ~VISIBLE;

                       }

                       if (weapon_number == 1)

                       {

                               weapon1.flags2 &= ~VISIBLE;

                               weapon2.flags2 &= ~VISIBLE;

                               weapon3.flags2 |= VISIBLE;

                       }

               }

               wait (1);

       }

}

 

 

Q: Is it possible to load skins on my entities at runtime ? What I mean to do is change the clothes on an entity at runtime.

A: You can use ent_morphskin for that; here's an example.

 

action my_entity()

{

       my.skill1 = 100; // the entity starts with 100 health points

       my.skill2 = 0;

       while (my.skill1 > 0)

       {

               // decrease the health (skill1) at all times; this should be done by the enemies under normal conditions

               my.skill1 -= 1 * time_step; // 1 gives the health decreasing speed

               my.skill22 += 4 * time_step; // 4 gives the "stand" animation speed

               ent_animate(my, "stand", my.skill22, ANM_CYCLE);

               if (my.skill1 < 20) // the entity is almost dead?

               {

                       if (my.skill2 == 0)

                       {

                               ent_morphskin(my, "bruised.pcx"); // then replace the skin with another one

                               my.skill2 = 1; // replace the skin only once; no need to waste the cpu power

                       }

               }

               wait (1);

       }

       my.skill22 = 0;

       while (my.skill22 < 100)

       {

               my.skill22 += 5 * time_step;

               ent_animate(my, "death", my.skill22, NULL);

               wait (1);

       }

       set (my, PASSABLE); // the corpse is passable now

}

 

aum81_faq1

 

 

Q: I have been trying to convert the cameras script from Aum4 with an addition from Aum7 (1st person add-on) to lite-C. Can anyone help?

A: There you go.

 

var camera_number = 1;

 

function camera_startup()

{

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

       while (1)

       {

               if (key_1)

               {

                       camera_number = 1;

               }

               if (key_2)

               {

                       camera_number = 2;

               }

               if (key_3)

               {

                       camera_number = 3;

               }

               if (key_4)

               {

                       camera_number = 4;

               }

               if (key_5)

               {

                       camera_number = 5;

               }

               if (camera_number == 1) // top view

               {

                       camera.x = player.x;

                       camera.y = player.y;

                       camera.z = player.z + 300; // play with this value

                       camera.pan = player.pan;

                       camera.tilt = -90;

                       camera.roll = 0;

               }

               if (camera_number == 2) // side view

               {

                       camera.x = player.x + 200 * sin(player.pan); // 200 = distance

                       camera.y = player.y - 200 * cos(player.pan) ; // same value here

                       camera.z = player.z + 10; // a little higher

                       camera.pan = player.pan + 90; // face the player

                       camera.tilt = 0;

                       camera.roll = 0;

               }

               if (camera_number == 3) // isometric view

               {

                       camera.x = player.x - 200 * cos(player.pan); // 200 = distance

                       camera.y = player.y - 200 * sin(player.pan); // same value here

                       camera.z = player.z + 200; // above the player

                       camera.pan = player.pan;

                       camera.tilt = -30; // look down at the player

                       camera.roll = 0;

               }

               if (camera_number == 4) // aidemo view

               {

                       // 200 = front distance, 150 = side distance

                       camera.x = player.x + 200 * cos(player.pan) + 150 * sin(player.pan);

                       camera.y = player.y + 200 * sin(player.pan) - 150 * cos(player.pan);

                       camera.z = player.z;

                       camera.pan = player.pan + 130; // look back to the player

                       camera.tilt = 0;

                       camera.roll = 0;

               }

               if (camera_number == 5) // 1st person view

               {

                       camera.x = player.x;

                       camera.y = player.y;

                       camera.z = player.z + 40; // play with 40

                       camera.pan = player.pan;

                       camera.tilt = player.tilt;

                       camera.roll = player.roll;

               }

               wait (1);

       }

}

 

action player_code() // attach this action to your player

{

       var movement_speed = 10; // movement speed

       var anim_percentage;

       VECTOR temp;

       player = my; // I'm the player

       while (1)

       {

               my.pan -= 7 * mouse_force.x * time_step;

               vec_set (temp.x, my.x); // trace 10,000 quants below the player

               temp.z -= 10000;

               temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) + 20; // play with 20

               temp.x = movement_speed * (key_w - key_s) * time_step;

               temp.y = movement_speed * (key_a - key_d) * 0.6 * time_step;

               c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);

               if (!key_w && !key_s) // the player isn't moving?

               {

                       ent_animate(my, "stand", anim_percentage, ANM_CYCLE); // play the "stand" animation

                       anim_percentage += 5 * time_step; // 5 = animation speed

               }

               else // the player is moving?

               {

                       ent_animate(my, "walk", anim_percentage, ANM_CYCLE); // play the "walk" animation

                       anim_percentage += 8 * time_step; // 8 = animation speed

               }

               wait (1);

       }

}

 

aum81_faq2

 

aum81_faq3

 

aum81_faq4

 

aum81_faq5

 

aum81_faq6

 

 

Q: I want to have a bird in my game. It should move along the x axis, and when it is above the player it should drop some models on player's head, just like the enemies from Aum71 (Parallax scrolling), but for a 2.5D game.

A: Here's a bird that moves back and forth along the x axis and drops models when it is above the player.

 

STRING* bomb_mdl = "bomb.mdl";

 

function set_frames()

{

       fps_max = 75; // limit the frame rate to 75 fps

}

 

function bomb_event()

{

       // do something bad to the player here ;)

       wait (1);

       ent_remove(my);

}

 

function move_bomb()

{

       my.emask |= (ENABLE_BLOCK | ENABLE_IMPACT | ENABLE_ENTITY);

       my.event = bomb_event;

       while (my)

       {

               c_move(my, vector(0, 0, -10 * time_step), nullvector, IGNORE_PASSABLE);

               wait (1);

       }

}

 

action bird_enemy()

{

       var anim_percentage;

       var init_x;

       init_x = my.x; // store the initial x value for the bird

       while (!player) {wait (1);} // wait until the player model is loaded

       while (1)

       {

               // move up to 1000 quants away from the initial position

               while (my.x < init_x + 1000)

               {

                       ent_animate(my, "fly", anim_percentage, ANM_CYCLE); // play the "fly" animation

                       anim_percentage += 8 * time_step; // 8 = animation speed

                       my.x += 15 * time_step;

                       // the player is close to the bird on the x axis? (play with 200)

                       // then drop a bomb every second!

                       if ((abs(my.x - player.x) < 200) && (total_frames % 75 == 1))

                       {

                               // create the bomb 20 quants below the bird's origin

                               ent_create (bomb_mdl, vector(my.x, my.y, my.z - 20), move_bomb);

                       }        

                       wait (1);

               }

               my.pan += 180; // the bird will turn back

               // now return to the initial position

               while (my.x > init_x)

               {

                       ent_animate(my, "fly", anim_percentage, ANM_CYCLE); // play the "fly" animation

                       anim_percentage += 8 * time_step; // 8 = animation speed

                       my.x -= 15 * time_step;

                       // the player is close to the bird on the x axis? (play with 200)

                       // then drop a bomb every second!

                       if ((abs(my.x - player.x) < 200) && (total_frames % 75 == 1))

                       {

                               // create the bomb 20 quants below the bird's origin

                               ent_create (bomb_mdl, vector(my.x, my.y, my.z - 20), move_bomb);

                       }        

                       wait (1);

               }

               my.pan += 180;        

               // restore the proper pan angle

               wait (1);

       }

}

 

aum81_faq7

 

 

Q: I'd like to load the desired level by clicking on its corresponding button on a panel. Can you help?

A: Sure; use the code below.

 

BMAP* levels_tga = "levels.tga";

BMAP* pointer_tga = "pointer.tga";

BMAP* level11_tga = "level11.tga";

BMAP* level12_tga = "level12.tga";

BMAP* level21_tga = "level21.tga";

BMAP* level22_tga = "level22.tga";

BMAP* level31_tga = "level31.tga";

BMAP* level32_tga = "level32.tga";

 

STRING* level1_wmb = "level1.wmb";

STRING* level2_wmb = "level2.wmb";

STRING* level3_wmb = "level3.wmb";

 

function load_level1();

function load_level2();

function load_level3();

 

PANEL* levels_pan =

{

       bmap = levels_tga;

       layer = 10;

       pos_x = 240;

       pos_y = 180;

       button (100, 70, level11_tga, level11_tga, level12_tga, load_level1, NULL, NULL);

       button (100, 110, level21_tga, level21_tga, level22_tga, load_level2, NULL, NULL);

       button (100, 150, level31_tga, level31_tga, level32_tga, load_level3, NULL, NULL);

       flags = VISIBLE;

}

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function load_level1()

{

       while (mouse_left) {wait (1);}

       level_load (level1_wmb);

       // remove the comment from the following line if you want to hide the panel after loading the level

       // reset(levels_pan, VISIBLE);

}

 

function load_level2()

{

       while (mouse_left) {wait (1);}

       level_load (level2_wmb);

       // remove the comment from the following line if you want to hide the panel after loading the level

       // reset(levels_pan, VISIBLE);

}

 

function load_level3()

{

       while (mouse_left) {wait (1);}

       level_load (level3_wmb);

       // remove the comment from the following line if you want to hide the panel after loading the level

       // reset(levels_pan, VISIBLE);

}

 

aum81_faq8

 

 

Q: Does anyone know of a snippet that allows you to touch an entity and makes a text appear? The one at au.conitec.net isn't working for me.

A: Here's a snippet that does what you want.

 

BMAP* pointer_tga = "pointer.tga";

 

TEXT* message_txt =

{

       pos_x = 300;

       pos_y = 50;

       string("Hey! Move the mouse away from me!");

}

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function display_text()

{

       set (message_txt, VISIBLE);

       wait (-5);

       reset (message_txt, VISIBLE);

}

 

action my_entity()

{

       my.emask |= (ENABLE_TOUCH);

       my.event = display_text;

}

 

 

Q: Will somebody please give me a treasure chest action code?

A: Attach the action below to your animated chest model; run into the chest to open it.

 

STRING* prize_mdl = "prize.mdl";

 

function spinning_model()

{

       var init_z;

       init_z = my.z;

       set (my, PASSABLE);

       while (my.z < init_z + 300) // the prize will move 300 quants upwards

       {

               my.z += 10 * time_step;

               my.pan += 8 * time_step;

               wait (1);

       }

       while (my.z > init_z) // and then it will return to its initial height

       {

               my.z -= 7 * time_step;

               my.pan += 6 * time_step;

               wait (1);

       }

       while (1)

       {

               my.pan += 4 * time_step;

               if (vec_dist (player.x, my.x) < 30) // the player has come very close to the prize? (play with 30)

                       break; // then get out of the loop

               wait (1);

       }

       ent_remove (my); // the prize will disappear (it has been picked up)

       // increase player's health, score, etc here

}

 

function open_chest()

{

       if (!you) return; // didn't collide with an entity? Then don't do anything!

       if (you != player) return; // didn't collide with the player? Then don't do anything

       my.event = NULL; // don't react to other impacts from now on

       var anim_percentage = 0;

       while (anim_percentage < 100)

       {

               ent_animate(my, "open", anim_percentage, NULL); // play the "chest opening" animation

               anim_percentage += 2 * time_step; // 2 gives the animation speed

               wait (1);

       }

       // the chest is open here, so let's create a reward (a spinning model) inside it

       ent_create(prize_mdl, my.x, spinning_model);

       wait (-1); // wait for a second

       ent_remove(my); // now remove the chest model, allowing the player to come close to the reward

}

 

action my_chest() // the chest should have a size of 100 quants or so

{

       set (my, POLYGON);

       while (!player) {wait (1);} // make sure that the player exists in the level

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY); // the chest is sensitive to impacts with other entities

       my.event = open_chest;

}

 

 

Q: How can I create a metallic reflection in GameStudio?

A: GameStudio comes with many ready-to-use materials (and the actions that go with them); they can be found inside the mtlFX.c file. If you want something even more simple, take a look at this snippet:

 

action reflections() // attach this action to your model(s)

{        

       my.material = mat_metal; // use this material to achieve a quick metallic reflection effect

       while (1)

       {

               my.pan += 5 * time_step; // make the object spin

               wait (1);

       }

}

 

aum81_faq9

 

 

Q: I'm trying to create a simple top down space game and I would like to have the player respawn after its death. How can I do that?

A: Use the code below as a base for your code.

 

var players_health = 100;

 

STRING* ship_mdl = "ship.mdl";

 

PANEL* health_pan = // displays player's health

{

       layer = 15;

       digits(700, 20, 3 ,* , 1, players_health);

       flags = VISIBLE;

}

 

function damage_player()

{

       players_health -= 0.5 * time_step;

}

 

function control_ship() // control player's ship using the mouse

{

       player = my;

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);

       my.event = damage_player;

       var temp_speed;

       VECTOR player_speed;

       while (players_health > 0)

       {

               camera.x = my.x;

               camera.y = my.y;

               camera.z = my.z + 1000; // place the camera 1000 quants above the ship

               camera.pan = my.pan;

               camera.tilt = -90; // look down at the ship

               my.pan += 4 * mouse_force.x * time_step; // 4 gives the rotation speed

               temp_speed = 20 * mouse_force.y; // 20 gives the movement speed

               my.skill1 = temp_speed * time_step + maxv(1 - time_step * 0.1, 0) * my.skill1; // 0.1 gives the friction

            player_speed.x = my.skill1 * time_step;

               player_speed.y = 0;

               player_speed.z = 0;

               c_move(my, player_speed, nullvector, IGNORE_PASSABLE | GLIDE);

               wait (1);

       }

}

 

function respawn_startup()

{

       while (1)

       {

               // place the ship at x = 100, y = 200, z = 50 in the level (just an example)

               player = ent_create (ship_mdl, vector (100, 200, 50), control_ship);

               // wait until the player dies by colliding with the walls; use enemies to damage the player as well

               while (players_health > 0) {wait (1);}

               wait (-3); // wait for 3 seconds before respawning the player

               players_health = 100; // restore player's health

       }

}

 

aum81_faq10