Gw Temp

Menu

Tutorial - 'Basic ABS part two: Monsters!' by Stormshadow

An item about Gamemaker posted on

Blurb

Still remember kaworu's ABS tutorial, part 1? Here's the second part, continuing the first.

Body

Basic ABS part two - monsters and battles

Well hopefully you have already read my other tutorial on how to make your hero move and attack, if not then look it up before you read this. This will (hopefully) explain how to create a monster/enemy, create it's attacks and it's patrol route. Here you will learn how to use paths, health bars, distances and movement.

1.Setting up

Ok this is self explanatory, but still it is helpful to say. Create a new group under sprites and call it enemy1 in this group create two more groups one called attack, and the other walk. Now find the sprites for a monster walking (in all four directions) , I suggest trying Game sprite archive for these, and now load them to the group and with the correct names (sprwalkleft, sprwalkright, sprwalkdown, and sprwalkup). Now load up a sound effect for the player getting hit under the sounds heading and call it “sndhit”.

2.Path

Ok now go to the paths heading and click on add path. You will (hopefully) see a large cross with a dot in the middle, click on the horizontal axis of this cross roughly a quarter along. Click again about three-quarters along, so the dots are both sides of the vertical axis. See on the side where it says “ action at the end”, click on move to start. Now name the path patrol1 Well done! You have just created your first path (for some reason, people dread these. I think it is to do with lag) this will be used for the monster, to create it’s patrol route.

3.Return to Link

open up the “objplayer” object and add a new event, this will be create. This means that it takes effect as soon as the object is created. Now add a piece of code, which is simply

global.slash = false

Now open up the code under when enter is pressed, and add the code...

global.slash = true
alarm[4] = 7

under the “sprite_index =...” line for each direction. The whole code will look like...


if sprite_index = sprwalkup then
{
sprite_index = sprslashup
global.slash = true
alarm[4] = 7
alarm[0] = 7
}
if sprite_index = sprwalkdown then
{
sprite_index = sprslashdown
global.slash = true
alarm[4] = 7
alarm[1] = 7
}
if sprite_index = sprwalkleft then
{
sprite_index = sprslashleft
global.slash = true
alarm[4] = 7
alarm[2] = 7
}
if sprite_index = sprwalkright then
{
sprite_index = sprslashright
global.slash = true
alarm[4] = 7
alarm[3] = 7
}

Now create another event, this time for alarm4. Simply add the code...

global.slash = false

Now you have made the character turn on a switch whenever he attacks so that he can damage opponents.

4.Objects and events

Now under objects, create a new object and call it objenemy1. Add the create event, and then select “set a path for the instance” and select patrol1 from the list. Where it says speed, put 5 or 6. Now add another event for collision with objplayer, where you now add a code. This will check whether “global.slash” is switched on or off, then attack the player or get attacked depending on the outcome. Now the code is simply

if global.slash = false then
{
health -= 10;
sound_play(sndhit)
}
else
{
instance_destroy
}

There you have it, your basic monster created.

5.Extras

Well since this is assuming that you have read the beginers tutorial on the GM site, I won’t need to go into the health bar and such. But it would be a wise idea to add such a thing to your project. You can add varying enemies with greater health or attack power just by using variables. This is a basic engine, which I made a tutorial for to encourage you to think for yourself, so add what you want. Your only limit is your imagination.

6.Conclusion

Well this is the concluding part of my two part tutorial, though if people ask me then I may go on to further actions in another tutorial (so I can build up my FF monster collection). The whole tutorial and code should work, it works on my copy of GM 5.2, so if there are any errors then it is either your fault, your GM’s fault or mine for messing something up on the tutorial, but they are all basic coding and can be easily remedied. I was going to use magic in here, but there is really no need as it chould be self explanitory.
-Kaworu-
Is there anyone cuter?