Fragen aus dem Forum

Top  Previous  Next

F: Mir hat der “Fahrstühle für Wolkenkratzer” Code aus Aum 36 sehr gefallen. Kann ich auch mit der Tastatur ein Stockwerk anwählen? “1” sollte mich in den 1. Stock bringen, “2” in den zweiten und so weiter.

A: Hier ist die modifizierte Skriptversion.

 

var video_mode = 7; // 800x600 pixels

var video_depth = 16; // 16 bit mode

 

var floor1 = 39; // heights (in quants) for the 3 floors

var floor2 = 520;

var floor3 = 1032;

 

var goto_floor = 0;

var ready_for_clicks = 1; // enables (1) / disables (0) the elevator buttons

 

/////////////////////////////////////////////////////////////////////////////////

 

bmap pointer_pcx = <pointer.pcx>;

 

/////////////////////////////////////////////////////////////////////////////////

 

string elevator_wmb = <elevator.wmb>;

 

/////////////////////////////////////////////////////////////////////////////////

 

sound beep_sound = <beep.wav>;

 

/////////////////////////////////////////////////////////////////////////////////

 

function toggle_crosshair();

function button_clicked();

 

/////////////////////////////////////////////////////////////////////////////////

 

entity* my_elevator;

entity* button_red;

entity* button_green;

entity* button_blue;

 

/////////////////////////////////////////////////////////////////////////////////

 

function main()

{

       on_d = null; // disable the debug panel for A5

       level_load (elevator_wmb);

       mouse_map = pointer_pcx;

       mouse_mode = 0; // hide the pointer at game start

       while (1)

       {

               mouse_pos.x = pointer.x;

               mouse_pos.y = pointer.y;

               wait (1);

       }                

}

 

function toggle_crosshair()

{

       mouse_mode = (mouse_mode == 0) * 2; // mouse_mode = 0 or 2

}

 

action player1

{

       proc_late();

       player = my;

       my.invisible = on; // hide the player model

       while (1)

       {

               vec_set (camera.pos, my.pos);

               camera.z += 50;

               camera.pan = my.pan;        

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

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

 

               vec_set (temp, my.x);

               temp.z -= 3000;

               trace_mode = ignore_me + ignore_passable + use_box;

               temp.z = -trace (my.x, temp); // trace 3000 quants below player's feet

 

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

               temp.y = 8 * (key_a - key_d) * time * ready_for_clicks;

 

               ent_move (temp, nullvector);

               wait (1);

       }

}

 

action elevator

{

       proc_late();

       my_elevator = my;

       my.z = floor1; // stay out of trouble (Wed can drag you towards the dark side...)

}

 

action button

{

       my.light = on;

       my.lightrange = 0;

       my.unlit = on;

       my.ambient = -100;

       if (my.skill1 == 1)

       {

               button_red = my;

               my.lightred = 255;

               my.lightgreen = 0;

               my.lightblue = 0;

               goto_floor = 1;

       }

       if (my.skill1 == 2)

       {

               button_green = my;

               my.lightred = 0;

               my.lightgreen = 255;

               my.lightblue = 0;

               goto_floor = 2;

       }

       if (my.skill1 == 3)

       {

               button_blue = my;

               my.lightred = 0;

               my.lightgreen = 0;

               my.lightblue = 255;

               goto_floor = 3;

       }

       my.enable_click = on;

       my.event = button_clicked;

}        

 

function button_clicked()

