Beginner's corner

Top  Previous  Next

Compass

 

This article will tell you how to create a simple compass that keeps its size regardless of the screen resolution. If you have tried to work with panels before, you know that they change their relative size on the screen when you increase or decrease the screen resolution; the bigger video the resolution is the smaller will the panels will look. Why is that? The panels have kept their size in pixels but the number of pixels on screen has increased. You can resize the panels using the new scale_x and scale_y, which sometimes will make your panels look a bit uglier, or you can place your 2D elements in the 3D world as "entity" definitions.

 

aum45_shot2

 

aum45_shot3

 

entity compass

{

   type = <compass.tga>;

   layer = 10;

   scale_x = 0.25;

   scale_y = 0.25;

   x = 190;

   y = -85;

   z = -65;

   view = camera;

   flags = overlay, visible;

}

  

aum45_shot4

 

entity needle

{

   type = <needle.tga>;

   layer = 20;

   scale_x = 0.15;

   scale_y = 0.15;

   x = 190;

   y = -85;

   z = -65;

   view  = camera;

   flags = overlay, nofilter, visible;

}

 

These "entity" definitions use two tga files; you can see that I am setting their size, as well as their position in the 3D world (x sets the distance to the camera, y sets the position on the x axis of the screen and z sets the position on the y axis of the screen. The needle has layer = 20 so it will appear over compass' layer = 10. And the final touch: the needle has its "nofilter" flag set, which will render the needle sharper, without giving it that blurry look.

 

starter set_compass()

{

       while (player == null) {wait (1);} // wait until the player is loaded in the level 

       while (1) 

       {      

               needle.roll = -player.pan;

               wait (1); 

       }

}

 

The starter function above waits until the player is created, and then it sets needle's roll angle to player's pan angle multiplied by -1.

 

 

 

Flying birds

 

aum45_shot5

 

I remember myself playing Unreal1 and getting past the first indoor levels. I was imprisoned and then I managed to escape and I got out of a cave. I was amazed! The huge outdoor areas with trees and springs and birds flying up high in the sky... Man, those were the days! The snippet below will teach you to create the code for a bird that can fly and take care of itself. Let's stare at it for a second:

 

action move_bird

{

   var init_pos; // initial position of the bird

   var bird_speed; // flying speed

   var flying_distance;

   flying_distance = my.skill1;

   if (flying_distance == 0) {flying_distance = 2000;} // default flying distance

   bird_speed = my.skill2;

   if (bird_speed == 0) {bird_speed = 5;} // default flying speed

   my.passable = on;

   vec_set (init_pos.x, my.x); // store the initial position of the bird

   while (1)

   {

      temp.x = bird_speed * time;

      temp.y = 0;

      temp.z = 0;

      move_mode = ignore_passable;

      my.skill40 += ent_move (temp, nullvector); // move in the direction given by the pan angle in Wed

      if (my.skill40 > flying_distance)

      {

           my.skill40 = 0;

           vec_set (my.x, init_pos.x);

      }

      ent_cycle("walk", my.skill1); // animate the bird

      my.skill1 += 3 * time; // animation speed

      my.skill1 %= 100; // loop animation

      wait (1);

   }

}

 

We have defined a few variables; init_pos will store the initial position of the bird, bird_speed will store the speed of the bird and flying_distance will store the distance that must be covered by the bird before returning to its initial position. You can set flying_distance using skill1 and bird_speed using skill2 in Wed; however, if you forget to do that the code will use the predefined values of 2000 quants and 5. We make the bird passable (not really needed) and then we store the initial position of the bird in init_pos (that's the position you have given to your bird in Wed) before entering the while loop. The loop keeps bird's speed time-corrected and moves the bird, storing the distance that was covered in skill40; if that value gets bigger than flying_distance, the bird is returned to its initial position and the process repeats. The last few lines animate the bird; mine had a weird name for its animation (walk) but you can put the name of your bird's animation frames here.

 

How do you use these birds? Place them in the level at slightly different heights, choose their orientation and set a proper speed and flying distance. The distance should be big enough because you don't want the player to notice the trick (the movement in a loop); make sure that the birds start flying in an area that can't be seen by the player and end their journey in another place that can't be seen by the player. Have fun!