Fragen aus dem Forum

Top  Previous  Next

Q: Weiß irgendjemand was das lite-C-Äquivalent von "my.oriented = on;" ist?

A: Nehmen Sie "set(my, DECAL);" für jedwedes Sprite, das als Gemälde etc. über einer Wand angebracht ist. Müssen beide Seiten des Sprites sichtbar sein, ändern Sie einfach seine pan- oder tilt-Winkel auf irgendeinen kleinen Wert ungleich Null (etwa 0.1 oder so). 

 

 

Q: Ich versuche, einen Textbereich zu machen und benutze dazu ein Panel als Hintergrund und einen Text mit einem ttf-Font zum Anzeigen einiger Zeilen. Ich möchte den Text mit "Hyperlinks" anzeigen. Das meint, dass, ist der Text schwarz vor einem weißen Hintergrund, einige der Worte in Blau dargestellt werden. Ich denke, der Weg, das zu entwickeln ist der, mehr Textkontrollen zu verwenden, je nach Anzahl der Wörter oder Zeilen, die anzuzeigen sind. Gibt es einen einfacheren Weg, das zu erreichen?

A: Hier ist ein Beispiel, das Texte zur Laufzeit erstellt und es Ihnen ermöglicht, ihre Positionen und Farben vorzugeben.

 

TEXT* temp_txt;

 

STRING* temp_str = "#50";

 

FONT* arial_font = "Arial#20";

 

function colored_texts(VECTOR* text_color, VECTOR* text_position)

{

       temp_txt = txt_create(1, 10); // create a text with a string and layer = 10

       str_cpy((temp_txt.pstring)[0], temp_str); // assign it the proper string

       temp_txt.font = arial_font;

       temp_txt.red = text_color.x; // set the color of the text

       temp_txt.green = text_color.y;

       temp_txt.blue = text_color.z;

       temp_txt.pos_x = text_position.x; // set the position of the text (the z component of the vector isn't used)

       temp_txt.pos_y = text_position.y;

       temp_txt.flags = SHOW; // now display the text

}

 

function texts_startup()

{

       wait (-5); // wait a bit

       str_cpy(temp_str, "Get ready!"); // set the first string

       colored_texts(vector(100, 220, 130), vector(300, 200, 0)); // create the first text

       wait (-2); // wait a bit

       str_cpy(temp_str, "The level is being loaded"); // set the second string

       colored_texts(vector(255, 20, 220), vector(100, 400, 0)); // create the second text

       wait (-2); // wait a bit

       str_cpy(temp_str, "Game over!"); // set the third string

       colored_texts(vector(125, 120, 250), vector(500, 550, 0)); // create the third text

       // and so on

}

 

aum86_faq1

 

 

Q: Ich würde gerne mit einem einfachen 3D-Breakout-Game anfangen. Haben Sie ein kleines Beispiel.

A: Hier ist es:

 

#include <acknex.h>

#include <default.c>

 

ENTITY* ball; // defined for further use

 

function control_ball();

 

function main()

{

       video_mode = 8; // 1024 x 768 pixels

       video_screen = 1; // full screen mode

       level_load("breaker.wmb");

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

       ball = ent_create("ball.mdl", vector (800, 0, -250), control_ball);

}

 

action players_paddle()

{

       player = my;

       set(my, TRANSLUCENT);

       my.alpha = 70;

       while (1)

       {

               c_move (my, nullvector, vector(0, -50 * mouse_force.x * time_step, 40 * mouse_force.y * time_step), NULL);

               wait (1);

       }

}

 

function ball_was_hit()

{

       vec_to_angle(my.pan, bounce); // makes the ball bounce off on collisions

       // add some randomness to the ball (we wouldn't want to see it bouncing back and forth between 2 obstacles)

       my.pan += 1 - random(2);

}

 

function control_ball()

{

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

       my.event = ball_was_hit;

       while(1)

       {

               my.skill1 = c_move (my, vector(50 * time_step, 0, 0), nullvector, IGNORE_PASSABLE);

               if (my.skill1 < 5) // the ball got stuck? might be needed under special circumstances

               {

                       my.pan = random(360); // then help it escape by setting a random pan angle for it!

               }

               wait(1);

       }

}

 

aum86_faq2

 

 

Q: Hat irgendjemand ein Skript, das es mir erlaubt, einen Film auf einer Oberfläche eines Levels abzuspielen? Ich hätte es gerne, dass ich auf die Oberfläche klicken und den Film dadurch immer wieder abspielen kann.

A: Hier ein Beispiel:

 

BMAP* pointer_tga = "pointer.tga";

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function surface_clicked()

{

       media_play ("mymovie.avi", bmap_for_entity (my, 0), 100); // use your own movie name

}

 

// attach this action to a sprite or a model

// if you are using a sprite, make sure that it has the same size (in pixels) with the size of the movie

action movie_surface()

{

       my.emask |= ENABLE_CLICK;

       my.event = surface_clicked;

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

       wait (-10); // wait for 10 seconds, and then play the movie once

       media_play ("mymovie.avi", bmap_for_entity (my, 0), 100); // use your own movie name

}

 

aum86_faq3

 

aum86_faq4

 

 

Q: Ich verwende in meinem lite-C-Code die Variable "PI". Aber ich kriege einen Fehler, der sagt sie sei "undeclared identifier". Fehlen mir vielleicht ein paar "include"s, um sie benutzen zu können?

A: PI ist kein Schlüsselwort in lite-C aber Sie können es einfach mithilfe einer einzigen Codezeile, die eine sehr gute Approximation ergibt, definieren.

 

#define PI 355/113

 

 

Q: Ich habe ein Problem mit dem Menü-Code aus Aum69. Wenn ich auf das neue Game klicke, kriege ich die Nachricht "Empty prototype called in". Das Game startet und man kann es spielen. Aber ich muß auf ok klicken, damit das Nachrichtenfenster verschwindet. Ich würde dieses Menü-System gerne als Grundlage für mein Game benutzen aber ich habe es nicht geschafft, dieses Nachrichtenproblem zu beheben.

A: Die neuen Versionen der A7-Engine können auch noch so kleine Syntax-Fehler aufspüren. Werfen Sie einen Blick auf die Codezeilen unten und prüfen Sie die korrekten Funktionsprototypen:

 

function mouse_over();

function plasma_jet();

function particle_fade(PARTICLE *); // this function prototype definition wasn't correct

function particle_jet(PARTICLE *);

function particle_jet_small(PARTICLE *);

function robot_explodes();

 

 

Q: Ich möchte ein Turm-Verteidigungsspiel machen. Wie mache ich dem Turm klar, dass er auf den Feind mit dem niedrigsten Gesundheits-Wert schießen soll?

A: Hier ist ein Beispiel:

 

var minimum_health = 100;

 

ENTITY* turret;

ENTITY* enemy_target;

 

action my_turret() // attach this action to your turret

{

       turret = my;

       VECTOR temp;

       while (1)

       {

               // scan all the entities that are closer than 1000 quants to this entity

               c_scan(my.x, my.pan, vector(360, 180, 1000), IGNORE_ME);

 

               if (enemy_target) // an enemy target was detected?

               {

                       vec_set(temp, enemy_target.x);

                       vec_sub(temp, my.x);

                       vec_to_angle(my.pan, temp); // rotate towards the enemy target

                       if (total_frames % 120 == 1) // fire a bullet every 2 seconds

                       {

                               // ent_create("bullet.mdl", my.x, move_bullet); // use your own shooting code here

                       }

               }

               wait (1);

       }

}

 

function i_am_scanned()

{

       if (my.skill1 <= minimum_health)

       {

               minimum_health = my.skill1;

               enemy_target = my;

               my.scale_z = 1.5; // highlight the enemy with the minimum health value (make it taller)

       }

       else

       {

               my.scale_z = 1;

       }

}

 

action my_enemies() // attach this action to your enemies

{

       my.skill1 = random(100); // each enemy has a random health value

       my.emask |= ENABLE_SCAN; // make the entity sensitive to scanning

       my.event = i_am_scanned;

}

 

function init_startup()

{

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

       random_seed(0); // generate random values at each game run

}

 

 

Q: Ich habe einen Lichtschalter und woanders das betreffende Licht, das durch diesen Schalter angeschaltet werden soll. Wie kann ich das machen?

