First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Jesse

Got all that? Now it's time to review some important tricks. First let's review the functions we used and how to re-use them. Use a loadLevel function to load in a new level. In some games, you should create the levels with a makeLevel function or alot of objects. You should to store all the levels in an object called levels, but you don't have to. Using levels in objects is a quicker way to do things in complex games because that way, instead of checking for everything with multiple if statements, you can use level objects and for loops to check for different things. Here is an example:

function checkEverything(){
	if(level==1){
		if(defeated==5){
			level = 2
		}
	} else if(level==2){
		if(defeated==10){
			level = 3
		}
	}
}
_root.onEnterFrame = function(){
	checkEverything()
}

That code is very hard to do with more than two levels and it is very hard to make new levels. Now, look at the easier code.

levels = {level1:{baddys:5}, level2:{baddys:10}}
level = 1
function checkEverything(){
	levelName = "level"+level
	if(defeated==levels[levelName].baddys){
		level += 1
	}
}
_root.onEnterFrame = function(){
	checkEverything()
}

As you can see, this code does everything in one if statement. This way is much faster and it is much easier to add more levels. The way i used to make games like these was by using different frames for each level. This is even worse! This way, you can't even use the same functions! Then, i made a game where there was a movie clip that had all the levels in different frames. In the root timeline, i would loop through everything in the game, but there were no level objects. this way, if the bad guys added up to 100, they would always be 100 in every level. This is also a bad way to do things because in Flash, you can't scroll to infinity graphically, but you can with code. With code, you can put a movie clip at an x position of 100,000,000,000! Anyway, let's review more tricks.

weaponNum = 1
weaponsList = ["rifle", "shotGun", "laser"]
weapons = {}
for(a=1; a<=weaponsList.length; ++a){
	name = weaponsList[a-1]
	weapons[name] = {}
	weapons[name].bullets = 5
}
function toggleWeapon(){
	if(weaponNum==weaponsList.length){
		weaponNum = 1
		weapon = weaponsList[0]
		return
	}
	weaponNum += 1
	weapon = weaponsList[weaponNum-1]
	if(weapons[weapon].bullets<=0){
		toggleWeapon()
	}
}
_root.onEnterFrame = function(){
	if(Key.isDown(Key.SHIFT)){
		toggleWeapon()
		trace(weapon)
	}
}

As you can see, this is a great way to toggle through a list of weapons and a great toy for babies who can't stop pressing those buttons. Paste the code into a new Flash Document and Test the Movie. Press the SHIFT key. In the Output window, it will say your current weapon. This is just another version of my cool weapon-toggling trick. You should also note the major functions you need in most games with more than one level. Repeat after the computer monitor!

loadLevel() checkForKeys() checkForCollisions() checkGame() moveEverything()

The last thing to note is that i didn't use any graphics on the stage in the tutorial. I attached them all with actionscript! This is just a nice way to make games like this(and to feel better about yourself) Now that you've downloaded the game, play it over and over again! Note that there is no winning screen. I thought you could make it yourself. Just remember not to overwrite my file. Happy game-making!

» Level Intermediate

Added: 2004-12-18
Rating: 6.14 Votes: 21
(10 being the highest)
» Author
Just started working with flash and now i can't stop!
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

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

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.