Author: Matt Slaybaugh
Date: October 12, 2006
Level: Beginner
In this tutorial, you will work with Flash variables to make the Fly Catcher game more challenging to play. The game uses many variables, including the speed of the frog, the speed and number of flies, and the size of the target area on the frog's tongue. In this exercise we'll change the size of the target area on the frog's tongue.
- Flash 8
- flycatcher.fla
This software is licensed to the public under the CC-GNU GPL.
The flycatcher game uses many constants that determine how easy or difficult the game is. These constants include the frog's horizontal speed, the frog's vertical speed, the flies' speed, and how sensitive the frog's tongue is.
You can change any of these constants to make the game easier or harder. In this exercise we'll walk through how to change the sensitivity of the frog's tongue to make it easier to catch flies.
The flycatcher game uses only two keyframes in the main timeline. Frame 1 contains the preloader animation you see when the game is loading, and frame 5 contains the game itself. All the code used in the game is either associated with the frog movie clip, the fly movie clips, or in the scripts layer of frame 5.
- Open flycatcher.fla in Flash.
- Look for the scripts layer in the timeline and click frame 5.
- Make sure the Actions panel is open. You should see about 80 lines of comments and code.
- On or near line #52 you should see a line of code that looks like this:
if ((_root.tongue == true) && (ydist < 20) && (xdist < 150) && (xdist > 90) && isfacing(fly)) {This code is performing a complex conditional check. Breaking it down we see that it is looking for:
- _root.tongue == true
- Is the variable named tongue set to true or false?
- The syntax == means is equal to
- ydist < 20
- is the y distance (vertical distance) between the center of the fly and the center of the frog less than 20 pixles?
- The syntax && simply means And.
- To make the game easier, increase this number
- dist < 150 && xdist > 90
- Is the x distance (horizontal distance) between the center of the fly and the centyer of the frog both less than 150 pixels and greater than 90 pixels?
- These numbers define a range. If the fly is between 90 and 150 pixels away when the frog sticks out its tongue, the frog will catch the fly. If the fly is more than 150 pixels away, or closer tan 90 pixels, the frog will miss.
- To make the game easier, increase the range. Instead of 150, try a larger number so that the frog can reach flies farther away. Instead of 90 try a smaller number so that the frog can catch flies closer to it.
- isfacing(fly)
- Is the frog facing the fly or facing away from it.
- This line calls upon a function named isfacing
- You can ignore this line for the purpose of this exercise.
- _root.tongue == true
- Once you have made changes, save the file and test the game (ctrl-enter)
- Make the game easier by making the frog faster—The frog's speed is set as two constants in the main script: < code >frog_x_speed (horizontal speed in pixels per frame) and
frog_y_speed(vertical speed) - Make game harder by changing the speed of the flies—The flies' speed is set as a constant, < code >fly-speed. This number is divided into the distance between the frog and fly, so smaller numbers will make the flies move more quickly
Intermediate Projects
- Make each of the 5 flies have different speeds
- Make the flies fly away from the frog instead of chasing it
- Add a second type of fly, a horsefly that is bigger and faster than the dragonflies, and worth more points
- Add poisonous butterflies, that when eaten, make the frog sick and cause the score to go down
- Add code so that the frog loses points if it touches the weeds
Advanced Projects
- Add a 'Powerup' insect, that temporarily makes the frog move twice as fast
- Have the frog follow the mouse instead of using the arrow keys
- Make the flies instances of a 'fly' class so that you can add as many flies as the player can handle
- Using PHP and MySQL, create a high-scores table that users can submit to, and which displays next to the SWF
- http://www.adobe.com/support/flash/interactivity/keyobject/
- http://www.actionscript.org/showMovie.php?id=923
- http://www.myflashresource.com/flash-tutorials/the-tank-part-2-rotating-and-shooting-the-cannonprint/
- http://www.kirupa.com/developer/actionscript/hittest.htm
- http://www.matazone.co.uk/blog/?p=72
