KNP Code Solutions

Back to Top

Editing Power Ups Question:

I'm making a game and in it I have a big brick wall which a ball hits. When it does, it smashes out a brick. Each time this happens I want to be able to create say 15 different power ups that drop down the screen for a paddle to catch. How do I get my game to do this randomly so that no game is the same? I know it probably has something to do with values, but as there isn’t much explanation of these mysterious things in the Klik & Play manual. I need the power ups to appear from wherever the ball just hit and a brick has been destroyed.

A Solution:

There are many ways of course, but allow me to choose one. The ball hitting the brick is done, and the brick is destroyed. Now the new bit:

Level Editor:

Create an active object and name it `powerup'
Edit the animation of the powerup object:
Set Number of Directions to 32
Set direction arrow to dead-right (0)
Edit the image - your first powerup
Set direction one above the current direction (1)
Edit that image with your second powerup
Continue counter-clockwise until you have 15 powerup images (This should look like the top right quarter of the directions are all filled with images)

Note: We do this so we can change the powerup by simply changing the direction – remember

the movement has NOTHING to do with direction if we control the objects X and Y position ourselves! We will do the movement later in the event editor.

Event Editor:

When ball hits brick, destroy brick AND create new powerup object where the brick is:
Create ("powerup") at (0,0) from ("brick")
Make the powerup look like a different one each time by selecting a random direction (0 - 14)
Set Direction To Random (15)
Always move powerup objects down the screen:
Y Position ("powerup") = Y Position ("powerup") + 1
If powerup object leaves bottom of screen, destroy powerup:
If Y Position ("powerup") greater than 480 then Destroy ("Powerup")
When powerup hits bat, collect powerup
If ("Powerup") collides with ("bat") then Destroy("Powerup") AND get powerup!

 

Back to Top

 

 

 

    Where are VALUES used and what are they used for?

A Solution:

A big subject - with very little to it. A value, counter, global value, alterable value or INI number / item are all variables. Variables are thinks that remember numbers. If you tell a variable to remember the number 42, it will remember it for as long as it is supposed to.

Counters and Alterable values: remember their values up until you exit a level or frame. If you jumped to level two, then jumped back, these values would be forgotten.

Global Values: remember their values for as long as the entire game is INI number items: remember their values until you format your hard drive. They are stored on your hard drive for safekeeping.

Use: Use them anytime you want them. For example, say you need to count how many times the player clicks on the clown...ok, set your controls so that when the user clicks on the clown object, ‘1’ is added to the counter.

Or, you want to control how high a balloon can sour before it bursts. A value could be used to store the height, and code like this would be used:

At Start:

Global Value (1) = 100
Y Position ("Balloon") = 200
Always:
Always move balloon up the screen: - Y Position ("Balloon") = Y Position ("Balloon") - 1
If Y Position ("Balloon") less than Global Value (1) then Destroy ("Balloon")

Values are what you make them. They are not special, nor are they magical. If you don't need one, don't use one. When you know how they work, you’ll know when you need one =) I hope this sums up the chapter on elementary algebra.

Back To Top

 

 

 

    Can you explain how to develop the ‘randomising’ programming capabilities in Klik & Play menus. Can you give me an example? Step by step in plain English?

Solution:

No problem! Here is an example.

Level Editor:

Select a New Counter Object
Change the DISPLAY AS from "HIDDEN" to "NUMBERS"
Select OK to confirm
Select OK and drop into level

Event Editor:

Follow this exactly to make the SPACEBAR prompt the generation of a random
number in the counter, in as fine a breakdown as humanly possible: -

1) Right click on NEW CONDITION
2) Double click or Right click the MOUSE BUTTON AND KEYBOARD OBJECT
3) Select the Keyboard ... .And Upon Pressing a Key
4) Press the SPACEBAR
(You have now created a condition that will trigger when you press the spacebar)
5) Under the column of ("COUNTER 1") Object where the action goes, click the Right Mouse Button
6) Select Set Counter
7) Click EDIT (this can give you every piece of data available from your game)
8) Now select RETRIEVE DATA FROM AN OBJECT
9) You are given a window containing all the objects available at that time, have a really good look around at all the data you can have. All the possible values you can put in your counter. Is it not a wonderful sight? Anyway…
10) Right Click on the one that looks like a spanner (named SPECIAL)
11) From the list, select GENERATE A RANDOM NUMBER
12) Now type a number, I recommend 42, it's a remarkable value
13) Select OK to confirm your range...by giving 42 you will generate a range of
anything from 0 - 41 (42 possible states you see?)
14) Random (42) will appear in the expression area - instead of all that window
stuff, you could have just typed Random (42) if you wanted.
15) Select OK to confirm the expression
16) The action will read Set Counter to Random (42), select OK to confirm this!
17) Run the program, and press the spacebar
18) IF YOU DIDN'T UNDERSTAND RANDOM BEFORE, YOU DO NOW!

 

Back To Top

 

 

 

    I am having trouble coding a strategy game. Here's the problem: The player has 28 characters on the screen that he must lead over and ‘kill’ another 28 computer controlled characters. How do I program so that when one of the player's characters are within say, 120 pixels, of the bad characters, they blow up and die?

A Solution:

I am assuming that it is the ‘enemies’ that blow up and die, but any combination is simple. The trick is to define an 'aura' around your characters that determine the extent of the destructive abilities. If the enemies could destroy your characters, THEY would have the aura. If both destroyed each other, one would have the aura but you would command them both to be destroyed.

The 'aura' is generated in the Level Editor, believe it or not. You can switch off the masking of the image so you can create a huge object area, draw the guy in the middle and collisions could be detected based on the empty space within the image, not just when the two images touch.

Do this:

Level Editor: -

Create a new object and make an image - go to the picture editor
Specify a size of 240 x 240 for your character (guy has 120pxl radius aura)
Draw a 32x32 image dead centre of this large area (do not clip)
Move to HOT SPOT to the centre of the image
Select OK, and OK again to confirm the object
Go to the menubar and duplicate another ten of these objects, as these are your army of guys that will represent YOU.
Do exactly the same and create a new object for the ENEMY
Now you have 10 guys of yours, and 10 guys of the enemies (two objects each duplicated 10 times)
For each object, click the right mouse button to get the poop-up menu and select Object Preferences
Click the EXTRA Tab and tick-off 'Use Fine Detection' - this makes the image collide when it hits the area of the object, not the contoured image inside the area.

Event Editor: -

Simply create a condition which detects for an overlap between YOU and the ENEMY guys, where upon you can destroy anything you wish. You can make yours destroy, the enemies destroy or both destroy! We will make yours destroy the enemies guy: >> If ("YOU") overlap ("ENEMY") then Destroy ("ENEMY")

How simple is that. Well, too simple. You now cannot use the guys for fine collision detection like wandering through trees and protruding obstacles. But there are other means of detection, and other means of 'aura' generation. For one problem, this is one solution - and certainly not the only one.

 

Back To Top

 

 

 

    How does a programmer make Tetris come to life? I know how to make borders so objects won't cross the playing-field, but for example, how do I let the objects come one after the other?

Solution:

A big question - how do I make a Tetris Game ...hmm. Tetris might look simple, but to create it from scratch is a huge task, and not likely to be described successfully within these few pages of text. I can break the game down into more understandable components so you might see what needs doing and come up with your own solutions to the individual problems:

1) Create some shapes that you can rotate (ie longline, L-shape, cube block)
2) The shapes must move down the screen and stop when they cannot slide any further down
3) When a line is detected to be filled, remove the blocks from this line and scroll
any blocks above it one down, taking note that your shapes will have to be divided up.
It makes sense then that our shapes where divided up to start with (made from small
blocks) and grouped together to form shapes.
4) When the Tetris board fills up, the game is over
5) Show the next shape to be used
6) Keep score and high-score

To tackle the original question, how to move them down one after the other. The game needs to know that a shape is still being moved down the screen. ONLY when the shape has landed, can another shape be dropped from the top of the Tetris board. The rules may look like this:

a) Start game
b) Randomly select a shape
c) Drop shape from top of board
d) Keep sliding down
e) When it collides with another block from a previous shape or the floor of the
board, Go to (b).

Events that rely on a previous one being completed before it can proceed are heavily used in games of a more complicated nature. This is where VARIABLES are used. You may know them as counters, values or global values. We can say that each letter is a different value so (a)=1, (b)=2, etc. So your code may look like:

If Counter = 1, play some cool music and set counter to 2
If Counter = 2, randomly select a shape and set counter to 3
If Counter = 3, set shape at top of screen and set counter to 4
If Counter = 4, add 1 to the shapes Y vector.

[Object positions on screen are controlled by an X and Y, to say how far across and down they are from the top-left corner of the screen. If we took an objects Y vector, and added 1 to it, and gave it back to the object, it would seem as though it has moved down the screen! We use this almost always in large games to take full control of our objects =)]

If Counter = 4 AND it collides, set counter to 2

Follow this logic through as though you where the computer, and see how the computer must wait till the shape has hit the floor or another shape before it can randomly select another shape and do it all over again. Simplified of course, but it should demonstrate the process of controlling events using VARIABLES.

 

Back To Top

 

 

 

    In the real world, a space-ship is affected by gravity, as are   weapons....and the turning of the ship doesn't affect your course until you apply throttle...unlike using "race-car" control setup. How can this be done with Klik & Play?

A Solution:

Making your character move like this is extremely easy if you have done it before. After this answer, you’ll kick yourself! Create a new active object and draw your character and drop into the level editor. Do not change the movement type: we will need to keep it as a static movement because we will be controlling the movement ourselves (directly!). Advanced programmer types reading this will be looking for a COS / SINE table about this time - well we ain't got one yet so we'll have to cheat =) Create a second active object that we will keep invisible, and also place on the play-field. The basic idea is that the invisible object we created is going to control our ships thrust power, so we'll call it THRUSTER BULLET, for reasons to become clear.

In the event editor, code the following:

Always Shoot THRUSTER BULLET from SHIP in the direction the SHIP is pointing.
Always add 1 to the Alterable Value A of THRUSTER BULLET
If Alterable Value A of THRUSTER BULLET is greater than 50, destroy THRUSTER BULLET

The above code will look like a rapid stream of bullets shooting out of the ship and ending some distance from the ship. Add this:

NOTE: Key Pressed means 'sustained press' not 'when pressed'; we need continual sustained input from user!

If LEFT ARROW Key pressed, add 1 to Direction Value of SHIP
If RIGHT ARROW Key pressed, subtract 1 from Direction Value of SHIP

This will rotate the ship left and right, and notice as the stream of bullets forms a perfect line away from the SHIP in whatever direction you choose. This is the cheat! This will give us the velocities we need for the movement.

The movement is different from what you may be used to. The SHIP is positioned on screen by an X and a Y value (how far across and how far down), and we'll need to 'constantly' change these values based on which way you’re drifting. Always imagine the SHIP is drifting. Even when it is stopped, it is drifting at a speed of zero. We have 3 alterable values in the SHIP, which we will use. Alterable value A is going to store our BIG X VECTOR, Alterable Value B is going to store our BIG Y VECTOR and Alterable Value C is going to store our OVERALL VELOCITY.

The BIG VECTORS are to increase the quality of the movement, and are required for slow delicate movements. Add this:

>> At Start of Frame, Set Alterable Value A of SHIP to 320*100 and Set Alterable Value B of SHIP to 240*100
>> Always Set X Position of SHIP to (Alterable Value A / 100)
>> Always Set Y Position of SHIP to (Alterable Value B / 100)

To return to velocity, add these lines:

If UP ARROW Key pressed, add 1 to Alterable Value C (overall velocity)
If DOWN ARROW Key pressed, subtract 1 from Alterable Value C

>> Every 0.25 seconds AND Alterable Value C is greater than zero, subtract 1 from Alterable Value C. >> Every 0.25 seconds AND Alterable Value C is less than zero, add 1 to Alterable Value C.

The above code will do nothing to what you see in the program at the moment, but is responsible for letting the user increase velocity and also slows the SHIP down over time (decrease in speed).

The next bit is the magic bit. The THRUSTER BULLET ends it's life after 50 cycles (50 lots of adding 1 to Alterable Value A), and after this it should have traveled some distance before being destroyed. You must set the speed of the bullet shooting out of the SHIP so the bullet is destroyed approximately 100 pixels away from your SHIP. This is important. Keep experimenting will the shooting speed until the line of bullets is around a 6th of the width of the screen.

Now we must affect the SHIP position with a combination of direction and velocity. In the same event that Destroyed the THRUSTER BULLET, add these two actions:

>> Set Alterable Value A of SHIP to Alterable Value A + ( (X Position("THRUSTER BULLET") - X Position("SHIP") ) * Alterable Value C of SHIP )
>> Set Alterable Value B of SHIP to Alterable Value B + ( ( Y Position("THRUSTER BULLET") - Y Position("SHIP") ) * Alterable Value C of SHIP )

Wow! To really explain what's going on here is a tall order for the amateur programmer, but essentially by having a START X and Y and a DESTINATION X and Y, it is possible to get a plus or a minus X and a plus or a minus Y from them. And if you added these plus or minus values to START X and Y you would get the DESTINATION X and Y. Lets then say you wanted to only get to the destination in 20 cycles, you would divide the plus or minus values that I call 'velocities' by 20. That means you would have to add 20 of these 'velocity values' until you got to your DESTINATION. And it's this that allows us to push the ship in any direction. Alterable Value C (the velocity) simply increases the speeds up the time it takes to reach this mathematical direction. To truly understand this you'll need to break up the working code and have a think. But to continue...

If you run the program, and press the UP ARROW Key the SHIP should move in a forwardly direction, and by rotating left and right the SHIP will rotate as ordered. A nice touch also is by pressing the DOWN ARROW you slow and then reverse! But all you have managed to do up to this point is replicate the controls of the race car. You do however have the power to modify anything you wish about your code. The part about only going in a direction when you apply thrust is very easy to make possible now, providing you understand the above code. Without such understanding the next bit is deeper.

Create two counter objects and place on play-field and label them VELOCITY X and VELOCITY Y. You MUST Edit the Counters to have a minimum range of minus 99999 and maximum of plus 99999.

REMOVE THE LAST PIECE OF CODE FROM THE DESTROY BULLET EVENT WHICH READ:

>> Set Alterable Value A of SHIP to Alterable Value A + ( ( X Position ("THRUSTER BULLET") - X Position("SHIP") ) * Alterable Value C of SHIP )
>> Set Alterable Value B of SHIP to Alterable Value B + ( ( Y Position("THRUSTER BULLET") - Y Position("SHIP") ) * Alterable Value C of SHIP )

The condition which detects for the user pressing the UP ARROW Key, had an event to add 1 to the overall velocity. Add two more actions to this event to read:
>> Set X-VELOCITY Counter to X-VELOCITY Counter + ( ( X Position("THRUSTER BULLET") - X Position("SHIP")) * Alterable Value C of SHIP )
>> Set Y-VELOCITY Counter to Y-VELOCITY Counter + ( ( Y Position("THRUSTER BULLET") - Y Position("SHIP") ) * Alterable Value C of SHIP )
And when the user presses DOWN ARROW Key, do this:
>> Set X-VELOCITY Counter to X-VELOCITY Counter - ( ( X Position("THRUSTER BULLET") - X Position("SHIP") ) * Alterable Value C of SHIP )
>>Set Y-VELOCITY Counter to Y-VELOCITY Counter - ( ( Y Position("THRUSTER BULLET") - Y Position("SHIP") ) * Alterable Value C of SHIP )

And finally add the part which puts it all together:

Always Set X Position of SHIP to X Position("SHIP") + X-VELOCITY Counter
Always Set Y Position of SHIP to Y Position("SHIP") + Y-VELOCITY Counter

Even when the VELOCITY Counter are minus, the Ship’s position will be modified correctly. These are the rules:

[+] and [+] = [+] [-] and [-] = [+] [+] and [-] = [-] [-] and [+] = [-]

After a bit of tweaking for correct speeds and maybe capping the velocities so the SHIP does got go too fast, and you'll have yourself a completely comprehensive inertia controlled character. If along this winding road you got lost and built a florist in desperation, just e-mail TGFW and we'll expand any sections you’re not clear on =)

Back To Top

 

Shot at various times

 

    I have a problem about randomising. I made a game where I wanted the enemy to shoot at different times. I had to make 10 objects and then choose Pick One of Group.1 - Shoot an Object. Should I set a value to a random number and how would I do it?

A Solution:

One way is to use the System Timer. The System Timer is a stopwatch built-in that increments a thousand times a second from the moment your game is run. You can use this Timer (which can never be stopped or reset) to trigger things at different times. Lets say I want to press the SPACE and three seconds later a beep sounds. Do this:

In Level Editor:

>> Create a new COUNTER Object and place in play-field

In Event Editor:

If press SPACEBAR then Set COUNTER to Timer
If Timer > Value ("COUNTER") + 3000 then Set COUNTER to 0 and play a BEEP Sound

To make the action Set COUNTER to Timer, create an action under the COUNTER Object and select Set Counter. Click the EDIT Button and then select RETRIEVE DATA FROM AN OBJECT. You will see a CLOCK image as the first object in the window. Right click on the CLOCK IMAGE (the timer) and choose the first item "Timer count in 1/1000 since start of frame". Select OK and you now have Set COUNTER to TIMER.

For the condition that compares the TIMER with the COUNTER +3000, select the right mouse button on New Condition and select the SPECIAL Object (it looks like a spanner). You can then select "Compare to General Values". This condition will let you check ANY two values from ANYWHERE in your game - very useful. When the compare values window pops up, you must enter TWO different values to compare. In the top expression box type Timer to save time going through all the menus again. In the lower expression box click the EDIT button to the right and then RETRIEVE DATA FROM AN OBJECT. Select the COUNTER Object, and choose the only expression item "Current Value". Select OK here and then on the Compare window and you'll have created your value compare condition!

Remember RETRIEVE DATA FROM AN OBJECT allows you to 'steel' values from anything in your game. Both from built-in things like timers, random values, play-field widths to object values you have created yourself such as your player, your enemies, anything!

To the second part of the question, how to set a random value. By now, you may already have guessed, but let's just step through the process. Let’s set our COUNTER to a random value between 0 and 1999. Do this:

In Event Editor:

Make an action under the COUNTER Object and select Set Counter
Click EDIT and then select RETRIEVE DATA FROM AN OBJECT.

Select the SPECIAL Object (the spanner again), and choose the first item - which happens to be "Generate a Random Number".
Enter the value of how many random states you want. So if I put 500, the range would be 0-499. We shall enter 2000 to give us a range of 0-1999.
Select OK and you will see Random (2000) as the new expression. You could have easily typed this out yourself.
Select OK again to confirm the expression and there you have it; Set COUNTER to Random (2000).

 

Back To Top

 

 

 

    I want to create a game like tic-tac-toe, and I want the computer to pick a random place. But how do I program this?

A Solution:

Tic-Tac-Toe or for the British - naughts and crosses - is a game of awesome simplicity to play but a devil you get the computer to play with any degree of intelligence. Certainly not impossible, nor difficult if you have a good grasp of the logic - but from scratch, in TGF without a clue - then it gets tough. But to answer this particular question, one solution would be thus. Create an active object as a square and place nine duplicates of it in a 3 by 3 grid (three rows of three columns totalling 9 object copies on screen); a typical tic-tac-toe layout.

In the Event Editor:

Select START OF LEVEL as your condition
Under the Square Active Object, click right mouse button and choose Set Alterable Value and select A, then select the Spread a Value button.

NOTE: SPREAD A VALUE - If you had nine duplicates of an object in the Level Editor, this action would give each object a unique value based on the starting number. So spread a value from 5 would give each object a respective value of 5,6,7,8,9,10,11,12,13, or more useful spread a value from 1 would give us 1,2,3,4,5,6,7,8,9. Now ANY of the duplicate objects can be changed, moved or destroyed by specifying it's unique identity (value).

Specify 1 so you are spreading value 1 in alterable value A and clicking OK back the Event Editor.

It is very easy for us now to get the computer to generate a number from 1 to 9 and use this number to point to one of the objects (one of the grid positions on the board). Create a counter object named "Computer" and place it off the play-field so we cannot see it when the game runs. Now this:

If user presses SPACEBAR then Set Counter to 1+Random (9)

The 1+RANDOM (9) part of this can be typed directly into the expression box, but there is a menu system you can use too. Have an experiment if you like to see if you can find it, otherwise there is a more detailed reference about the random tool elsewhere in the Solution Zone.

You will need naughts ('0') and crosses ('X') as other objects. Let’s say the computer is always naughts ('0') and the player is cross :-) To make the computer put it's mark in the right grid position you can simply get the position of the square active object which holds the value you generated. And as ONLY ONE of the square active objects has that number, the naught will be placed on the board randomly. So:

If Alterable Value A ("Square") = Counter ("Computer") then Set Position ("Naught") to Position ("Square").

Is this daunting? Go to new condition and select the 'Square' active object and select from the pop-up menu Values. From the sub-menu select Alterable Value A and then an expression window will appear where you would normally put a value. Instead, go to EDIT and then RETRIEVE DATA FROM AN OBJECT button. Now select the counter with the right mouse button and choose the only expression from this object - Current Value. Click OK and confirm the condition. Now you need to create the action part of this line so go under the "Naught" active object (your image of a large zero) and go to action Set Position, where you will be given a sub-menu where you should choose Select Position. You'll be given a window - click on Relative To and then choose the Square active object (make sure the two upper values in this window are both zero before you click OK) then return to the Event Editor. And there you have your computer's naught ('0'). But that is just one - for many naughts you could paste it into the background and then hide it until the computer wants to select another grid location. You could create a new object and place it where you want the naught to go.

An extra tip is to destroy the Square active object when a (X) or (O) is placed there so the user cannot select there again and the computer cannot randomly select a grid place that is full. The random number generated by the computer must also keep randomly picking one until it finds one that is free - so replace the SPACEBAR condition with something more appropriate. And of course remember when there are no more grid positions (all the square objects have been destroyed) then the game is over).

Detecting for the winner is beyond the scope of this solution. Making the computer play a good game is beyond the scope of this solution. In fact, most of the game tic-tac-toe is beyond the scope of this solution. Such is life =)

 

Back To Top

 

 

 

    How do you make multiple saves using edit objects so that you can save a particular name, then have the game that you started…and yet it still saves to the same ini?

A Solution:

It is a simple matter of first creating a new EDIT OBJECT to act as your filename entry and then doing one of two things. If you want to save some game data, ask the user to enter the save-name in the EDIT OBJECT and providing you have an INI OBJECT in your frame, do the following:

In Event Editor:

Click right mouse button on the new condition and then double click on the mouse and keyboard object. Select keyboard and then choose "Upon pressing a key". Hit RETURN to enter your key for saving.

Click right mouse button under the INI Object and choose Set Current File. Now click EDIT and RETRIEVE DATA FROM AN OBJECT. Double click on the presented EDIT OBJECT and choose Get Text. Click OK to confirm.

Right. The above event will wait for the user to click the RETURN key (presumably just after entering a save-name). Your event will then take the text (Get Text) from the EDIT OBJECT and use this string to fill the expression for the Set Current File action. In short, you are setting the current INI file to what the user just entered. You will then be able to specify your groups and items and fill the INI file with your game position data. For details on entering INI file data, look elsewhere in the Solution Zone as their are several entries on this.

To load your saved games is a not much more than this. You will select from a list of saved-games. This list could be created using a C&C COMBO BOX or some TGF EDIT OBJECTS strung together. The contents of these lists will have to be created upon the user saving their game. To do this, you will require a universal INI file that just stores the 'names' of the saved-games. This way, the computer knows all the filenames you have created, and gives you them in a list so you can choose one and load the data from that particular INI file. As before, you can extract a string (Get Text) from the COMBO or EDIT OBJECT and use it to specify the INI file you wish to read.

But wait! Won't the object switch directions the moment it LOOKS towards the enemy? No. Because we are not going to use the bouncing ball movement. We are going to use our own movement code to modify the X and Y vectors. If you take the value of X (distance from left side of screen) and add 1 to it, and then set the objects current X position to this new amount, you will move the objects position 1 pixel to the right. You can use this basic idea to move the objects around the screen without using bouncing ball movement. There is much more involved in moving the object in a direction by changing it's X and Y's, and can be found elsewhere in the Solution Zone titled GRAVITY; check it out later!

Now we have objects that are moving around the screen, and LOOKING at their enemies, but not following them immediately, we can do the last two lines:

Every 1 second, if current LOOKING direction VALUE is greater than current MOVING direction VALUE then Add 1 to MOVING direction.
Every 1 second, if current LOOKING direction VALUE is less than current MOVING direction VALUE then Subtract 1 from MOVING direction.

LOOKING DIRECTION is generated all the time using an ALWAYS - Look in direction of ENEMY OBJECT. The MOVING DIRECTION is stored in an Alterable Value and the details of how and where to use this can be found in the GRAVITY solution referenced earlier. It was a big solution for a big question. If you can get through this and win, you'll be a better Clicker for it!

 

Back To Top

 

 

 

    Hi-Score INI File Question:

I am creating a game and know how to use INI Files, but I want to create a high score table and am completely baffled about how to do so. How do I it?

A Solution:

The built in Hi-Score Object does allow you to replace the contents of the board with your own entries before it is displayed. You could copy data from the INI file to the Hi-Score table and ten let the player enter their latest score then extract the data from the hi-score object and place it back in the INI file. Experiment with the expressions of the hi-score object to find out how to extract data from it. With this info, you should be able to guess how to change the data the moment your frame starts.

Back To Top

 

 

 

    Platforms Disappearing Question

Ok, here is the failing platform object level. The rock platforms will work fine at first. Then scroll to the right a little, and JUMP OFF. Go back to the start of the level and try to jump on the first platform. It doesn’t work. Some do, but not that one. This has happened in other levels; some platforms are just duds. What do I do?

A Solution:

It's not as bad as a bug - but it is a problem. The default mode for platform games seem to be the Rambo style where you go in one direction and do not ever go back under any circumstances. When your character goes back, all the platform 'MASKS' have been erased to save memory - TGF did not expect you to go backwards.

The solution is simple enough. Go to the Level Editor and select EDIT MENU from the top bar of the window. Now select FRAME SETUP and click the tag "Handle background collisions even in invisible play-field". This will keep all the platform masks intact and you will have no more platform problems.

 

Back To Top

 

 

  33

    Creating Multiple Enemies Question:

I have created a counter that sets to a random number so the enemies will appear in different places. But how do create maybe 10 enemies at one door?

A Solution:

Presuming you have 10 different objects as your enemies, you must in some way group all those objects to treat them all as a possible enemy.

In the level editor, right click on one of your enemy objects and choose Object Preferences. The window shown will hold all the group identities for this object. It is an enemy, so click ADD and double click on the Group.Bad symbol to select it. Now click OK. You have make this object part of the Group.Bad group which you can effect as though it where a single object. It is possible to ADD this Group.Bad to as many objects as you want. So all your enemy objects must have this Group.Bad symbol in their object preferences to start with.

In the event editor, it is now very easy to ask TGF to pick one of the objects which has the Group.Bad symbol and control it.

Create a condition in the event editor to read:
Every 1.00 second

You will notice a new icon at the top of the event editor called Group.Bad. This represents all the objects that have been assigned to this group. Create an action under it to position in the middle of the screen, presumably where a door would be as an example.

Right click under the Group.Bad object and select Position -> Set Position and select the centre of the screen with the box cursor. Click OK and then run. The object under this group will go to that position on the screen.

For the second part, we can create many objects (different enemies), but add the same Group.Bad symbol in each of their object preferences.

In the event editor, add a new condition onto the existing Every 1.00 second condition. Right click on the condition number 1 and select add a new condition. Choose the Group.Bad Object and go to the sub-menu Pick or Count, and select the condition Pick "Group.Bad" at random. This will add a condition that will only select one of the group each second.

If you have a few enemies on screen, all grouped to Group.Bad and run, an enemy will be selected at random and placed in the position of our example doorway. The user can then be fooled if you move ALL the enemies off the play-field and out of sight. It then appears the enemies are appearing at random at the doorway.

There is more to this technique, and I feel you're best exploring these extra challenges in your own way. For now, you have some code to write =)

 

Back To Top

 

    180 Degrees Question:

Please could you help me out with a small problem? I am trying to shoot an object at 2 deg increments (through 180 deg) from a fixed point. Apart from creating 90 objects each with one of the required paths, is there another way of overcoming this problem? The object is also required to bounce off background objects (ie Walls). A Sin / Cos Table would be very handy!

Solution:

One solution would be to use your own movement system. First imagine this.

An object starts on the left side of the screen and moves over to the right side of the screen (simple X Position = X Position + 1)

Now tell the object that every "third" pixel it should move one pixel up the screen. When the object moves, you will notice is move is a very slight diagonal line as it moves across (and slightly up) the screen. This is the basis for subtle movement systems.

To implement, create two counters (or use alterable values per object). One counter counts for the X Position and one counter counts for the Y Position. Setting these values to different numbers gives impressive results when experimenting. Another two counters will be required to set the maximum the counter can go before it resets and effects the object position.

In the Level Editor:

Create four counters (CounterX, CounterY, CounterMAXX, CounterMAXY and an active object.

In the Event Editor:

Start of Level you should Set CounterMAXX to 0 and Set CounterMAXY to 3
Always Add 1 to CounterX and Always Add 1 to CounterY
If CounterX > CounterMAXX then CounterX = 0 and Increment X Position by 1
If CounterY > CounterMAXY then CounterY = 0 and Increment Y Position by 1

Examples:

CounterMAXX=0 CounterMAXY=1000 - move at 90 degrees
CounterMAXX=0 CounterMAXY=2 - move at 101 degrees
CounterMAXX=0 CounterMAXY=1 - move at 112 degrees
CounterMAXX=0 CounterMAXY=0 - move at 135 degrees
CounterMAXX=1000 CounterMAXY=0 - move at 180 degrees

Granted this does not allow all 360 degrees of movement, but the technique can be easily extended to cover resolutions of far more than 360 degrees, not that you'll need it.

Yes, it would be no more than two event lines if we has Cos / Sin Table to use - but alas, the only way you can get that is by creating your own cos table and holding it in an INI file. But that's another story.

SCROLLING TO FOLLOW TWO PLAYERS

 

Back To Top

 

 

   Ghost Question:

I want to make it possible to be 2 players playing against each other. I would like to have TGF to centre the scrolling between the 2 cars but I can't make it work. I guess that I am forced to have some kind of "ghost" object that follows the cars and that the "ghost" object have to be the real scrolling centre, but I can't figure out a function that centre this "ghost" object between the two cars.

A Solution:

You will need a 'ghost' object, but its location is deliberately calculated to provide the perfect scroll position. Let us presume you have your two player objects and this third 'ghost' object. For the beginner, a ghost object is an object you create in the frame editor but which is turned invisible at the start of the level so you can still use it's alterable values and position, but the user cannot see it. Clever hey! No? Oh.

The calculation is mind-numbingly easy if you've seen the code before. I happen to have benefited from the inexorable skills of a former Event Writer. I stole it =)

In the Event Editor:

Always Set X Position ("Ghost") to X Position ("Object 1") + (X Position ("Object 2") - X Position ("Object 1")) >> Always Set Y Position ("Ghost") to Y Position ("Object 1") + (Y Position ("Object 2") - Y Position ("Object 1"))
And that is it. The ghost object will always be between Object 1 and Object 2. It's that simple. Now all you have to do is centre the play-field on the ghost object and you can proceed to create the next Gauntlet/Garrison! Just don't make too many Black Death ghosts or the players won't stand a chance!

 

Back To Top

Visit An Area

Technophile_City_(INFOTECH)The_Time_Machine_(HISTORY)  |  The_Tree_House_(SOSE)Lessons_Index   |  Assessment_Instruments  |  Maps   |  Power Point   |  Proforma  |  Links  |  Gallery  |  Games  |  Humour   |  Prizes  |  WebRings  |  Soapbox  |  Search_Engines  |  Site_ Map_ |

.

             Search OzEdweb by Keyword   

.CLICK ME TO VIEW FRAMES ALL_RIGHTS_RESERVED  OZEDWEB-©-VIRTUAL OZ  HOME