First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Jesse
function checkForCollisions(){
	if(char._y<=250 && char.jump==false){
		char.ySpeed = -5
		char.falling = true
	} else if(char._y>250 && char.jump==false){
		char.ySpeed = 0
		char.falling = false
	}
	for(a=1; a<=levels[levelName].clips; ++a){
		name = "clip"+a
		if(char.hitTest(world[name])){
			if(world[name].type==1){
				energy1 -= 2.5
				oldSpeed = char.xSpeed
				if(char.xSpeed>0){
					char.xSpeed -= 2.5
				} else {
					char.xSpeed += 2.5
				}
				if((char.xSpeed<0 && oldSpeed>0) || (char.xSpeed>0 && oldSpeed<0)){
					char.xSpeed = 0
				}
			} else if(world[name].type==2){
				energy2 -= 1
				oldSpeed = char.xSpeed
				if(char.xSpeed>0){
					char.xSpeed -= 2.5
				} else {
					char.xSpeed += 2.5
				}
				if((char.xSpeed<0 && oldSpeed>0) || (char.xSpeed>0 && oldSpeed<0)){
					char.xSpeed = 0
				}
			} else if(world[name].type==3 && world[name]._visible==true){
				energy1 += 5
				world[name]._visible = false
			} else if(world[name].type>=4){
				if(char._y<=world[name]._y-90){
					char.ySpeed = 0
					char.jump = false
					char.falling = false
				}
			}
		}
	}
}

This is pretty complicated(AGAIN!) so you should read how it works. First, if the character isn’t on the ground and isn’t jumping, his ySpeed is set to -5 and falling is set to true.(That took me hours!!!) If the character is on the ground, and isn’t jumping, then he’s not falling and ySpeed is set to 0. Don’t worry, if he’s on a platform, he won’t fall! Note that in most games, there won’t be a ground, so you should just check for jumping being false. Then, we loop through all the clips in the current level and check for a collision with them. If there is a collision, then we check to see what type it is. If the type is 1, you lose some energy, and depending on your xSpeed, you go slower. Then if the type is 2, we do the same thing but you lose a different kind of energy. This is not something you need to put in your games, but it’s fun to do in this game to make it more like real life. If the clip is a snowball, and it’s visible, you get energy and it becomes invisible. Finally, if it’s a platform, and you’re on top of it, your ySpeed is set to 0, jump is false, and falling is false. This way, even if falling was set to true at the beginning because you were high up and weren’t jumping, you still won’t be falling if you get on a platform. Next, we will do a checkGame function like in the other game.

» Level Intermediate

Added: 2004-12-29
Rating: 6 Votes: 14
(10 being the highest)
» Author
I love making flash games but it's really annoying when Flash doesn't work!
» 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: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
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: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.