Managing Monsters – Like Parent, Like, err, Child…

When you created added several monsters to the maze game that moved in different directions (Adding Monsters to the Maze Game), you may have found that you forgot to add an event to the player object that checked for a collision with am instance of a “vertical monster” object as well as an instance of the “horizontal monster” object. (If that is the case, the player would not have suffered any ill consequence of colliding with a vertically moving monster; to remedy this oversight (?!), you need to check for a collision with an obj_verMonster in the player object, and add a similar set of actions as used in the collision with an obj_horMonster event.)

If you have lots of objects that are ‘variations on a theme’ – such as the monster objects – it can become quite confusing trying to maintain separate collision detection events for each of them.

However, there is a technique we can use whereby objects can ‘inherit’ certain properties from other ‘parent’ objects, in such a way that allows them to be treated as those parent objects in certain respects.

(Objects, instances and inheritance are all ideas taken from computing/software engineering – in particular, the object oriented programming model. I’ll cover some of the basic nitty gritty in another post, but if you’re already familiar with the basic idea, and are feeling up to a challenge, you can maybe learn a bit more from this OpenLearn unit on Modelling object-oriented software – an introduction .)

To make use of these ‘object inheritance’ properties, you will need to run Gamemaker in Advanced mode. If you are not already in Advanced Mode (?!), save your current game, go to the File menu and select ‘Advanced Mode’. Gamemaker will close and open again with a new game, so you will need to open the game you just saved back in.

Delete the vertical monster object and the corresponding collision event from the player object and create a new ‘vertical monster’ object. Give it an appropriate sprite. You should see that there are now several more options in the object editor now that we are in advanced mode. The one we are interested in at the moment is the parent property.

Set the parent of the vertical monster to be the horizontal monster.

If you were now to add the vertical monster to the game, it would behave in exactly the same way as the horizontal monster – it has inherited all its behavioural properties.

However, we can override some of those properties by explicitly defining them within the vertical monster object. In this case, the property we want to override the direction the monster moves in, so add a Create event that sets the movement direction to be up or down, with a speed greater than that of the player object.

We do not need to explicitly define the collision event between either the vertical monster and the wall, or the player object and the monster because the player essentially sees the vertical monster as a horizontal monster type and reacts to it as such.

With multiple monsters in your game, it is possible to set up many situations that may prove increasingly challenging for your player to negotiate. For example, see if you can set up a couple of rooms that are empty except for five or six monsters that just move up or down, either all in a line, or maybe out of sequence with each other (start some of them at the top of the screen, others at the bottom, and so on). The challenge here is simply to cross the room… Are there any particular configurations of monsters that make this especially difficult to achieve? To what extent does increasing the speed of the monsters make it a more or less difficult task to cross the room?

Advertisements

2 Responses to “Managing Monsters – Like Parent, Like, err, Child…”


  1. 1 r3becca March 18, 2008 at 8:48 pm

    This isn’t anything to do with the post (can’t build a game cos I’ve got a Mac :-( ).

    I wondered if you’d thought of connecting this un-course up with Open Learn? It seems the sort of thing Open Learn ought to be doing.

    And, I know it’s an un-university course, but it’s also all the sorts of things my eight-year-old son is fascinated by. If I had more spare time I’d go and use it as a basis for a games-building club at his school.

  2. 2 Tony Hirst March 20, 2008 at 12:56 am

    “I wondered if you’d thought of connecting this un-course up with Open Learn? It seems the sort of thing Open Learn ought to be doing.”

    Yes – partly – but i also wanted to explore the ‘blog form’e.g. in terms of the tone of each post, the self-contained nature of each post, the daily delivery ( and, err, ‘discipline’ of producing it/keeping up with it on a daily basis!)

    There is a possibility that some of the material in the blog will end up in an official OU course, so there is an issue with copyright/license conditions, possibly… Also, by running this blog essentially as an independent, liability for any copyright infringement is mine….nor do I have to spend weeks and months trying to get copyright clearance for third party assets…;-)

    “And, I know it’s an un-university course, but it’s also all the sorts of things my eight-year-old son is fascinated by. If I had more spare time I’d go and use it as a basis for a games-building club at his school.”

    If you want to chat more about how we can do that, let’s chat more; I suspect that Game Maker is definitely okay for independent use at Key Stage 3, based on a comparison with the complexity of it cf. the RobotLab s/w we use in T184 ( http://ouseful.open.ac.uk/t184 ), which is being used successfully with Y8 in my daughter’s school. ( http://robots.open.ac.uk and http://robofesta.open.ac.uk for more info on robotics outreach…)

    Scratch could also be used in school – and i really do intend to get on to that when I have worked through the Game Maker stuff.

    Btw, i just noticed a comment that had got caught by the spam filter that gave a Scratch variant of the catch a clown game:

    https://digitalworlds.wordpress.com/2008/03/07/getting-started-with-game-maker/#comment-55


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Categories


%d bloggers like this: