Fragen aus dem Forum

Top  Previous  Next

F: Wie kann ich mehrere Musikstücke nacheinander so abspielen, dass sie in einer Schleife laufen?

A: Hier ist ein Beispiel.

 

var track_handle;

 

starter game_music()

{

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

       while (1)

       {

               track_handle = media_play("track1.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               track_handle = media_play("track2.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               track_handle = media_play("track3.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               track_handle = media_play("track4.mid", null, 50);

               while (media_playing(track_handle)) {wait (1);}

               wait (1);

       }

}

 

 

F: Wie kann ich ein Objekt in meinem Strategiespiel hervorheben, wenn die Maus darüber bewegt wird?

A: Benutzen Sie diesen Ausschnitt.

 

function highlight_me()

{

       if (event_type == event_touch)

       {

               my.ambient = 100; // highlight the unit

       }

       while (event_type != event_release) {wait (1);}

       my.ambient = 0;

}

 

action my_unit

{

       my.enable_touch = on;

       my.enable_release = on;

       my.event = highlight_me;

}

 

 

F: Wie kann ich eine “while” Schleife eine bestimmte Anzahl Sekunden laufen lassen?

A: Benutzen Sie dieses Beispiel.

 

function countdown_timer()

{

       var time_passed = 12; // the loop will run for 12 seconds

       while (time_passed > 0)

       {

               time_passed -= time / 16; // decrease time_passed every frame

               // do something useful here for 12 seconds

               camera.ambient = random(100); // now that's useful stuff!

               wait (1);

       }

       // the action would goes on here after 12 seconds

}

 

on_c = countdown_timer; // press "C" to run the function

 

 

F: Wie bekomme ich einen gut aussehenden Fackel Effekt hin?

A: Hier ist ein Codebeispiel.

 

bmap fire_tga = <fire.tga>;

bmap smoke1_tga = <smoke1.tga>;

bmap smoke2_tga = <smoke2.tga>;

 

function fire_effect();

function fade_flames();

function smoke_effect();

function fade_smoke();

 

action my_torch

{

       my.passable = on;

       while (1)

       {

               vec_set(temp.x, my.x);

               vec_add(temp.x, vector(random(2) - 4, random(2) - 4, 25 + random(3))); // play with 25

               effect (fire_effect, 10 * time, temp.x, normal); // play with 10

               if (random(1) > 0.85)

               {

                       temp.z += 5 + random(5); // play with 5

                       effect (smoke_effect, 1, temp.x, normal);

               }

               my.lightrange = 200;

               my.lightred = 200;

               my.lightgreen = 150 + random(50);

               my.lightblue = 100;

               wait (1);

       }

}

 

function fire_effect()

{

       temp.x = random(4) - 2;

       temp.y = random(4) - 2;

       temp.z = random(2); // play with 2

       vec_add (my.vel_x, temp);

       my.alpha = 20 + random(80);

       my.bmap = fire_tga;

       my.size = 25; // play with 25        

       my.bright = on;

       my.move = on;

       my.lifespan = 5;

       my.function = fade_flames;

}

 

function fade_flames()

{

       my.vel_x /= 2;

       my.alpha -= 2 * time;

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

}

 

function smoke_effect()

{

       temp.x = random(1) - 0.5;

       temp.y = random(1) - 0.5;

       temp.z = random(1); // play with 1

       vec_add (my.vel_x, temp);

       my.alpha = 20 + random(20);

       if (random(1) > 0.7)

       {

               my.bmap = smoke2_tga;

       }

       else

       {

               my.bmap = smoke1_tga;        

       }

       my.size = 20; // play with 20

       my.bright = on;

       my.move = on;

       my.lifespan = 500;

       my.function = fade_smoke;

}

 

function fade_smoke()

{

       my.alpha -= 0.2 * time; // play with 0.2

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

}

 

aum54_faq1

 

 

 

F: Kann ich zum Spielstart einen Film (mein Logo) abspielen und dann ins Hauptmenü wechseln?

A: Hier ist Code, der das leistet.

 

var logo_handle;

 

function main()

{

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

       logo_handle = media_play("logo.avi", null, 100); // play your logo movie

       while (media_playing(logo_handle)) {wait (1);} // wait until the movie has ended

       level_load (mylevel_wmb); // now load the level

       wait (3); // wait until the level is loaded

       mainmenu_pan.visible = on; // don't forget to define this panel first

       // put the rest of the code for function main here

}

 

 

F: Wie bekomme ich es hin, dass ein Objekt dem Spieler die ganze Zeit über folgt? Es wäre auch gut, wenn ich den Abstand festlegen könnte...

A: Hier ist ein Beispiel:

 

string follower_mdl = <follower.mdl>;

 

function follow_player()

{

       proc_late();

       while (1)

       {

               vec_set (my.x, vector (100, 50, 30)); // play with these values

               vec_rotate (my.x, player.pan);

               vec_add (my.x, player.x);

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

               wait (1);

       }

}

 

 

action player1

{

       player = my; // I'm the player

       ent_create (follower_mdl, my.x, follow_player);

       ................................

}

 

 

F: Ich würde gern das Umgebungslicht meines Levels mit dem Mausrad kontrollieren. Ist das überhaupt möglich?

A: Sicher. Hier ist der Code dazu.

 

starter set_ambient()

{

       while (1)

       {

               camera.ambient -= 0.2 * mickey.z * time;

               camera.ambient = min (max (camera.ambient, 0), 100); // limit camera.ambient to 0...100

               wait (1);

       }

}

 

 

F: Kennen Sie ein Tool, mit dem man roboterhafte Sprachausgabe hinbekommt?

A: Versuchen Sie es mit Saylt von AnalogX www.analogx.com

 

 

F: Ich möchte, dass eine Entity zum “player” wird, wenn man sie anklickt.

A: Hier ist ein Ausschnitt.

 

function become_player()

{

       player = my;

}

 

action potential_player // attach this action to several entities

{

       my.enable_click = on;

       my.event = become_player;

}

 

starter control_player()

{

       while (1)

       {

               if (player != null)

               {

                       player.pan += 1 * time;

               }

               wait (1);

       }

}

 

 

F: Wie kann ich ein Sprite mit ent_animate animieren? Ich sehe die Frames nicht!

A: Hier ist ein Beispiel.

 

action animated_sprite // attach this action to a sprite that contains several frames

{

       var anim_speed;

       while (1)

       {

               ent_animate(my, "test", anim_speed, anm_cycle); // put any animation name here ("test", "stand", whatever)

               anim_speed += 5 * time; // "5" controls the animation speed

               wait (1);

       }

}