First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
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: 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.