A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11336 Flash Movies | 2 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Surjit Dhami
» Title: Book
» Description: Book
» More by Surjit Dhami


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5848 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: All-American Rejects
» Description: Get to know this great band by exploring their "practice room".


Random Links | Add your own Flash Related Links
Flash Tutorials 1277 Tutorials 7 New Tutorials Added!
What's New | Top100

» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» HTML Photo Gallery Tutorial
» Create your first flash site – PART 1
» How to Make a Flash Photo Gallery
» Unknown Tag: Title10
Random Tutorial | Add Site

Trading Customer Accounting (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Games

Categories Making a cool multi-level game
Author: Jesse

 
Page 10
«prev 1 2 3 4 5 6 7 8 9 10

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!

«prev 1 2 3 4 5 6 7 8 9 10

» Level Intermediate

Added: : 2004-12-18
Rating: 6.12 Votes: 18
Hits: 245
» Author
Just started working with flash and now i can't stop!
» Download
Download the files used in this tutorial.
Download (21 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs