Collisions. Ball vs a wall!

Hey,
Hopefully someone can spare me the pain of getting this collision to work.
I’m very very new to collisions, and I’ve managed to get the ball to bounce of a wall, but there are two major problems:

  1. If I keep pressing the button toward the wall, I’ll go through it, and the entire thing just goes nuts.

  2. My collision array, I’m sure, is the stupidest/slowest way in the world. (You’ll see what I mean below).

I use an array to draw my map. Currently it looks like:


levelOne = [
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        ];

I draw it with:



var level = mapData.levelOne; 
            
for (var t = 0; t <level.length; t++ ){[INDENT]for (var u = 0; u <level[t].length; u++) {[INDENT]if (level[t][u] != 0) {                       [INDENT]var newTile:MovieClip = new wall;                       
addChild(newTile);
                        
with (newTile) {[INDENT]gotoAndStop(1);
x = 30 + (u * 60);
y = 30 + (t * 60); [/INDENT]}
                        
collisionArray.push(newTile);[/INDENT]}[/INDENT]}[/INDENT]}

As you can see, I put each tile into a collisionArray so when doing collisions I use:

private function checkCollisions():void {
    var arrayCount:Number = collisionArray.length;

    for (var a:Number = 0; a < arrayCount; a++) {
        if(collisionArray[a].hitTestPoint(newPlayer.x-newPlayer.radius,newPlayer.y,true)){
            xSpeed *= (0 - bounce);    
            collisionAnimation();            
        }

        if(collisionArray[a].hitTestPoint(newPlayer.x+newPlayer.radius,newPlayer.y,true)){
            xSpeed *= (0 - bounce);
            collisionAnimation();  
        }
        
        if(collisionArray[a].hitTestPoint(newPlayer.x,newPlayer.y-newPlayer.radius,true)){
            ySpeed *= (0 - bounce);
            collisionAnimation();
        }
        
        if(collisionArray[a].hitTestPoint(newPlayer.x,newPlayer.y+newPlayer.radius,true)){
            ySpeed *= (0 - bounce);
            collisionAnimation();
        }                        
    }
}

I know… I know… Awful coding… But any help?

  • CrimsonHEART.