Questions from the forum |
Top Previous Next |
Q: Have you got a small clipping range example for us? A: Here's a simple function that uses clipping and white fog to hide it.
starter set_clipping() { sleep (1); // wait a bit d3d_fogcolor1.red = 255; // set up white fog d3d_fogcolor1.green = 255; d3d_fogcolor1.blue = 255; fog_color = 1; // and enable it camera.clip_near = 10; // experimental value, play with it camera.clip_far = 10000; // clip everything outside the 10000 quants radius, play with 10000 camera.fog_start = 100; // experimental value, play with it camera.fog_end = 0.95 * camera.clip_far; // put dense fog close to the end of the clipping area }
Q: I can't figure out how to run the older Aum scripts in full screen mode. They keep appearing as a large window. How do I fix this? A: Place this line at the beginning of the script(s):
var video_screen = 1;
Q: How can you make an entity face another entity that triggered an event? The rotation should be progressive, using the pan angle. A: Use the following example.
function rotate_me { my.event = null; // trigger a single event while (you != null) { vec_set (temp.x, you.x); vec_sub (temp.x, my.x); vec_to_angle (my.skill40, temp); // use any free skill here my.pan -= ang(my.pan - my.skill40) * 0.1 * time; // 0.1 = rotation speed wait (1); } }
action trigger_me { my.enable_trigger = on; my.trigger_range = 200; my.event = rotate_me; }
Q: I am trying to make a simple 'collect 10 items and win' type game but really don't have a clue about coding. I would like an audio file to play every time I collect an item and I'd like a music file and splash screen to appear when all the items are collected. A: Use this snippet:
var items_to_collect = 10; var items_collected = 0;
sound collected_wav = <collected.wav>; sound completed_wav = <completed.wav>;
bmap completed_pcx = <completed.pcx>;
panel completed_pan { bmap = completed_pcx; layer = 20; flags = overlay, refresh; }
action collectable_item // place 10 objects in the level and assign them this action { my.passable = on; while (player == null) {wait (1);} while (vec_dist (player.x, my.x) > 70) {wait (1);} snd_play (collected_wav, 50, 0); items_collected += 1; my.invisible = on; sleep (2); // wait until the entire sound has been played ent_remove (my); // now we can safely remove the entity }
starter objects_are_collected() { while (items_to_collect != items_collected) {wait (1);} sleep (1); snd_play (completed_wav, 100, 0); completed_pan.visible = on; }
Q: I have spent hours trying to figure out how I can add jumping to your code from Aum52's workshop. Can you help? A: Replace action players_code with the one below:
action players_code { var anim_percentage; // animation percentage var jump_percentage; // animation percentage for jumping var movement_speed; // player's movement speed var distance_to_ground; // the distance between player's origin and the ground var jump_height; var reached_height; player = my; // I'm the player while (1) { my.pan += 6 * (key_a - key_d) * time; // rotate the player using the "A" and "D" keys vec_set (temp.x, my.x); // copy player's position to temp temp.z -= 5000; // set temp.z 5000 quants below player's origin distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box); movement_speed.x = 5 * (key_w - key_s) * time; // move the player using "W" and "S" movement_speed.y = 0; // don't move sideways if ((key_space == on) && (reached_height == 0)) { jump_height = min(40, jump_height + 5 * time); // 40 sets the height, 5 sets the ascending speed if (jump_height == 40) // reached the maximum height? Then start descending! { reached_height = 1; jump_height = max(0, jump_height - 5 * time); // 5 sets the falling speed } } else // space isn't pressed anymore? { jump_height = max(0, jump_height - 3 * time); // use a smaller falling speed (3) for (potential) smaller jumps if ((jump_height == 0) && (key_space == off)) // the player has touched the ground? { reached_height = 0; // then allow it to jump again } } movement_speed.z = - (distance_to_ground - 17) + jump_height; // 17 = experimental value movement_speed.z = max (-35 * time, movement_speed.z); // 35 = falling speed c_move (my, movement_speed.x, nullvector, glide); // move the player if (jump_height == 0) // the player isn't jumping? { if ((key_w == off) && (key_s == off)) // the player isn't moving? { ent_animate(my, "stand", anim_percentage, anm_cycle); // play the "stand" animation } else // the player is moving? { ent_animate(my, "walk", anim_percentage, anm_cycle); // play the "walk" animation } anim_percentage += 5 * time; // 5 = animation speed jump_percentage = 0; // always start jumping with the first frame } else // the player is jumping { jump_percentage += 5 * time; // 5 = jump animation speed ent_animate(my, "jump", jump_percentage, anm_cycle); // play the "jump" animation } wait (1); } }
Q: How can I let 3DGS check if the game has been started with a specific command line (parameter)? If the parameter is missing I'd like to show a panel which says that the game wasn't started with the needed shortcut. A: Use this example:
bmap error_pcx = <error.pcx>;
panel error_pan { bmap = error_pcx; flags = overlay, refresh; }
function main() { ifndef hq; // the user didn't start the engine using the "-d hq" = high quality parameter error_pan.visible = on; // tell the user that he has forgotten to start the engine using the "hq" option while (key_any == off) {wait (1);} // wait until the user presses a key exit; // and then shut down the engine ifelse; // the user has used the "hq" command line video_switch(8, 0, 0); // so let's switch to 1024x768 pixels endif; // function main continues here ...................... }
Q: Is there any way to stop my character from going through parts of my models? if I make a table the model goes through it until it hits a certain point or it can't get around the model because it's like a barrier around it. A: What you are seeing is the invisible bounding box of the model, which is used for faster collision detections. Use a wmb entity instead of a model for your table or attach the following action to it. Don't forget to move your entities using c_move; otherwise, you won't be able to use the new, polygon-based collision detection system.
action proper_collision { my.polygon = on; }
Q: I've made a menu for my game with an "options" section. What's the best way to save the settings so that they don't reset back to the defaults every time the game is run? A: Use this example:
var filehandle; var video_resolution;
// run function save_settings at least once before running load_settings // otherwise, you won't have any settings.txt file to read from function save_settings() // call this function before exiting the game { filehandle = file_open_write("settings.txt"); file_var_write (filehandle, video_mode); // save the video resolution file_asc_write (filehandle, 13); // move on to the following line file_asc_write (filehandle, 10); file_var_write (filehandle, sound_vol); // save the sound volume file_asc_write (filehandle, 13); // move on to the following line file_asc_write (filehandle, 10); file_var_write (filehandle, midi_vol); // save the midi volume file_close(filehandle); // close the file }
// call this from function main() function load_settings() { sleep (1); filehandle = file_open_read("settings.txt"); // open the settings.txt file video_resolution = file_var_read(filehandle); // read the video resolution video_switch(video_resolution, 0, 0); // set the new video resolution sound_vol = file_var_read(filehandle); // set the volume of the sound midi_vol = file_var_read(filehandle); // set the volume of the midi music file_close(filehandle); // close the file; }
Q: I want to play a sound with a random change of frequency. When I do that, the frequency of the other sounds that are played in my game is changed as well. How can I stop that? A: Examine the snippet below; it uses a sound that changes its frequency and another one that keeps its frequency.
sound siren1_wav = <siren1.wav>; sound siren2_wav = <siren2.wav>;
action variable_freq { var sound_handle; sound_handle = ent_playloop (my, siren1_wav, 40); while (1) { snd_tune (sound_handle, 0, (10 + random(290)), 0); // change the frequency from 10% to 300% sleep(1); } }
action fixed_freq { var sound_handle; sound_handle = ent_playloop (my, siren2_wav, 100); }
Q: I was wondering how do you create a button that plays a full screen movie and then, only once the video is finished, loads a level. A: Use this example:
var movie_handle;
bmap movie_pcx = <movie.pcx>; bmap playmovie1_pcx = <playmovie1.pcx>; bmap playmovie2_pcx = <playmovie2.pcx>;
function play_the_movie();
panel movie_pan { bmap = movie_pcx; layer = 5; button = 50, 150, playmovie2_pcx, playmovie1_pcx, playmovie2_pcx, play_the_movie, null, null; flags = overlay, refresh, visible; }
function play_the_movie() { movie_pan.visible = off; movie_handle = media_play("test.avi", null, 100); while (media_playing (movie_handle) == 0) {wait (1);} // wait until the movie starts playing while (media_playing (movie_handle) != 0) {wait (1);} // wait until the movie has stopped beep; beep; // load your new level here }
|