{

       if (ready_for_clicks == 0) {return;} // don't allow multiple clicks while the elevator is moving

       ready_for_clicks = 0; // don't register button clicks for now

       if (goto_floor == 1) // pressed the red (1st floor) button?

       {

               if (my_elevator.z == floor1) // if the elevator is at the first floor already

               {        

                       ready_for_clicks = 1; // enable clicking again

                       return; // do nothing

               }

               if ((my_elevator.z == floor2) || (my_elevator.z == floor3)) // if the elevator is at the second or third floor

               {        

                       while (my_elevator.z > floor1)

                       {

                               my_elevator.z -= 5 * time;

                               player.z = my_elevator.z + 48; // 48 = experimental value, depends on the height of the model

                               button_red.z = my_elevator.z + 81; // experimental values

                               button_green.z = my_elevator.z + 105;

                               button_blue.z = my_elevator.z + 129;

                               wait (1);

                       }

               }

               my_elevator.z = floor1;

       }

       if (goto_floor == 2) // pressed the green (2nd floor) button?

       {

               if (my_elevator.z == floor2) // if the elevator is at the second floor already

               {        

                       ready_for_clicks = 1; // enable clicking again

                       return; // do nothing

               }

               if (my_elevator.z == floor1) // if the elevator is at the first floor

               {        

                       while (my_elevator.z < floor2)

                       {

                               my_elevator.z += 5 * time;

                               player.z = my_elevator.z + 48; // 48 = experimental value, depends on the height of the model

                               button_red.z = my_elevator.z + 81;

                               button_green.z = my_elevator.z + 105;

                               button_blue.z = my_elevator.z + 129;

                               wait (1);

                       }

               }

               if (my_elevator.z == floor3) // if the elevator is at the third floor

               {        

                       while (my_elevator.z > floor2)

                       {

                               my_elevator.z -= 5 * time;

                               player.z = my_elevator.z + 48; // 48 = experimental value, depends on the height of the model

                               button_red.z = my_elevator.z + 81;

                               button_green.z = my_elevator.z + 105;

                               button_blue.z = my_elevator.z + 129;

                               wait (1);

                       }

               }

               my_elevator.z = floor2;

       }

       if (goto_floor == 3) // pressed the blue (3rd floor) button?

       {

               if (my_elevator.z == floor3) // if the elevator is at the third floor already

               {        

                       ready_for_clicks = 1; // enable clicking again

                       return; // do nothing

               }

               if ((my_elevator.z == floor1) || (my_elevator.z == floor2)) // if the elevator is at the first or second floor

               {        

                       while (my_elevator.z < floor3)

                       {

                               my_elevator.z += 5 * time;

                               player.z = my_elevator.z + 48; // 48 = experimental value, depends on the height of the model

                               button_red.z = my_elevator.z + 81;

                               button_green.z = my_elevator.z + 105;

                               button_blue.z = my_elevator.z + 129;

                               wait (1);

                       }

               }

               my_elevator.z = floor3;

       }

       button_red.z = my_elevator.z + 81;

       button_green.z = my_elevator.z + 105;

       button_blue.z = my_elevator.z + 129;

       ready_for_clicks = 1;

}

 

 

on_mouse_right = toggle_crosshair;

 

 

function go_floor1()

{

       goto_floor = 1;

       button_clicked(); // call the event function

}

 

function go_floor2()

{

       goto_floor = 2;

       button_clicked(); // call the event function

}

 

function go_floor3()

{

       goto_floor = 3;

       button_clicked(); // call the event function

}

 

on_1 = go_floor1;

on_2 = go_floor2;

on_3 = go_floor3;

 

 

F: Wie kann ich Objekte mit der Maus bewegen? Wenn man ein Objekt anklickt, soll es dem Mauszeiger folgen.

A: Hier ist ein Beispiel; damit können Sie Objekte aufheben, bewegen und ablegen.

 

function pick_or_drop()

{

       wait (1);

       my.skill1 += 1;

       if ((my.skill1 % 2) == 1) // clicked the object?

       {

               while (mouse_left == on) {wait (1);}

               while (mouse_left == off) // move the object until the player presses the mouse button again

               {

                       temp.x = pointer.x;

                       temp.y = pointer.y;

                       temp.z = 200; // move the object 200 quants below the camera, play with this value

                       vec_for_screen(temp.x, camera);

                       my.x = temp.x;

                       my.y = temp.y;

                       my.z = temp.z;

                       wait (1);

               }

       }

       else // drop the object

       {

               vec_set (temp.x, my.x);

               temp.z -= 3000;

               trace_mode = ignore_me + ignore_sprites + ignore_models + use_box;

               my.z -= trace (my.pos, temp); // place the object on the ground

       }

}

 

action click_and_move

{

       my.skill1 = 0;

       my.enable_click = on;

       my.event = pick_or_drop;

}

 

 

F: Wie kann ich mein Spiel in mehreren Sprachen anbieten, z.B. Englisch und Deutsch?

A: Hier ist ein Beispiel:

 

