Fragen aus dem Forum

Top  Previous  Next

F: Ich versuche, eine Rakete zu erstellen, die ihre Geschwindigkeit solange erhöht bis sie einen bestimmten Wert erreicht hat. Dann sollte sie damit aufhören und mit gleichbleibender Geschwindigkeit weiterfliegen.

A: Hier ist ein gutes Beispiel: eine Waffe, die die Geschwindigkeit verfolgt und dazu die im letzten Frame zurückgelegte Distanz verwendet (ein Wert, der von c_move zurückgeliefert wird.

 

var front_offset = 30; // animates player's weapon while it is firing by moving it backwards

var init_offset = 30; // stores front_offset's value

var distance_covered; // global variable, so that we can display it using a digit on a panel

var got_weapon1 = 0;

 

ENTITY* weapon1;

 

STRING* bullet_mdl = "bullet.mdl";

 

SOUND* bullet_wav = "bullet.wav";

 

function fire_bullets();

function move_bullets();

function remove_bullets();

 

action players_weapon() // place your weapon model in the level and attach it this action

{

       weapon1 = my; // I'm weapon1

       VECTOR player1_pos; // stores the initial position of the player

       VECTOR player2_pos; // stores the position of the player after a frame

       VECTOR weapon_offset;

       var weapon_height;

       set (my, PASSABLE); // the weapon model is passable

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

       while (vec_dist (player.x, my.x) > 50) {wait (1);} // wait until the player comes close to pick up the weapon

       got_weapon1 = 1;

       my.roll = 0;

       while (1)

       {

               vec_set (player1_pos.x, player.x); // store the initial player position

               // place the weapon 30 quants in front, 18 quants to the right and 20 quants below camera's origin

               vec_set (weapon_offset.x, vector (front_offset, -18, -20));

               if (vec_dist (player1_pos.x, player2_pos.x) != 0) // the player has moved during the last frame?

               {

                       weapon_height += 30 * time_step; // then offset weapon_height (30 = weapon waving speed)

                       weapon_offset.z += 0.3 * sin(weapon_height); // (0.3 = weapon waving amplitude)

               }

               // rotate weapon_offset according to the camera angles

               vec_rotate (weapon_offset.x, vector (camera.pan, camera.tilt, 0));

               vec_add (weapon_offset.x, camera.x); // add the camera position to weapon_offset

               vec_set (my.x, weapon_offset.x); // set weapon's coords to weapon_offset

               my.pan = camera.pan; // use the same camera angles for the weapon

               my.tilt = camera.tilt;

               vec_set (player2_pos.x, player.x); // store the new player coordinates after 1 frame

               wait (1);

       }

}

 

function weapon_startup()

{

       on_mouse_left = fire_bullets; // call function fire_bullets() when the left mouse button is pressed

}

 

function fire_bullets() // includes the code that animates the weapon as well

{

       if (!got_weapon1) return; // didn't get the weapon? Then don't allow the player to fire bullets!

       var temp_seconds = 0;

       VECTOR temp;

       proc_kill(4); // don't allow more than 1 copy of this function to run

       while (mouse_left) // this loop runs for as long as the left mouse button is pressed

       {

               front_offset -= 1; // move the weapon backwards a bit

               vec_for_vertex (temp.x, weapon1, 29); // get the coordinates for the bullets' origin

               // create the bullet at camera's position and attach it the "move_bullets" function

               ent_create (bullet_mdl, temp.x, move_bullets);

               temp_seconds = 0;

               snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100

               while (temp_seconds < 0.5)

               {

                       temp_seconds += time_step / 16; // adds 0.5 to temp_seconds in 0.5 seconds)

                       front_offset -= 0.1; // restore the position of the weapon

                       wait (1);

               }

               while (front_offset < init_offset)

               {

                       front_offset += 0.1; // restore the position of the weapon

                       wait (1);

               }

          front_offset = init_offset;

       }

}

 

function move_bullets()

{

       VECTOR bullet_speed; // stores the speed of the bullet

       my.skill30 = 1; // I'm a bullet

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);

       my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run

       my.pan = camera.pan; // the bullet has the same pan

       my.tilt = camera.tilt; // and tilt with the camera

       bullet_speed.x = 2 * time_step; // set the initial speed of the bullet here

       bullet_speed.y = 0; // the bullet doesn't move sideways

       bullet_speed.z = 0; // then don't allow the gravity to have its ways with the bullet

       while (my) // this loop will run for as long as the bullet exists (it isn't "null")

       {

               if (distance_covered < 100 * time_step) // increase bullet's speed until it reaches 100 * time_step;

                       bullet_speed.x += 3 * time_step; // 3 gives the speed growth / frame

               // move the bullet ignoring the passable entities and store the result in distance_covered

               distance_covered = c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);

               wait (1);

       }

}

 

