# Collisions. Ball vs a wall!

**URL:** <https://forum.kirupa.com/t/collisions-ball-vs-a-wall/266493>\
**Category:** Uncategorized\
**Created:** [July 21, 2008, 3:01pm UTC](https://forum.kirupa.com/t/collisions-ball-vs-a-wall/266493 "2008-07-21T15:01:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrimsonHEART](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@CrimsonHEART](https://forum.kirupa.com/u/CrimsonHEART)\
**Post date:** [July 21, 2008, 3:01pm UTC](https://forum.kirupa.com/t/collisions-ball-vs-a-wall/266493/1 "2008-07-21T15:01:20Z")

</div>

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:

```auto

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:

```auto

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:

```auto
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.
