Q: How can I add another animation to your sword combat code in Aum12?
A: The modified function below adds "jump" to the code:
action player_fight // attached to the player
{
player = me; // I'm the player
player.healthpoints = 100; // and I have 100 health points
while (player.healthpoints > 0) // as long as I'm alive
{
camera.x = player.x - 200 * cos(player.pan); // 200 = distance between the player and the camera
camera.y = player.y - 200 * sin(player.pan); // same value here
camera.z = 200; // above the player
camera.pan = player.pan; // looks in the same direction with the player
camera.tilt = -30; // look down at the player
my.pan += 4 * (key_a - key_d) * time - 20 * mouse_force.x * time; // rotates with the keys A and D or with the mouse
player_distance.x = 10 * (key_w - key_s) * time; // moves forward / backward with W / S
player_distance.y = 0;
player_distance.z = 0;
if ((key_w == 1) || (key_s == 1)) // the player is walking
{
ent_cycle("walk", my.skill20); // play walk frames animation
my.skill20 += 4 * time; // "walk" animation speed
if (my.skill20 > 100) {my.skill20 = 0;} // loop animation
}
if (key_space == 1) // space to jump
{
ent_cycle("jump", my.skill20);
my.skill20 += 3 * time; // "jump" animation speed
if (my.skill20 < 100)
{
player_distance.z += 0.04 * time;
}
}
if (key_any == 0) // the player is standing
{
player_distance.z = 0;
ent_cycle("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
ent_move(player_distance, nullvector);
if (mouse_left == 1) // if we press the left mouse button
{
my.skill22 = 0; // reset "attack" frames
while (my.skill22 < 100)
{
ent_vertex(my.sword_tip, 315); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 293); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable; // ignore me (the player) and all the entities that are passable
trace (my.sword_base, my.sword_tip); // trace between these sword positions
if (result != 0) // the player has hit something
{
effect (particle_sparks, 10, target, normal);
if (you != null) {you.healthpoints -= 6 * time;} // if it hasn't hit a wall, decrease health
ent_playsound (my, sword_snd, 50); // sword sound
}
ent_cycle("attack", my.skill22); // play attack frames animation
my.skill22 += 8 * time; // "attack" animation speed
wait (1);
}
while (mouse_left == 1) {wait (1);} // can't use autofire on a sword :)
}
wait (1);
}
while (my.skill23 < 90) // the player is dead
{
ent_cycle("death", my.skill23); // play death frames animation
my.skill23 += 3 * time; // "death" animation speed
wait (1);
}
my.passable = on; // the corpse can't be hit by the enemy sword from now on
}
Q: How would I get a sound to initiate when an object passes within a certain radius of a model, and a different event to occur when it hits the model?
A: Here's a sample:
function i_am_hit();
action my_object
{
my.enable_impact = on;
my.enable_entity = on;
my.event = i_am_hit;
while (1)
{
temp.pan = 360;
temp.tilt = 180;
temp.z = your_scanning_distance;
scan_entity (my.x, temp);
if ((result < your_scanning_distance)
{
do_your_stuff;
}
waitt (4); // scans 4 times a second
}
}
function i_am_hit()
{
snd_play (hit_snd, 70, 0);
}
Q: Is there a way of making an invisible block which allows the player to pass through but not the enemy actors. The player still needs to be able to shoot through it ?
A: Yes, you can use a model and set different push values for it, for the player and for the enemies.
Q: How can i create flying enemies?
A: Take a good look at the chopper code in this Aum edition; it covers horizontal and vertical movement, collision detection, shooting and being shot, etc.
Q: I would like to click the mouse and have the mouse click go through one panel, but be intercepted by the panel below; the mouse is holding an object which is in fact a panel.
A: Create the object as an "entity" - this way it will look like a panel but you'll be able to change its position on x, y, z without any problem.
Q: I've been working on a little clock script and got all the parts to work pretty well; how can I get the names of weekdays or months to show up?
A: Here's an example - store the days of the week and the months as strings:
.........
if (sys_dow == 1)
{
.................
display_monday
}
.........................
if (sys_dow == 7)
{
.................
display_sunday
}
.........
if (sys_month == 1)
{
.................
display_january
}
.........................
if (sys_month == 12)
{
.................
display_december
}
Q: Is it possible to shoot from two different vertices at the same time?
A: Yes, it is - here's an example:
var lefthand_gun;
var righthand_gun;
function player_shoots();
function player_bullets();
action player
{
...........
while (1)
{
....................
vec_for_vertex(lefthand_gun, my, 6); // shoot from vertex 6
vec_for_vertex(righthand_gun, my, 26); // and from vertex 26
....................
if (mouse_left == 1)
{
player_shoots();
while (mouse_left == 1) {wait (1);}
}
...................
wait (1);
}
}
function player_shoots()
{
ent_create (bullet_mdl, lefthand_gun, player_bullets);
ent_create (bullet_mdl, righthand_gun, player_bullets);
}
function player_bullets()
{
this_function_moves_the_bullets
}
Q: Is there a script to make the background music throughout the game but I don't want midi, I prefer .wav
A: You can use something like this to play the song once:
sound mymusic_snd = <mymusic.wav>;
// put this line at the end of your main function:
snd_play (mymusic_snd, 40, 0);
or something like this to play the song in a loop:
function start_music();
sound mymusic_snd = <mymusic.wav>;
var music_handle;
// call it at the end of your main function
function start_music()
{
while (1)
{
if (music_handle == 0)
{
snd_loop (mymusic_snd, 40, 0);
music_handle = result;
}
wait (1);
}
}
Q: I use the campath script in Aum6 for the intro in my game and I need to load a new level when the camera reaches a certain area. How can I do that?
A: I will assume that you want to load a new level when camera's x coordinate reaches 2000.
action cutcamera_init
{
..................
// add some spices
if (camera.x > 2000) // get this value in Wed
{
level_load(my_new_level_wmb);
}
wait(1);
}
}
Q: How can I use your random forest script in Aum12 if the level isn't centered in the origin?
A: Here's Mirek Thier's answer:
// we add 2 new variables
var max_min_x_dif; // difference between max and min numerical x value
var max_min_y_dif; // difference between max and min numerical y value
function generate_forest()
{
randomize(); // always generate a different forest
while (tree_index < num_trees)
{
max_min_x_dif = max_x - min_x;
max_min_y_dif = max_y - min_y;
max_min_x_dif = random (max_min_x_dif);
max_min_y_dif = random (max_min_y_dif);
tree_pos.x = min_x + max_min_x_dif;
tree_pos.y = min_y + max_min_y_dif;
tree_pos.z = 1000; // 1000 quants above the floor level
tree_index += 1;
if (random(1) > 0.5)
{
ent_create (treeold1_mdl, tree_pos, create_tree);
}
else
{
ent_create (treeold2_mdl, tree_pos, create_tree);
}
ifdef fun;
waitt (8);
endif;
}
}
|