Gw Temp

Menu

Tutorial - 'The Gfactory Tutorial Part 2: Basic SideScrolling' by GotMilkXtreme2

An item about Clickteam posted on

Blurb

The second part of GotMilkXtreme2's The Games Factory tutorials, this time covering enemies and basic variables.

Body

The Ultimate Gfactory (Klik Intro) Tutorial Part 2 Making Simple AI for Sidescrollers By GotMilkXtreme2

Gfactory (The Games Factory (Klik)) is probably the easiest 2D side scroller/minigame/etc... maker I have found yet and is free (well, a free trial). It's a lot easier than its 2d competition "Gamemaker" but that's controversial.
You can download Gfactory at the Clickteam website. Unfortunately they only include a 30-day trial.

On with the game making! In this tutorial you will learn:
To create simple wander, look, and shoot ai badguys
-- how to create a character badguy that will patrol a certain area and then try to shoot you when you walk by
-- how to make groups (to be less specific with your objects)
-- how to work with coordinates and simple variables (sounds hard but its really, really easy)
What you should know: -- How to create a main character that can shoot bullets from a platform (tutorial for the complete beginner)

---------------------------------------------------------------------------------------------------------------
For this tutorial I'm going to use the .gam from the "Tutorial for the complete beginner". So if you haven’t made that game, make a backdrop object, a bullet of some sort and a main character. Sort out the main character so that he can shoot the bullet and walk around the backdrop object (platform).

Now create an enemy of some sort. For this tutorial I've created a green square as the badguy. You'll have to make the badguy an active object, because any object that's going to interact with something else in the game should be an active object.
You will have to create a group. Groups are mostly for objects that you want to categorize, for example we're making AI for the badguys, and you may want to create more than one badguy. So right click the green square badguy and click the "object prefrences" button, and click "add" in the lower left of the window.
These are all the qualifiers (groups) you can choose from. Click the Group.Bad (angry face) button and click ok to both menus. Now your object is within group.bad and you can use that category in the event editor to make multiple objects (or one object that you don't have to know about) do stuff.
Now create 2 more active objects. Make one of them an arrow pointing right, and another an arrow pointing left (you don't necessarily have to make arrows, these are just markers that will help the badguy patrol an area). A very fast and easy way to do this is draw one arrow pointing one direction, and then right clicking it and clicking "New Object>>>Active". This will create a new object that is a replica of the last one, but will still have attributes of its own. To flip the arrow around, you can enter the animation menu for the active object, get into the mini paint program, and select the "Flip Horizontally" button" Once you've finished making the arrows, put them on either side of the badguy like in the picture.
Now enter the "Event Editor". Right click on what the highest number down the line is for you, click "insert>>>a group of events".
A group events window should appear. Type "Badguys Movement";; Keep the box that says "active when level starts" checked and click ok.
Now this is where it could get a little bit confusing for some people if this tutorial hasn't become confusing already ;-). Just follow through the tutorial even if you have no idea what’s going on, and at the end I guarantee that you'll know what you’re doing.
Under the "Badguys Movement" group there should be a box that says "new condition" (of course, this means that you can make a new condition and an action there). Right click the number on that event line under the "Badguys Movement" group and click "insert>>>a new line". It'll take you to the new condition window.
Right click the timer in the upper most left corner. Click the "Every" button in the drop down menu. Now in the minutes box leave 0, in the seconds box leave 0 and in the hundreths box leave 1.
Each object has columns that go up and down throughout the event editor. Find the column for "group.bad" and align it with the event that was created (the event line). Right click the box that aligns the event and the column to "group.bad" and select "Position>>>Set X Coordinate"
The "Set X Coordinate" box should have appeared, stating 0 in the syntax field. Click "Edit" to the right of the syntax field, and click "Retreive data from an object". The "Get data from objects” window should appear and right click on the group.bad object/group and select "position>>>X coordinate". You should now see the syntax field again saying X("Group.Bad"). add in " - 1" So that you'll have " X("Group.Bad") - 1 ".
Now you'll be able to play your game and watch as your badguy active object slowly makes his way left. This should be understandable because you took the X coordinates (left and right position of object) and every split second you've made the object minus 1 {X("Group.Bad") - 1} from its position.
So how do you think you'll be able to make the badguy go right? Yes, add instead of subtract, but the badguy is still going to have to have something else that checks whether he has to go right or left: for example, say the badguy is going right and touches the left arrow telling him to go left. You still need some kind of condition in there that says that he touched that arrow. This will be done with numbers.
Go back to that event line and add a new condition by right clicking its number and selecting "Add a new Condition". There are two types of numbers you can use. One is a global value, but that isn't necessary here because a global value is something that works across levels. So right click "Group.Bad" and click.
"Values>>>Compare to Alterable Value A" (Which simply means check what alterable value A is [a number] before doing stuff [the actions])
Let’s have the value equal 2 for left, and 3 for right. So change the 0 in the syntax field into 2, because X is being subtracted from here. Now if you play your game you'll see that the badguy doesn't move left, this is because the alterable value doesn't equal 2. The badguy can either start out going left [2] or right [3], so you decide which way he will be going first. I wanted to keep my guy going left at first so I created a new event line in the beginning of the game (NOT WITHIN THE GROUP OF EVENTS!!!) that said, if timer equals 00"00"00, then alterable value A of group.bad is equal to 2. Remember not to add a new condition but to insert a new event!
So create another event under the lowest one, that you followed the tutorial with all this time, and make it about the same as the other event that was created except that the "Alterable Value A" of "Group.Bad" is equal to 3 and the x coordinates are added to "{X("Group.Bad") + 1}" instead of "{X("Group.Bad") -1}".
Now to make the badguy turn create another event right under the one that was just created. For the conditions of this event right click group.bad and select "Collisions>>>Another Object". Click the Arrow you made earlier that was pointing right and click ok. Now for the actions, under the group bad column (for the third friggin time) right click and click on values. Now click "set value" and type 3 into the syntax field and click ok. Now, assuming that you made the badguy go right when "group.bad"'s Alterable Value A was set to 3, when the badguy hits the arrow pointing right, he'll go right! Now do the same thing for him to go left (of course this time you'll have to set the value to 2).

If you want to skip this part you can


Whew...big part done already huh? Now before we make the badguy stop and shoot at the hero...sphere...active object (err whatever you made the hero), we need to make the badguy blow up or something when the hero hits him with one of his shooting stars. So make a collision between the shooting star object and the badguy. ------- Go to event condition in the event editor, (DON'T make it in the "Badguys Movement" group of events) and select "Badguy1>>>collisions>>>shooting star". Now search for the sound column. Right click it and select a good wav file for destruction! Now right click under the badguy1 column (NOT THE GROUP.BAD COLUMN!!!) and select destroy. It'll look kinda weak but you could always add some effects.

Back to the show

Now we need to make the badguy ao [active object] stop and shoot at the hero ao. Start by going into the level editor and creating a thin strand (active object). I named the strand "Hero Detector" because the program will check if the hero ever hits the strand. If he does the program will then check whether the hero is to the left or to the right of the badguy by comparing X coordinates. If the X coordinates of the badguy are <= the hero the badguy will shoot left, and vice versa.
To be concluded (part 3)... "I'm tired now let me get some sleep"