A: Lassen Sie den Schalter den Player scannen. Der Code unten schaltet das Licht an sobald sich der Player dem Schalter nähert. 

 

aum86_faq6

 

var light_on = 0; // the light is turned off at first

 

action my_switch() // attach this action to your light switch

{

       while (1)

       {

               // scan the entities that are closer than 100 quants to the light switch

               c_scan(my.x, my.pan, vector(360, 180, 100), IGNORE_ME);

               if (you == player) // the player has come closer than 100 quants to the light switch entity?

               {

                       light_on = 1; // then turn the light on!

               }

               wait (1);

       }

}

 

action my_lightbulb() // attach this action to your light entity

{

       while (!light_on) {wait (1);} // wait until the player comes close to the switch

       set (my, CAST);

       my.lightrange = 500;

       my.red = 200;

       my.green = 200;

       my.blue = 160;                

}

 

 

Q: Wenn ich einen String wie    STRING* MyString = "Hi out there";  erstelle, gibt es da eine Möglichkeit, einzelne Zeichen wie den Buchstaben H und den Buchstaben i etc. abzurufen?

A: Verwenden Sie den folgenden Schnipsel:

 

var string_length, string_index;

 

STRING* MyString = "Hi out there";

STRING* temp_str = "#50"; // just a backup string

STRING* output_str = " "; // displays the string character by character

 

TEXT* output_txt =

{

       pos_x = 200;

       pos_y = 20;

       string(output_str);

       flags = SHOW;

}

 

function chars_startup()

{

       string_index = 0;

       while (!key_s) {wait (1);} // press the "S" key to start the action

       while (key_s) {wait (1);} // wait until the "S" key is released

       string_length = str_len(MyString); // get the length of the string

       while (string_index < string_length) // go through all the characters of the string, one by one

       {

               str_cpy (temp_str, MyString); // first of all, copy MyString to temp_str (we don't want to destroy it)

               str_clip(temp_str, string_index); // cut the needed number of characters from the beginning of the string

               str_trunc(temp_str, string_length - string_index - 1); // and cut from the end as well

               // here's we've got all the characters of the string rolling one by one, so let's display them

               str_cpy(output_str, temp_str); // copy the truncated temp_str to output_str

            string_index += 1; // move on to the following character in the string

               wait (-1); // display a character each second

       }

       str_cpy(output_str, " "); // hide the last character after it has been displayed

}

 

 

Q: Hat irgendjemand einen Cadeschnipsel der eine Entity zur Position einer anderen Entity schickt aber auch über dessen Position hinausschießt und sich selbst korrigiert? Auf diese Art sollte die Entity so aussehen, als rüttle sie ihre Position wenn sie zu ihrer Zielposition gelangt.

A: Nehmen Sie dieses Beispiel als Grundlage für Ihren Code:

 

ENTITY* my_target;

 

action my_destination() // attach this action to the target entity

{

       my_target = my;       

}

 

action target_seeker() // attach this action to your target seeking entity

{

       while (!my_target) {wait (1);} // wait until the target entity is loaded

       VECTOR temp, temp_angle;

       var temp_time;

       vec_set(temp_angle, my_target.x);

         vec_sub(temp_angle, my.x);

         vec_to_angle(my.pan, temp_angle);

       my.tilt = 0;

       // the entity was rotated towards the destination here

       // let's change its angle a bit, making it miss the target at first

       if (random(1) > 0.5)

               my.pan += 5; // play with 5

       else

               my.pan -= 5; // play with -5

       // we have added -5 or 5 degrees to the pan angle here, so the entity will miss the target a bit

       // the following loop runs until the entity comes close enough to the target

         while (vec_dist(my.x, my_target.x) > 100) // play with 100

       {

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

               wait (1);

       }

       // keep the entity moving in the wrong direction for 2 more seconds

       temp_time = 0;

         while (temp_time < 2)

       {

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

               temp_time += time_step / 16;

               wait (1);

       }

       // now rotate towards the target correctly

       vec_set(temp_angle, my_target.x);

         vec_sub(temp_angle, my.x);

         vec_to_angle(my.pan, temp_angle);

         while (vec_dist(my.x, my_target.x) > 40) // stop when the entity is closer than 40 quants to the target (play with 40)

       {

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

               wait (1);

       }

       // the goal was reached here

}