define english 1;

define german 2;

 

string displayed_str;

 

text english_txt // create an array of strings using a text

{

       strings = 5;

       string = "english text 1";

       string = "english text 2";

       string = "english text 3";

       string = "english text 4";

       string = "english text 5";

}

 

text german_txt // create an array of strings using a text

{

       strings = 5;

       string = "german text 1";

       string = "german text 2";

       string = "german text 3";

       string = "german text 4";

       string = "german text 5";

}

 

text displayed_txt

{

       pos_x = 300;

       pos_y = 100;

       string = displayed_str;

}

 

function display_text(line_number, language)

{

       if (language == english)

       {

               str_cpy (displayed_str, english_txt.string[line_number]); // set the proper English string

       }

       if (language == german)

       {

               str_cpy (displayed_str, german_txt.string[line_number]); // set the proper German string

       }

       displayed_txt.visible = on; // show the text

       sleep (5); // for 5 seconds

       displayed_txt.visible = off;

}

 

// display_text (0, english) will display "english text 1"

// display_text (3, german) will display "german text 4"

 

 

F: Wie kann ich einen einfachen 3D Side Scroller erstellen? Ich benötige Code für den Spieler und die Kamera.

A: Hier ist etwas Code, den Sie als Grundlage benutzen können.

 

// this action is set up for a player that's traveling from left to right in Wed's top view

action player_side_scroll

{

       var walk_percentage;

       while (1)

       {

               c_move (my, vector((key_cul - key_cur) * 2 * time, 0, 0), nullvector, glide);

               if (key_cur + key_cul != 0)

               {

                       ent_animate(my, "walk", walk_percentage, anm_cycle);

                       walk_percentage += 3 * (key_cul - key_cur) * time; // 3 = "walk" animation speed

               }

               else

               {

                       ent_animate(my, "stand", walk_percentage, anm_cycle);

                       walk_percentage += 2 * time;

               }

               camera.x = my.x;

               camera.y = my.y + 300; // might need changes depending on your level setup

               camera.z = my.z;

               camera.pan = my.pan - 90;

               wait (1);

       }

}

 

F: Wie kann ich die Framerate direkt einstellen? Ich habe versucht, fps_max auf 60 zu setzen, aber das Spiel lief bei 56 fps. Bei einer Einstellung von 70 läuft es bei 66,7. Klassische Spiele, wie Sonic oder Mario laufen konstant auf 60 fps. Entweder läuft mein Spiel zu langsam (56) oder zu schnell (66,7). Wie kann ich die fps exakt festlegen?

A: Mit fps_max können Sie einen ungefähren Wert für die maximale Framerate festlegen; Sie können mit Hilfe eines kleinen Skriptes das Feintuning übernehmen. Bedenken Sie, dass die Framerate auf verschiedenen Rechnern auch von der Grafikkarte abhängt.

 

// use "1" and "Q" to set fps_max, and then use the "real" fps_max value in your script

 

var fpsec;

var init_frames;

 

text info_txt

{

       layer = 20;

       pos_x = 60;

       pos_y = 0;

       string = "fps_max            real frame rate";

       flags = visible;

}

 

panel framerate_pan

{

       pos_x = 50;

       pos_y = 20;

       layer = 15;

       digits = 20, 0, 4, _a4font, 1, fps_max;        

       digits = 150, 0, 4, _a4font, 1, fpsec;        

       flags = overlay, refresh, visible;

}

 

starter set_fpsmax()

{

       while (1)

       {

               if (key_1 == on)

               {

                       fps_max += 5 * time;

               }

               if (key_q == on)

               {

                       fps_max -= 5 * time;

               }

               init_frames = total_frames;

               sleep (1);

               fpsec = total_frames - init_frames;

               wait (1);

       }

}

 

 

F: Ich hätte gern einen Schalter, mit dem man Licht ein und ausschalten kann; außerdem sollte ein Text erscheinen, wenn der Spieler den Schalter mit der Maus berührt. Ist das möglich?

A: Sicher.

 

text light_txt

{

       layer = 2;

       pos_x = 300;

       pos_y = 275;

       string = "That's a light switch!";

}

 

function light_on_off()

