Search tutorials
This code loops through all the variables in an array called passwords(in the root timeline) If there is something in the passwordText text field, the game checks to see if the text field matches any of the passwords in the passwords array. If it does, it sets level equal to a-1, and makes the root timeline load a level. (We haven't done anything in the root timeline so none of these variables mean anything, but we'll get to that later.) Finally, we set the gameOver movie clip to be invisible. If the wrong password is typed in, the wrongPassword movie clip is displayed. Note that even if one of the passwords is wrong, then the next time you see the gameOver movie clip, the wrongPassword movie clip is shown. The way to stop this from happening is to say that whenever you see the gameOver movie clip, the wrongPassword movie clip is invisible. Now if the passwordText doesn't have any text, the level is set to zero, a level is loaded, and the gameOver movie clip is invisible. After you've done that and had a quick break, make a movie clip called cone and draw a traffic cone. Then make a movie clip called snow and put in slippery-looking snow. Now make a movie clip called snowball and draw a snowball. Finally, make a movie clip called platform and a movie clip called bigPlatform. In the platform movie clip, draw a snowy platform(The graphics i made are really basic, but you can make more advanced ones.) In the bigPlatform movie clip, make a platform as wide as your movie. Now give each one the same linkage names as their library names(Not the movie clips you already put in other movie clips, though) Then type in the following script:
level = 0
levels = {}
clipArray = ["cone", "snow", "snowball", "platform", "bigPlatform"]
passwords = []
_root.createEmptyMovieClip("world", 30)
_root.attachMovie("character", "char", 1000)
_root.attachMovie("bigPlatform", "ground", 20)
_root.attachMovie("energy", "energyClip1", 40)
_root.attachMovie("energy", "energyClip2", 50)
_root.attachMovie("ready", "readyClip", 5000)
_root.attachMovie("gameOver", "gameOver", 6000)
char._y = 250
char._x = 25
char.jump = false
ground._y = 350
energyClip2._x = 450
readyClip._x = 100
readyClip._y = 100
gameOver._visible = false
First, just like the other game, we set a variable called level that is equal to zero, and an object called levels, but we don't add anything to it(but we will later.) Then we create two arrays: an array called clipArray containing five different movie clips we made, and an empty array called passwords, which we talked about in the gameOver movie clip. Then, we make an empty movie clip called world(you should do this alot in games like this) Then we attach different movie clips(the character, the ground, etc.) Note that we attach the bigPlatform as the ground, but we will also use it in the levels we make. This is also why we set it's width to the same width as the movie. Then, we set all their properties and variables. This is really important in a game like this. The next function makes each level. Copy and paste the code into Flash.
function makeLevel(num, clips, xArray, yArray, tArray, password){
levelName = "level"+num
levels[levelName] = {}
levels[levelName].clips = clips
passwords.push(password)
for(a=1; a<=clips; ++a){
name = "clip"+a
levels[levelName][name] = {}
levels[levelName][name].x = xArray[a-1]
levels[levelName][name].y = yArray[a-1]
levels[levelName][name].type = tArray[a-1]
}
}
This code is kind of simple. The makeLevel function accepts many parameters: num(the number level it is), clips(the amount of movie clips we put in the level), xArray(the array of x positions for each clip), yArray(the array of y positions for each clip), tArray(the type of clip each movie clip is), and password(the password that people can use to play that level again) First, we create an object depending on the num variable that we put inside levels. Then we store the clips variable inside the object we just created. Then, we push the password into the passwords array we created earlier. Finally, we loop through all the clips and store their x and y positions and their types in an object thats name changes each time the loop happens. This way, we can create a level with the makeLevel function and all of its contents will be added to an object. This makes level creation much easier. Go to the next page to learn how to load the level.
| » Level Intermediate |
|
Added: 2004-12-29 Rating: 6 Votes: 14 |
| » Author |
| I love making flash games but it's really annoying when Flash doesn't work! |
| » Download |
| Download the files used in this tutorial. |
| Download (17 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!