function remove_bullets() // this function runs when the bullet collides with something

{

       wait (1); // wait a frame to be sure (don't trigger engine warnings)

       ent_remove (my); // and then remove the bullet

}

 

PANEL* distance_pan =

{

       layer = 15;

       digits(600, 20, 4.3 ,* , 1, distance_covered);

       flags = SHOW;

}

 

 

F: Könntest du bitte "Booker" aus AUM 72 in Ordnung bringen? Mit A8 funktioniert das nicht gut. Ich bekomme eine Empty-Pointer-Fehlermeldung und die Buchinfo wird nicht auf die Disk gespeichert.

A: Versuchen Sie es nochmal mit der neuesten A8-Version - Ich habe es gemacht und jetzt funktioniert es gut. Die Daten lassen sich unter Windows Vista und Windows 7 nicht auf die Disk speichern, wenn Sie nicht die passenden Rechte haben. Starten Siebei der Eingabeaufforderung secpol.msc und bringen Sie das Fenster "Local Security Policy" auf den Schrim. Stellen Sie die benötigten Benutzerrechte ein.

 

 

F: Können Sie mir zeigen wie ich eine Minikarte eines Levels mache? Ich hätte gerne einen kreisförmigen View, der den Player im Zentrum der Minikarte zeigt. Wenn ein NPC in den View kommt, taucht der NPC auch auf der Minikarte auft.

A: Bitteschön:

 

VIEW* minimap_view;

 

ENTITY* minimap_model =

{

       x = 100; // tweak these values until you set the desired position and size of the minimap view

       y = -40;

       z = 20;

       tilt = -90;

       type = "teler.mdl"; // use your own model here

       layer = 20;

       flags2 = SHOW; // show the model

}

 

function minimap_startup()

{

       while (!minimap_model) {wait (1);}

       minimap_view = view_create(10); // set the layer value for the view to 10

       wait (2);

       set (minimap_view, SHOW);

       // the view will have 256x256 pixels; increase these values and the skin of the minimap model if you need a higher resolution

       minimap_view.size_x = 256;

       minimap_view.size_y = 256;

       minimap_view.bmap = bmap_for_entity(minimap_model, 0);

       minimap_view.arc = 90; // play with this value

       vec_set(minimap_view.pan, vector(0, -90, 0)); // make the minimap view point downwards (tilt = -90)

       while (1)

       {

               // set the position of the minimap 300 quants above the player - use a bigger value here if you'd like to see a bigger area around the player

               vec_set(minimap_view.x, vector(player.x, player.y, player.z + 300));

               wait (1);

       }

}

 

aum95_questions1

 

 

F: Ich hätte gerne einen Feind mit einem Schwert, das den Player beschädigt, sobald es Kontakt mit dem Körper des Players bekommt.

A: Schauen Sie sich meinen Code-Schnipsel zum "Kung Fu Master"-Plug and Play aus AUM 93 an. Die Feinde beschädigen den Player indem sie von zwei Vertices ihrer Körper, Beine etc. aus "tracen" . Ersetzen Sie diese Vertices durch die Basis- bzw. Spitzen-Vertices des Feindschwerts und schon passt es.

 

 

Q: Ich hätte gerne zwei Panels, die unabhängig von der Videoauflösung in der oberen linken bzw. rechten Ecke des Bildschirms bleiben.

A: Hier ein einfaches und doch voll funktionierendes Beispiel:

 

