Creating an NPC in GameMaker - fullcoll.edu

Creating an NPC in GameMaker

Most game have NPCs (Non-player characters) that act independently. NPCs could be companions or enemies or just background characters to the game. In most cases such NPCs will move around the screen on their own power. Most Game Engines have tools to manage the behavior of NPCs. In GameMaker one of the tools is to create a Path and then assign the NPC to the path when the game starts. A Path in GameMaker is an object that consists of a set of points on the screen in a particular order. When an NPC is assigned to a Path it will automatically followthe path as the game runs.

Using a Path consists of:

A. Creating a Path object B. Assigning the Path object to an NPC object C. Setting the path variables.

When the game runs, each time through the game loop, the object assigned to the path will move along the path. The default Path actions for NPCs include moving and performing a defined action when the end of the path is reached.

Along with setting an NPC on a path, the game programmer can also control the actions of the NPC while they are on the path. This is done by adding a scripting component to the object and checking, each time through the game loop, what percent of the path has been completed. The events that the NPC needs to listen for are:

Create Event ? happens when the game starts and the NPC object is created

Step Event ? happens each time the game loop is executed

The actions behind each of these events include:

Create Event initialize the object and assign the Path object to the NPC object and start the NPC on the path

Step Event check the position of the object on the path and perform actions based on position

Using GameMaker 8.1

Using GameMaker Studio 2.0

NPCs in GameMaker 8.1

1. Download and unzip the BraidGraphics file. 2. Start a new GameMaker document. 3. Add the following sprites located in the indicated folders in the braidgraphics folder

animation-set/greeter-walk-50-w.gif ? name this sprite dinoleft animation-set/monstar-walk-w.gif? name this sprite monsterright icons_128/door1.png ? name this sprite door icons_128/flower.png ? name this sprite flower

4. For each sprite, make sure you click the Center button to set the sprite origin. 5. Create a background by loading the background image named bg_4_02.jpg ? name this level1back 6. Create a room. 7. Click the settings tab and name the room level1and set the size as 1280 by 720. 8. Click the background tab and add the level1back background. 9. Create objects for each sprite and name the objects dinoobj, monsterobj, door, and flower.

You will next add a path and behaviors for some of the objects. 10. Right click the Path folder and choose Create path. 11. In the path window click the show room button and choose the room show the room.

12. Set the Snap X and Snap Y values as 32 if they are not set to this value. 13. Click points on the screen to set positions. Lines will automatically be drawn between position. Point to a path

position and click and drag to resize the path. 14. Change the path name from Path0 to MonsterPath and click the green check mark to save the path. 15. Open the Monster object and click Add Event. 16. Choose the Create Event. 17. Click the Path button and drag it into the Actions area

18. In the Set path dialog box choose the Monster Path, set the speed to 4, and set the At End action t o reverse. 19. Click OK to set the path for this monster. This path will be automatically loaded when the monster is created (at

the start of the game). 20. Open the Dino object. Add events Press Left, Press Right, Release Left, and Release Right. 21. For the Press Left and Press Right add the move fixed button and move left/right and set a speed 5 22. For the Release Left and Release Right add the move fixed button and set the speed 0 23. Open the room and click the Objects tab. 24. Add the Monster object towards the top part of the screen, add the Dino object and the door object towards the

lower part of the screen. 25. Run your program.

NPCs in GameMaker Studio 2.0 1. Start a new GameMaker 2.0 project. 2. Add the following sprites located in the indicated folders in the braidgraphics folder animation-set/greeter-walk-50-w.gif ? name this sprite dinoleft animation-set/monstar-walk-w.gif? name this sprite monsterright icons_128/door1.png ? name this sprite door icons_128/flower.png ? name this sprite flower bg_4_02.jpg ? name this sprite background 3. Open the room object and set the size as 1280 by 720. 4. Click the Background link and add the background sprite Background. 5. Create objects for each sprite and name the objects dinoobj, monsterobj, doorobj, and flowerobj. 6. Create a new Path object. 7. Name this path Monsterpath and click to set the following points:

8. Open the Monster object and click Add Event. 9. Choose the Create Event.

10. In the Create Event window type the word Path. 11. Drag the first red path icon into the area. You see options for the path. 12. Choose the MonsterPath for the path name, set the path speed to 4 and change the On End action to Reverse.

13. Open the Dino objects. 14. In the Add Event choose the Key Down left option. 15. Type the word Move in the search window.

16. Chose the first blue arrow icon with four arrows and drag it into the edit window. 17. Set the direction arrow to left. 18. Type the search term Speed.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download