Questions from the forum |
Top Previous Next |
Q: I would like my top view camera to point towards any entity I'm touching with the mouse pointer. A: There you go.
BMAP* pointer_tga = "pointer.tga";
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
function camera_startup() { camera.z = 600; // play with the z value camera.tilt = -80; // with the tilt angle camera.arc = 100; // and with the arc value until you see all the entities at once VECTOR temp; while (1) { if (mouse_ent) { vec_set(temp, mouse_ent.x); vec_sub(temp, camera.x); vec_to_angle(camera.pan, temp); } wait (1); } }
Q: Does anyone know of a lite-C script for a mini camera? The camera would be fixed somewhere in a level and the movie would be shown at a screen somewhere else at the level. A: Here's a fully working example.
var fixed_camera = 1;
BMAP* pointer_tga = "pointer.tga";
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
// activates the fixed camera for as long as fixed_camera is set to 1 function camera_startup() { while (1) { if (fixed_camera) { camera.x = -700; camera.y = -365; camera.z = 450; camera.pan = 40; camera.tilt = -35; } wait (1); } }
// attach this action to a sprite or a model // if you are using a sprite, make sure that it has the same size (in pixels) with the size of the movie action movie_display() { media_loop ("movie.wmv", bmap_for_entity (my, 0), 100); // use your own movie name }
Q: I would like to get and display the xyz position of an object in a room, on which i am pointing with my mouse cursor. Hope you can help me. A: There you go.
BMAP* pointer_tga = "pointer.tga";
FONT* arial_font = "Arial#14";
PANEL* entity_pan = // displays the xyz coordinates of the entity { pos_x = 10; pos_y = 10; layer = 15; digits(0, 10, "Entity x coordinate: %.f", arial_font, 1, mouse_ent.x); digits(0, 30, "Entity y coordinate: %.f", arial_font, 1, mouse_ent.y); digits(0, 50, "Entity z coordinate: %.f", arial_font, 1, mouse_ent.z); flags = SHOW; }
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
Q: How can I show an entity skill on a panel? I've tried with digits, but it didn't work. A: You need to use an entity pointer - here's a simple example.
var enemy_skill1, enemy_skill2, enemy_skill3;
FONT* arial_font = "Arial#14";
ENTITY* my_enemy;
PANEL* entity_pan = // displays the xyz coordinates of the entity { pos_x = 10; pos_y = 10; layer = 15; digits(0, 10, "Enemy skill1: %.f", arial_font, 1, enemy_skill1); digits(0, 30, "Enemy skill2: %.f", arial_font, 1, enemy_skill2); digits(0, 50, "Enemy skill3: %.f", arial_font, 1, enemy_skill3); flags = SHOW; }
action enemy_action() { my_enemy = my; my_enemy.skill1 = 123; enemy_skill1 = my_enemy.skill1; my_enemy.skill2 = 456; enemy_skill2 = my_enemy.skill2; my_enemy.skill3 = 789; enemy_skill3 = my_enemy.skill3; }
Q: How can I scroll a text that's displayed above a panel? The text is larger than the panel. A: There you go.
#include <strio.c> // need to include this library
var string_limit = 50; // don't display more than 50 characters from message_str at once
STRING* message_str = "This is a very long text that will be scrolled because its size exceeds the size of the panel"; STRING* temp_str = ""; STRING* output_str = "";
PANEL* hud_pan = { pos_x = 10; pos_y = 10; layer = 15; bmap = "map.tga"; flags = SHOW; }
TEXT* hud_txt = { pos_x = 20; pos_y = 20; layer = 20; // the text is displayed on top of hud_pan string(output_str); flags = SHOW; }
function cut_startup() { var i = 0, j; while (1) { str_cpy(temp_str, message_str); j = i + string_limit; str_cut(output_str, temp_str, i, j); // using a function from the strio.c library to cut the string wait (-0.3); i++; j++; if (i > str_len(message_str)) // the long string ended? i = 0; } }
Q: How can I make a sprite appear on a key press? The sprite needs to fade in. A: Here's an example
function display_sprite();
function create_sprites() { VECTOR sprite_coords; sprite_coords.x = random(200) - 400; // the x of the sprite will be in the -200... 200 quants interval sprite_coords.y = random(200) - 400; // the y of the sprite will be in the -200... 200 quants interval sprite_coords.z = random(200) - 350; // the z of the sprite will be in the -150... 200 quants interval ent_create ("heart2.tga", sprite_coords, display_sprite); }
function display_sprite() { set(my, PASSABLE | TRANSLUCENT); my.alpha = 0; while (my.alpha < 100) { my.alpha += 7 * time_step; // 7 gives the fade-in speed wait (1); } my.alpha = 100; reset(my, TRANSLUCENT);
}
function sprites_startup() { on_c = create_sprites; // press the "C" key to create a new sprite }
Q: How to make a sphere model be filled with mist? A: You can generate particles from the center of the sphere - here's an example.
BMAP* mist_tga = "mist.tga";
function fade_mist(PARTICLE *p) { p.alpha -= 0.5 * time_step; // fade out the particles if (p.alpha < 0) p.lifespan = 0; }
function mist_function(PARTICLE *p) { p.alpha = 10 + random(20); // play with all these values p->vel_x = (1 - random(2)) / 3; // play with all these values p->vel_y = (1 - random(2)) / 3; p->vel_z = (1 - random(2)) / 3; p.bmap = mist_tga; p.size = 5 + random(4); // sets the size of the mist particles p.flags |= (BRIGHT | MOVE); p.event = fade_mist; }
action misty_sphere() // attach this action to your sphere model { set (my, PASSABLE | TRANSLUCENT); // make the sphere passable and transparent my.alpha = 40; // play with this value while (1) { effect(mist_function, 5, my.x, nullvector); wait (1); } }
Q: With c_scan, I can only scan static lights... how can i scan for dynamic lights? A: Create your dynamic lights using entities; make them invisible and passable if you need to. Then, use the snippet below.
action players_code() // sample player code { var anim_percentage, distance_to_ground; VECTOR movement_speed, temp; player = my; while (1) { c_scan(my.x, my.pan, vector(360, 180, 300), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME); // scan for lights camera.x = player.x - 250 * cos(player.pan); camera.y = player.y - 250 * sin(player.pan); camera.z = player.z + 150; camera.pan = player.pan; camera.tilt = -20; my.pan += 6 * (key_a - key_d) * time_step; vec_set (temp, my.x); temp.z -= 5000; distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX); movement_speed.x = 5 * (key_w - key_s) * time_step; movement_speed.y = 0; movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value movement_speed.z = maxv (-35 * time_step, movement_speed.z); // 35 = falling speed c_move (my, movement_speed.x, nullvector, GLIDE); if (!key_w && !key_s) { ent_animate(my, "stand", anim_percentage, ANM_CYCLE); } else // the player is moving? { ent_animate(my, "walk", anim_percentage, ANM_CYCLE); } anim_percentage += 5 * time_step; // 5 = animation speed wait (1); } }
function change_color() { vec_set(my.blue, vector(0, 0, 255)); // change to red light }
action my_light() { vec_set(my.blue, vector(255, 255, 255)); // white light my.emask = ENABLE_SCAN; my.event = change_color; while(1) { my.lightrange = 500; // set a light range of 500 quants wait (1); } }
Q: I would like to be able to set the colors for the cars in my racing game by clicking them, and the choosing one of the options from a menu. A: Here's the code that does what you want.
VECTOR* car_pos[3];
BMAP* pointer_tga = "pointer.tga"; BMAP* red1_pcx = "red1.pcx"; BMAP* red2_pcx = "red2.pcx"; BMAP* green1_pcx = "green1.pcx"; BMAP* green2_pcx = "green2.pcx"; BMAP* blue1_pcx = "blue1.pcx"; BMAP* blue2_pcx = "blue2.pcx";
ENTITY* active_car;
function set_red(); function set_green(); function set_blue();
PANEL* carcolor_pan = { bmap = "carcolor.pcx"; button = 0, 12, red2_pcx, red1_pcx, red2_pcx, set_red, NULL, NULL; button = 0, 24, green2_pcx, green1_pcx, green2_pcx, set_green, NULL, NULL; button = 0, 36, blue2_pcx, blue1_pcx, blue2_pcx, set_blue, NULL, NULL; }
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
function set_red() { active_car.red = 255; active_car.green = 0; active_car.blue = 0; }
function set_green() { active_car.red = 0; active_car.green = 255; active_car.blue = 0; }
function set_blue() { active_car.red = 0; active_car.green = 0; active_car.blue = 255; }
function display_menu() { active_car = my; vec_set(car_pos, my.x); vec_to_screen(car_pos, camera); carcolor_pan.pos_x = car_pos.x; carcolor_pan.pos_y = car_pos.y; carcolor_pan.flags |= SHOW; }
action colored_car() { my.emask |= ENABLE_CLICK; my.event = display_menu; set (my, LIGHT); }
Q: I'd like to have a ball that moves freely in the level and kills all the enemies that it is touching. A: Here's a simple example.
function ball_collides() { // the ball has collided with one of the entities in the level? if (event_type == EVENT_ENTITY) { if (you.skill1 == 999) // collided with one of the enemies? { you.skill1 = 0; // then remove it! } } // change the direction even if the ball has only collided with a level block vec_to_angle(my.pan,bounce); // add a slightly random value to the pan angle each time, in order to prevent the ball from getting stuck my.pan += 10 - random(20); }
action bouncing_ball() { my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); // make the entity sensitive to collisions with level blocks and entities my.event = ball_collides; while(1) { c_move(my, vector(10 * time_step, 0, 0),nullvector, NULL); // 10 gives the ball movement speed wait(1); } }
action my_enemies() { my.skill1 = 999; // this value identifies an enemy while (my.skill1 == 999) {wait (1);} ent_remove (my); }
|