Game Development Reference
In-Depth Information
Adding the Collectibles Object and Exit
1. Create a new object ( Misc group) called obj_exit and give it the spr_exit sprite.
2. Add a Create event and include a Set Variable action ( control tab) that sets
image_speed to 0.5 . This halves the animation speed of the exit sprite.
3. Select the obj_score object and right-click to Duplicate the object. Call the new object
obj_collect_count and give it the spr_icon_collect sprite.
4. Add a Create event and include a Set Variable action that sets image_speed to 0 .
This stops the sprite from animating, as only the first image of the sprite contains the
initial collectibles icon and the remaining nine are the compass pointers used later on.
5. Add a Set Variable action that sets collect_total to instance_number(obj_collect) .
This is a function that provides the total number of instances of a particular object on
the current level, a bit like the Test Instance Count action.
6. Include a Set Variable action that sets collect_percent to 0 .
7. Add a Set Variable action that sets obj_exit.visible to false . This hides the exit at the
start of the level. Again, this is done in the collect object so that the exit only gets
hidden when the user interface is turned on.
8. Add a Step, Step event and include a Set Variable action that sets collect_current to
collect_total-instance_number(obj_collect) . In other words, the number of items
collected is the total number to start with minus the number remaining on the level.
9. Include a Set Variable action that sets collect_percent to
(collect_current*100)/collect_total . This turns the number collected into a
percentage from 0 to 100.
10. Include a Test Variable action that tests if collect_percent is larger than 75 . W e have
just hard-coded the percentage of items that need to be collected before the exit is
revealed, but you could make this a global variable, or even a constant.
11. Include a Start Block action.
12. Add a Set Variable action that sets obj_exit.visible to true . This reveals the exit.
13. Add a Set Variable action that sets exit_direction to
point_direction(obj_zool.x,obj_zool.y,obj_exit.x,obj_exit.y) . Remember, this
function provides the angle from one position toward another, in this case
X1 = obj_zool.x , Y1 = obj_zool.y and X2 = obj_exit.x , Y2 = obj_exit.y .
14. Add a Set Variable action that sets image_index to 1+round(exit_direction/45) . The
angle stored in exit_direction will be in the range 0-360, so dividing it by 45 will give a
value between 0-8 that maps onto the appropriate compass image. The round function
rounds fractions up to the nearest whole number.
15. Include an End Block action. The Step event for obj_collect_count should now have
the eight actions shown in Figure 6-10.
 
Search WWH ::




Custom Search