{

       my.skill1 += 1;

       if ((my.skill1 % 2) == 1)

       {

               my.lightrange = 500;

       }

       else

       {        

               my.lightrange = 0;

       }

}

 

action light_source // attach it to the light source

{

       my.skill1 = 0;

       my.red = 255;

       my.green = 255;

       my.blue = 200;

       my.enable_scan = on;

       my.event = light_on_off;

}

 

function switch_event()

{

       if (event_type == event_click)

       {

               wait (1);

               temp.x = 360; // horizontal scanning angle

               temp.y = 180; // vertical scanning angle

               temp.z = 1000; // scanning range = 1000 quants

               scan_entity (my.x, temp);

       }

       else // touched with the mouse?

       {

               light_txt.visible = on; // display the text for 5 seconds

               sleep (5);

               light_txt.visible = off;

       }

}

 

action light_switch // attach it to the switch

{

       my.enable_click = on;

       my.enable_touch = on;

       my.event = switch_event;

}

 

 

F: Ich möchte ein Panel (in 2D Koordinaten) genau über einer gewissen 3D Position plazieren. Wie kann ich das erreichen?

A: Verwenden Sie das folgende Beispiel:

 

bmap my_pcx = <my.pcx>;

 

panel my_pan

{

       bmap = my_pcx;

       layer = 15;

       flags = overlay, refresh, visible;

}

 

function highlight_me()

{

       var temporary;

       while (1)

       {

               vec_set (temporary, my.x);

               vec_to_screen (temporary, camera);

               my_pan.pos_x = temporary.x;

               my_pan.pos_y = temporary.y;

               wait (1);

       }

}

 

action my_entity

{

       highlight_me(); // attach the panel to the entity

       // put the rest of the code for your entity here

}

 

 

F: In meinem Spiel habe ich ein Model für ein Gewehr. Ich brauche kein Spielermodel, möchte aber die Waffe wie in einem Shooter anzeigen. Kann mir jemand helfen?

A: Verwenden Sie einfach eine “entity” Definition.

 

entity my_gun

{

       type = <microuzi.mdl>; // put the name of your model here

       layer = 10;

       view = camera;

       x = 25; // x, y, z adjust the position of the weapon in relation to the camera

       y = -10;

       z = -10;

       flags = visible;

}

 

 

F: Kann man die Engine in einem Frame laufen lassen? Ich sehe ein wie man mit Hilfe von Panels die Bereiche abdeckt, die man nicht braucht, aber ist das nicht Verschwendung von Ressourcen?

A: Sie müssen keine Bereiche abdecken erzeugen Sie ein kleineres Engine Fenster und plazieren Sie es wo Sie möchten.

 

// make sure that big.pcx has a black (rbg = 000) cutout that has the same size with the small camera

bmap big_pcx = <big.pcx>;

 

panel big_pan // that's a 640x480 pixels bitmap

{

       bmap = big_pcx;

       layer = 15;

       flags = overlay, refresh, visible;

}

 

view small_camera

{

       layer = 20; // appears over big_pan

       pos_x = 63; // pos_x and pos_y give the position of the view

       pos_y = 188;

       size_x = 116; // size_x and size_y give its size

       size_y = 160;

       flags = visible;

}

 

starter action_camera()

{

       camera.visible = off; // hide the big, predefined camera

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

       while (1)

       {

               small_camera.x = player.x; // show the player on the small camera

               small_camera.y = player.y;

               small_camera.z = player.z + 200;

               small_camera.pan = player.pan;

               small_camera.tilt = -90;

               wait (1);

       }

}

 

smallcamera

 

 

F: Kann ich die Engine Version anzeigen? Ich bin ein Beta Tester und weiß nicht, welche Version ich wann starte.

A: Hier ist ein Beispiel:

 

string version_str;

string engine_str;

 

text version_txt

{

       layer = 5;

       pos_x = 30;

       pos_y = 25;

       string = engine_str;

}

 

starter display_version()

{

       sleep (5); // wait until the level is loaded, the splash screen is displayed, and so on

       str_for_num(version_str, version);

       str_cpy(engine_str, "Starting Acknex v");

       str_cat(engine_str, version_str);

       version_txt.visible = on; // show the engine version for 5 seconds

       sleep (5);

       version_txt.visible = off;

}