JavaScript Breakout - Ball horizontal motion based on where it hits the paddle
<p>Question's pretty self explanatory. I trying to get the horizontal motion of my 15px by 15px cube to based on where it hits my 15px by 90px paddle for my breakout game I'm working on. The idea would be when it hits the middle the paddle from one direction, it'll just go diagonally up the opposite. Been stuck on it for a while now and try different ways, but nothing has worked. Any help will be very much appreciated. Thanks!!</p>

<p>Here's what I have so far:</p>

<pre><code>var left = parseInt(box.style.left);

var top = parseInt(box.style.top);

var paddleTop = parseInt(paddle.style.left) - parseInt(box.width);

var paddleBott = parseInt(paddle.style.left) + parseInt(paddle.width);

var deltaL = 3;

var deltaT = 7;

    if(left + deltaL &gt;= parseInt(view.width)){

        deltaL = -deltaL;

    } else if(left + deltaL &lt;= 0){

        deltaL = -deltaL;

    } else if(top + deltaT &gt;= parseInt(view.height)+8){

        deltaT = 0;
        deltaL = 0;

    } else if(top + deltaT &lt;= 0){

        deltaT = -deltaT;

    }

    if(top + deltaT &gt;= ((parseInt(view.height-19)) - parseInt(paddle.height))){

        if((left &gt;= paddleTop) &amp;&amp; (left &lt;= paddleBott)){    

            deltaL = -deltaL;

            deltaT = -deltaT;


        } 

    }


    box.style.left = left + deltaL + 'px';
    box.style.top = top + deltaT + 'px';
</code></pre>
