Fragen aus dem Forum

Top  Previous  Next

F: Ich würde gern verschiedene Bilder in zufälliger Reihenfolge anzeigen, abhängig von dem Wert einer zufälligen Variable.

A: Hier ist ein Beispiel.

 

bmap picture1_pcx = <picture1.pcx>;

bmap picture2_pcx = <picture2.pcx>;

bmap picture3_pcx = <picture3.pcx>;

bmap picture4_pcx = <picture4.pcx>;

bmap picture5_pcx = <picture5.pcx>;

 

panel picture_pan

{

       layer = 10;

       pos_x = 100; // use your own values here

       pos_y = 100;

       flags = visible;

}

 

starter change_pictures()

{

       while (1)

       {

               temp = 1 + int (random(5));

               if (temp == 1)

               {

                       picture_pan.bmap = picture1_pcx;

               }

               if (temp == 2)

               {

                       picture_pan.bmap = picture2_pcx;

               }

               if (temp == 3)

               {

                       picture_pan.bmap = picture3_pcx;

               }

               if (temp == 4)

               {

                       picture_pan.bmap = picture4_pcx;

               }

               if (temp == 5)

               {

                       picture_pan.bmap = picture5_pcx;

               }

               sleep (2); // change the picture every 2 seconds, play with this value

       }

}

 

 

F: Können Sie mir erklären, was vec_rotate ist und wie man es verwendet?

A: Vec_rotate dreht einen Vektor (die Position der Kamera im folgenden Beispiel) um die Winkel, die durch einen zweiten Vektor gegeben sind (vector(-300, -50, 70) in meinem Beispiel). Hier ist eine kleine Funktion, die dafür sorgt, dass die Kamera dem Spieler in einem vorgegebenen Abstand folgt; der Workshop in AUM 54 enthält mehr Informationen und Bilder.

 

starter follow_player()

{

       while (player == null) {wait (1);} // wait until the player is created

       while (1)

       {

               vec_set (camera.x, vector (-300, -50, 70)); // play with these values

               vec_rotate (camera.x, player.pan);

               vec_add (camera.x, player.x);

               camera.pan = player.pan; // only if you need this as well

               wait (1);

       }

}

 

aum60_faq1

 

 

F: Haben Sie zufällig Code für einen Partikeleffekt, der bei einem bestimmten Vertex eines Models beginnt und sich aufwärts bewegt?

A: Hier ist ein Beispiel.

 

bmap smoke_tga = <smoke.tga>;

 

function fade_smoke()

{

       my.alpha -= 0.15 * time; // particle fading speed

       if (my.alpha < 0) {my.lifespan = 0;}

}

 

function smoke_effect()

{

       temp.x = random(1) - 0.5; // move a bit on the x

       temp.y = random(1) - 0.5; // and y axis

       temp.z = random(2); // but always move upwards on the z axis

       vec_add (my.vel_x, temp);

       my.alpha = 10 + random(20);

       my.bmap = smoke_tga;

       my.size = 40; // size of the smoke

       my.bright = on;

       my.move = on;

       my.lifespan = 350; // lifespan for the smoke particles

       my.function = fade_smoke;

}

 

starter generate_smoke()

{

       while (player == null) {wait (1);}

       while (1)

       {

               vec_for_vertex (temp, player, 246); // generate smoke from the 246th vertex on the player model

               // create more smoke particles on more powerful computers

               effect (smoke_effect, (2 / (time_step + 0.1)), temp.x, normal);

               wait (1);

       }

}

 

aum60_faq2

 

 

F: Ich brauche ein Bitmap für Bonuspunkte, das auf dem Bildschirm erscheint und sich dann aufwärts bewegt und verblasst, bevor es den oberen Rand erreicht.

A: Bitte schön:

 

bmap bonus_pcx = <bonus.pcx>;

 

panel bonus_pan

{

       bmap = bonus_pcx;

       layer = 20;

       flags = transparent;

}

 

function generate_bonus()

{

       bonus_pan.pos_x = 400; // use your own x and y values here

       bonus_pan.pos_y = 500;

       bonus_pan.alpha = 100;

       bonus_pan.visible = on;

       while (bonus_pan.pos_y > 0) // scroll the panel upwards

       {

               bonus_pan.pos_y -= 10 * time_step; // 10 = vertical scrolling speed

               bonus_pan.pos_x -= 3 * time_step; // 3 = horizontal scrolling speed, use positive values as well

               bonus_pan.alpha -= 2.5 * time_step; // 2.5 = fading speed

               bonus_pan.alpha = clamp (bonus_pan.alpha, 0, 100); // limit the alpha to 0...100

               wait (1);

       }

}

 

on_b = generate_bonus; // call this function from within your game or press "B" to generate a bonus bitmap

 

 

F: Ich brauche eine Funktion, die Text aus einer Datei liest und in einen String kopiert. Können Sie da helfen?

A: Sicher. Hier ist ein Ausschnitt.

 

string info_string[100]; // store up to 100 characters

 

text mytext

{

       pos_x = 200;

       pos_y = 20;

       font = _a4font; // feel free to use any other previously defined font

       string = info_string; // this text shows the content of info_string

       flags = visible;

}

 

function read_text()

{

       var text_handle;

       text_handle = file_open_read("mytext.txt"); // create a file named mytext.txt and put your text inside it

       file_str_read(text_handle, info_string); // read the text and store it inside info_string

       file_close (text_handle); // now close the file

}

 

// press the "R" key to read the text or call function read_text() from within your game when you need it

on_r = read_text;

 

 

F: Ist es möglich, den Spieler auf einer Kugeloberfläche laufen zu lassen?

A: Falls Ihr Spiel in der Egoperspektive läuft, können Sie das simulieren, indem Sie die Kugel drehen und den Spieler an einer Position belassen, das funktioniert. Für eine Außenkamera benötigen Sie Ihren eigenen (komplexen) Bewegungscode, der in einer Schleife den Winkel des Spieler an die Normale der Oberfläche angleicht, in etwa so wie unten gezeigt.

 

temp.tilt = 0;

temp.roll = 0;

temp.pan = -my.pan;

vec_rotate(normal, temp);

temp.tilt = -asin(normal.x);

temp.roll = -asin(normal.y);

my.tilt += 0.5 * ang(temp.tilt - my.tilt); // play with 0.5

my.roll += 0.5 * ang(temp.roll - my.roll); // play with 0.5

 

Die Geschwindigkeit des Spielers in x, y und z-Richtung müssen abhängig vom Tilt korrekt berechnet werden.

 

 

F: Wie kann ich ein Model um einen Vertex drehen?

A: Hier ist der Code dafür.

 

var init_position; // position of the needed vertex

var rotation_radius = 30;

 

string guard_mdl = <guard.mdl>;

 

function rotate_around()

{

       while (1)

       {

               my.skill1 += 3 * time;

               my.y = init_position.y + rotation_radius * cos(my.skill1); // you can use any combination of x, y, z here

               my.z = init_position.z + rotation_radius * sin(my.skill1);

               wait (1);                

       }

}

 

action master_blaster

{

       vec_for_vertex (init_position, my, 246); // get the position of the rotation center

       ent_create (guard_mdl, my.x, rotate_around); // create the model that will rotate around that point

}

 

 

F: Wie kann ich Text einlesen, z.B. für den Namen eines Spielers unter der Gesundheitsanzeige?

A: Hier ist entsprechender Code.

 

string players_str = "                    "; // use up to 20 characters for the name

 

text players_txt

{

       layer = 30;

       pos_x = 20; // use proper x and y values here

       pos_y = 50; // make sure that the blinking cursor appears below player's health bar

       font = _a4font; // use any other previously defined font here

       string = players_str;

}

 

function player_name_input()

{

       players_txt.visible = on; // show the text

       str_cpy (players_str, "");

       while (str_cmpi (players_str, "") == 1) // make sure that the player has typed something

       {

               inkey (players_str); // show the cursor -> store the input in players_str

               wait (1);

       }

       players_txt.visible = on; // show the text

}

 

on_p = player_name_input; // press "P" to input player's name

 

 

F: Wie kann ich ein Objekt relativ zu den lokalen Koordinaten einer Entity plazieren anstatt die globalen Koordinaten zu verwenden?

A: Hier ist ein Codeschnipsel als Grundlage.

 

action dummy_player

{

       player = my;

}        

 

action follow_player

{

       // keeps the entity 50 quants ahead of its master, 20 quants sideways and 15 quants above master's origin

       var entity_offset[3] = 50, 20, 15;

       my.passable = on; // not really needed, but might come in handy for some objects

       while (player == null) {wait (1);} // wait until the player is created (you can use any other entity here)

       while (1)

       {

               vec_set (my.x, entity_offset.x);

               vec_rotate (my.x, player.pan);

               vec_add (my.x, player.x);

               my.pan = player.pan;

               wait (1);

       }

}

 

 

F: In meinem Spiel gibt es einen Sumpf. Wenn sich der Spieler über diesen Block bewegt, soll das Geräusch swamp.wav ertönen. Wie ist das möglich?

A: Nutzen Sie moderne Technologie (A6) und das folgende Skript:

 

var swamp_handle;

 

sound swamp_wav = <swamp.wav>;

 

action player1 // attach this action to your player model

{

       var movement_speed = 7; // movement speed

       var distance_covered = 0;

       player = my; // I'm the player

       my.invisible = on;

       while (1)

       {

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

               camera.x = my.x;

               camera.y = my.y;

               camera.z = my.z + 50 + 1.1 * sin(my.skill44); // play with 50 and 1.1

               camera.pan = my.pan;

               camera.tilt += 5 * mouse_force.y * time;

               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 | scan_texture) + 20;

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

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

               distance_covered = c_move (my, temp.x, nullvector, ignore_passable | glide);

               if (key_w + key_s > 0) // if the player is walking

               {

                       my.skill44 += 25 * time;

                       ent_cycle("walk", my.skill46); // play its "walk" frames animation

                       my.skill46 += 5 * time;

                       my.skill46 %= 100; // loop the animation

               }

               else // if the player is standing

               {

                       ent_cycle("stand", my.skill48); // play the "stand" frames animation

                       my.skill48 += 2 * time; // "stand" animation speed

                       my.skill48 %= 100; // loop animation

               }

               // use any other name for the swampy texture; I have used "tiles3" from standard.wad in this example

               if ((str_cmpi ("tiles3", tex_name)) && (distance_covered > 0)) // moving over the tiles3 (swamp) texture?

               {

                       if (snd_playing (swamp_handle) == null) // swamp.wav isn't being played at the moment?

                       {

                               swamp_handle = snd_play (swamp_wav, 40, 0); // then play it!

                       }                        

               }

               wait (1);

       }

}