BMAP* left_pcx = "left.pcx";

BMAP* right_pcx = "right.pcx";

 

PANEL* left_pan =

{

       bmap = left_pcx;

       layer = 15;

       pos_x = 0;

       pos_y = 0;

       flags = SHOW;

}

 

PANEL* right_pan =

{

       bmap = right_pcx;

       layer = 15;

       flags = SHOW;

}

 

function panels_startup()

{

       while (1)

       {

               right_pan.pos_x = screen_size.x - bmap_width(right_pcx);

               wait (1);

       }

}

 

 

F: Wie mache ich es, daß der Player mit den Wänden kollidiert und nicht durch sie hindurch geht? Ich weiß nicht wo ich da anfangen soll.

A: Objekte lassen sich entweder durch direktes Ändern ihrer Koordinaten bewegen wie bei "player.x += 1;", oder indem man den passenden Weg wählt: die "c_move"-Anweisung. Hier ein einfaches Beispiel, das Sie ihrem Player-Modell zuweisen können.

 

action players_code() // attach this action to your player model

{        

       var movement_speed = 20;

       VECTOR temp;

       set (my, INVISIBLE);

       player = my;

       while (1)

       {

               // simple player movement code with gravity - use WSAD to move the player and the mouse to look around / rotate

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

               vec_set (temp.x, my.x);

               temp.z -= 10000;

               temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 2;

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

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

               c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);

 

               // bonus - simple camera code! ;)

               camera.x = my.x;

               camera.y = my.y;

               camera.z = my.z + 50;

               camera.pan = my.pan;

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

               wait (1);

       }

}

 

 

F: Wie kann ich einem meiner Soldaten eine Waffe anheften?

A: Animieren Sie die Waffe zusammen mit dem Player und speichern Sie sie als separate Modelle. Wenn Sie Ihre animierte Waffe "solgun.mdl" genannt haben, brauchen Sie nur noch Ihrem Player die Aktion unten zuzuweisen.

 

STRING* soldiergun_mdl = "solgun.mdl";

 

function attach_weapon()

{

       proc_mode = PROC_LATE;

       set (my, PASSABLE);

       while(you)

       {

               vec_set(my.x, you.x);

               vec_set(my.pan, you.pan);

               my.frame = you.frame;

               my.next_frame = you.next_frame;

               wait(1);

       }

       ent_remove(my);

}

 

action my_soldier()

{

       var anim_percentage;

       ent_create(soldiergun_mdl, nullvector, attach_weapon); // give the soldier a gun

       while (1)

       {

               ent_animate(my, "walk", anim_percentage, ANM_CYCLE);

               anim_percentage += 4 * time_step; // "1" controls the "stand" animation speed

               c_move (my, vector(3 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

               my.pan += 2 * time_step; // "2" controls the rotation speed

               wait (1);

       }

}

 

aum95_questions2

 

 

F: Ich möchte, daß mein Player überall wo er die Richtung ändert eine Spur hinterläßt. Wie kann ich das mithilfe des Partikelsystems erreichen?

A: Hier ist ein voll funktionsfähiges Beispiel, das Staubpartikel generiert wann immer das Player-Modell sich dreht und zwar 30 Quants unterhalb seines Ursprungs.

 

BMAP* dust_tga = "dust.tga";

 

function fade_dust(PARTICLE *p)

{

       p.alpha -= 2 * time_step; // dust fading speed = 2

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

}

 

function dust_particle(PARTICLE *p)

{

       p->vel_x = 0; // slightly random

       p->vel_y = 0; // horizontal speed

       p->vel_z = random(1); // small vertical speed

       p.alpha = 70; // initial transparency, play with this value

       p.bmap = dust_tga;

       p.size = 10;

       p.flags |= (BRIGHT | MOVE);

       p.event = fade_dust;

}

 

action players_code() // attach this action to your player model

{        

       var movement_speed = 4;

       var anim_percentage;

       VECTOR temp;

       player = my;

       while (1)

       {

               vec_set (temp.x, my.x);

               temp.z -= 10000;

               temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 2;

               temp.x = movement_speed * (key_cuu - key_cud) * time_step;

               my.pan -= movement_speed * (key_cur - key_cul) * 0.3 * time_step;

               temp.y = 0;

               c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);

               camera.x = my.x;

               camera.y = my.y;

               camera.z = my.z + 500;

               camera.pan = my.pan;

               camera.tilt = -90;

               if (key_cuu + key_cud) // one of the movement keys is being pressed?

                       ent_animate(my, "walk", anim_percentage, ANM_CYCLE);

                       anim_percentage += 4 * time_step; // "1" controls the "stand" animation speed

               if (key_cul + key_cur) // one of the rotation keys is being pressed?

                       effect (dust_particle, 3, vector(my.x, my.y, my.z - 30), normal); // generate dust particles 30 quants below the origin of the model

               wait (1);

       }

}

 

aum95_questions3

 

 

F: Ich muß wissen, wie man eine Tür öffnet wenn der Player die Sicherheitskarte bekommen hat.

A: Voila:

 

var got_card = 0;

 

SOUND* gotcard_wav = "gotcard.wav";

 

action my_card() // attach this action to your card model

{

       set (my, PASSABLE);

       while (!player) {wait (1);}

       while (vec_dist (player.x, my.x) > 100) // wait until the player comes close to the card

       {

               my.pan += 4 * time_step; // rotate the card around its pan angle until the player gets it

               wait (1);

       }

       snd_play(gotcard_wav, 60, 0);

       set (my, INVISIBLE); // the player has picked up the card, so hide it

       got_card = 1;

}

 

action my_door() // attach this action to your door entity

{

       VECTOR door_coords;

       vec_set (door_coords.x, my.x); // store the initial door position

       while (!got_card) {wait (1);} // wait until the player picks up the card

       while (vec_dist (player.x, my.x) > 150) {wait (1);} // wait until the player comes closer than 150 quants to the door

       while (my.x < door_coords.x + 80) // 80 gives the sideway movement (door offset) - play with this value

       {

               my.x += 3 * time_step; // 3 gives the door sliding speed - play with it

               wait (1);

       }

}

 

 

F: Bitte helft mir, ein Panel ein- und auszublenden. Ich habe ein Hauptmenü und Knöpfe. Wenn ich einen bestimmten Knopf drücke, möchte ich, daß das Hauptmenü ausblendet und dafür ein anderes Panel eingeblendet wird.

A: Hier ein Schnipselchen, das macht, was Sie wünschen:

 

var main_alpha = 100; // stores the transparency value for the "main" panel

var options_alpha = 0; // stores the transparency value for the "options" panel

 

BMAP* pointer_tga = "pointer.tga";

 

function new_game();

function exit_game();

 

PANEL* main_pan =

{

       layer = 10;

       bmap = "main.jpg";

       pos_x = 0;    

       pos_y = 0;   

       button (250, 100, "newgame2.pcx", "newgame1.pcx", "newgame2.pcx", new_game, NULL, NULL);

       button (250, 150, "exit2.pcx", "exit1.pcx", "exit2.pcx", exit_game, NULL, NULL);

       alpha = 100;

       flags = SHOW;

}

 

PANEL* options_pan =

{

       layer = 15;

       bmap = "options.pcx";

       pos_x = 0;

       pos_y = 0;

       alpha = 0;

       flags = TRANSLUCENT;

}

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function new_game()

{

       main_pan.flags |= TRANSLUCENT; // the player has clicked the "options" button, so let's make the main panel transparent

       options_pan.flags |= SHOW;        // show the options panel

       while (main_alpha > 5) // decrease main panel's alpha value, making it less and less visible

       {

               main_alpha -= 4 * time_step; // 4 gives main pan's fade out fading speed

               main_pan.alpha = main_alpha;

               options_alpha += 4 * time_step; // 4 gives option pan's fade in speed

               options_pan.alpha = options_alpha;

               wait (1);

       }

       main_pan.flags &= ~SHOW; // options_pan is visible, so let's hide the main panel

       options_pan.alpha = 100; // and then let's make options_pan fully visible by setting its alpha value to 100

}

 

function exit_game()

{

       sys_exit(NULL);        

}