Explain to me how the collisions work in this game, provide the code
Great, but i warn you that it gonna a be a big explain, sorry if in the comments I have spell error (im mexican).
Here is the code (just for bottom collision), I suggest you hightlight the code:
//Defining the boxBottomMeeting ubication;
package myGameLibrary.Collision{
//Importing flash classes, because i gonna use them in my function;
import flash.display.MovieClip;
import flash.geom.Rectangle;
//boxBottomMeeting function starts here.
//Notice that I manage a Array, that array holds the instanes that
//I gonna check for collsion. The function return a boolean that says
//if a collision ocurred;
public function boxBottomMeeting(clip:MovieClip,dist:int,array:Array):Boolean {
//The boolean that I gonna return;
var collide:Boolean = false;
//Clip is the player, but it can be any Movieclip I want;
//Box is a rectangle that is part of my custom class;
var w1:Number = clip.box.width / 2;
var h1:Number = clip.box.height / 2;
var x1:Number = clip.x + clip.box.x + w1;
//Okay I gonna explain the previous var part for part...
//I add to the clip.x the clip.box.x for manage boxes with different positions;
//Same thing as previous var.
var y1:Number = clip.y + clip.box.y + h1;
//I gonna define this vars latter...
//Acutally is the same thing that I do with upper vars.
var x2:Number;
var y2:Number;
var w2:Number;
var h2:Number;
//Looping all the array to check if theres a collsion;
for (var i:int=array.length-1; i>-1; i--) {
//The same thing that I do previously, but this is for the
//second object indispensable for check the collision.
w2 = array[i].box.width / 2;
h2 = array[i].box.height / 2;
x2 = array[i].x + array[i].box.x+w2;
y2 = array[i].y + array[i].box.y+h2;
//Checking if clip (in this case player) is higher than
//array[i] (in this case the wall)
if (y1 > y2) {
//Okay, is hard to explaind this, I gonna try to explain it in
//a image more later...
if ((y1< y2+h1+h2+dist)&&(x1>x2-w1-w2+1)&&(x1< x2+w1+w2-1)) {
collide = true;
}
}
}
//Return if theres a collsion;
return collide;
}
}
Here a image where I explain how the function and variables works:
Collision image.I hope this is sufficient proof