Search tutorials
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 isnt on the ground and isnt 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 isnt jumping, then hes not falling and ySpeed is set to 0. Dont worry, if hes on a platform, he wont fall! Note that in most games, there wont 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 its fun to do in this game to make it more like real life. If the clip is a snowball, and its visible, you get energy and it becomes invisible. Finally, if its a platform, and youre 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 werent jumping, you still wont 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 |
| » 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!