Code snippets |
Top Previous Next |
Morrowing
The last Morrowing episode (sniff) introduces a new character that speaks with the player and takes different actions depending on player's answers: it can fly away (really!) or it can fight the player. I won't concentrate my efforts on the code that deals with the dialogue; you can always examine its inner works in the Morrowing article from Aum49.
action enemy2 // attached to the berzerka.mdl model
The first few lines declare some local variables; the most important are right_fist and left_fist, which will be used for hand combat. The monster has 200 health points and it is invisible and passable at first; it will wait until the player picks up and uses the mace (mace != null), and then it will become impassable and opaque, increasing its alpha inside the while loop. When the monster is completely opaque it plays the beast2_wav sound.
while (my.health > 0) // as long as the enemy is alive
The enemy will attack for as long as its health is positive; if the player is alive and comes closer than 2000 quants to the enemy, we increment lines_on, and if lines_on = 1 (the lines are to be said only once) we start to process the text: we set dialog_number to 7 (the dialogs from Aum 49 have ended at dialog_number = 6), we set the relevant lines of text for the monster and for the player, we display them and we wait until their_pan is made invisible; this will happen when the dialogs have disappeared from the screen. The last line of code will allow the player to move again, but only if the texts have disappeared.
if (dialog_number == 8) // the player is a chicken? then fly away
If dialog_number = 8, meaning that the player isn't courageous (and this was decided inside panelstexts.wdl), the monster will play a (funny?) "initiating the startup sequence" sound, it will wait until the sound is over, and then it will play the launched_wav sound. The enemy will start moving upwards with a big speed, rotating around its pan angle at the same time. We decrease its scale on all the axis, creating the illusion that the monster moves away at an enormous speed (we've got a limited level size to play with). The last line of code stops the "while" loop.
enemy_speed.x = 30 * time; // "walk" speed
The code from above is executed if the player has decided to fight the monster; it moves the monster and animates it using the "walk" animation frames. If the player is closer than 400 quants, the monster will play its beast2_wav sound, and if the player is alive it will set right_fist and left_fist to the coordinates of the 3rd and 138th vertex. I could have used the same tracing method to damage the player, but I have thought that you might be interested in seeing a new method that works well for close combat. I get the position of those 2 key vertices that are placed on monster's fists, and if the distance between them and player's origin is smaller than 100 quants (experimental value) I damage the player. If the player is hit by the monster, I rotate him in the proper direction; this makes it a bit harder for the player but it's still really easy to kill that fat monster.
// the player loses health more easily if its armor is damaged (or off) and if its shield isn't used
The player has been hit here; we decrease its health, depending on the status of the armor and shield, and then we play the old sword_wav sound that was also used by the skeleton. The monster will play its "attack" animation frames with the speed given by 5 * time, which sets the attacking rate as well. The last line stops the monster if another dialogue appears on the screen.
else // the player is farther than 2000 quants away
If the player is farther than 2000 quants away, the monster will start running towards him, playing some awful beastwalk_wav sounds and making the camera shake by changing its roll angle. The last 3 lines take care of the "run" animation.
vec_set(temp, player.x); // rotate the enemy towards the player all the time
The last chunk of code makes sure that the monster faces the player at all times, waits 1 frame (this instruction is needed by the parent while loop) and then sets the movement speed on y and z (gravity). The last while loop plays the "death" animation, and then it makes the monster passable and adds 15 points to player's experience.
This article concludes the Morrowing series. You can continue to walk on that path, meet and (hopefully) kill the first skeleton, reaching the entrance door. I chose to make the enemies pretty weak but you can (and you should) increase their health in order to make the things more challenging for the player.
Morrowing was a shorter series, but I was planning to change Aum's content and layout a few months ago and Aum50 sounded like a round value to me. I'll see you in Aum51 with a new layout, new topics and - hold your breath - a searchable magazine.
|