Beginner's corner

Top  Previous  Next

Feature of the month: aspect

Acknex includes a lot of great features that aren't exploited properly; this month I want to show you what "aspect" does.

Practical use: flip the screen upside down (useful for space games), create impressive spell effects and more!

The keyword "aspect" determines the vertical to horizontal pixel size ratio. In other words, if you place a square model on your screen you can make it look like a rectangle if you change its "aspect". I have created two simple functions that use this great engine feature:

function flip_level()
{
    while (camera.aspect > -1)
    {
         camera.aspect -= 0.1 * time;
         wait (1);
    }
}

function grow_level()
{
    while (camera.aspect < 5)
    {
         camera.aspect += 0.2 * time;
         wait (1);
    }
}

on_f = flip_level;
on_g = grow_level;

The first function will run when we press the "F" key; it will decrease camera.aspect from 1 (normal value at game start) to -1. When camera.aspect = -1, the image is flipped upside down.

The second function runs as soon as we press the "G" key; it will increase camera.aspect from 1 to 5, changing the aspect of the level: every pixel on x will correspond to 5 pixels on y. Look how cool are my rocks with aspect = 5! I would use this effect for a magical potion, etc.



Landmines

Let's imagine this situation: you are being chased by way too many enemies. Your health is lower and lower and every bullet gets you closer and closer to a dishonorable death. And this hallway looks like it will never end! (Although you are hurt, you can't stop thinking that Acknex is such a great engine...) The enemies are right behind you, but wait, there's a door over here! You open the door and then you hear two short beeps. A spectacular jump saves your live. The landmine explodes without hurting you at all! But this isn't true for your enemies...

If this sounds good to you, rejoice: this article will teach you how to create a landmine that can kill you or your enemies. You can make your enemies follow you and if they get close to the landmine they will die.

The code isn't complicated at all:

action landmine
{
    my.skill1 = 0;
    my.enable_detect = on;
    my.event = hurt_them;

We are setting skill1 to zero; its value will remain zero as long as the mine hasn't detected an entity. We set enable_detect to on; this way the mine will be sensitive to any entity with its enable_scan set: the player and the "normal" enemies (actor_ai_one, for example). If one of these entities approaches the landmine, function hurt_them will run.

    while (my.skill1 == 0)
    {
         temp.pan = 360;
         temp.tilt = 180;
         temp.z = 200;
         scan_entity(my.x, temp);
         if ((result > 0) && (result < 200))
         {
              my.ambient = 100;
              ent_playsound (my, beephigh_wav, 500);
              sleep (0.3);
              my.ambient = 0;
              sleep (0.3);
              my.ambient = 100;
              ent_playsound (my, beephigh_wav, 500);
              my.skill1 = 1; // get out of the while loop
         }
         sleep (0.2); // scan 5 times a second
    }

As long as skill1 = 0, we scan everything around the landmine, like in the picture below, five times a second:

Nothing can escape our scan; more than that, we can simply set temp.z to a bigger value to increase the scanning range. If the mine has detected an entity, it increases its ambient, plays a sound then waits for 0.3 seconds. The ambient is set back to zero, we wait for 0.3 seconds and the sequence repeats. As soon as the second beep is played, we set skill1 to 1 so that we can get out of the while loop. Sleep (0.2) will make the engine scan 5 times a second; if you think that your enemies are faster than that (if you are creating a space game, for example) you can lower this value.

You can see that we didn't hurt anybody until now; the code that does that is located in function hurt_them():

function hurt_them()
{
sleep (1);
you._health -= 200;
}

We wait for a second; the entity is already dead by now so we give the illusion that he / she / it might escape. This can't happen because the next line decreases 200 health points from entity's health. A landmine should kill everybody, isn't it?