// Sections from the rebound.js file
function init() {
//instantiate HTML object instance vars
ball = document.getElementById('idball');
paddle = document.getElementById('idpaddle');
score = document.getElementById('score');
hiScore = document.getElementById('hiScore');
gameTime = document.getElementById('gameTime');
//resister key listener with document object
document.onkeydown = keyListener;
//function keyListener(e) {
// if (!e) {
// //for IE
// e = window.event;
// }
// if (e.keyCode == 37 && paddleLeft > 10) {
// //keycode 37 is left arrow
// paddleLeft -= 10;
// paddle.style.left = paddleLeft + 'px';
// }
// if (e.keyCode == 39 && paddleLeft < 425) {
// //keycode 39 is right arrow
// paddleLeft += 10;
// paddle.style.left = paddleLeft + "px";
// }
//}
function detectCollisions() {
//just reflect the ball on a collision
//a more robust engine could change trajectory of
//the ball based on where the ball hits the paddle
if (collisionX())
dx = dx * -1;
if (collisionY())
dy = dy * -1;
}
function collisionX() {
//check left and right boundaries
if (ballLeft < 4 || ballLeft > 480)
return true;
return false;
}
function collisionY() {
//check if at top of playing area
if(ballTop < 4)
return true;
//check to see if ball collided with paddle
if(ballTop >450) {
if(ballLeft > paddleLeft - 10 && ballLeft < paddleLeft + 64)
return true;
}
return false;
}
var divName = 'mypaddle'; // div that is to follow the mouse
// (must be position:absolute)
var offX = -45; // X offset from mouse position
var offY = 0; // Y offset from mouse position
function mouseX(evt) {
if (!evt) evt = window.event;
if (evt.pageX) return evt.pageX;
else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
//function mouseY(evt) {
//if (!evt) evt = window.event;
//if (evt.pageY) return evt.pageY;
//else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
//else return 0;}
function follow(evt) {if (document.getElementById) {var obj = document.getElementById(divName).style; obj.visibility = 'visible';
obj.left = (parseInt(mouseX(evt))+offX) + 'px';
obj.top = (parseInt(mouseY(evt))+offY) + 'px';}}
document.onmousemove = follow;
**************************************************
//HTML Div Tag
*****************************************
//CSS Class
#mypaddle
{
position:absolute;
overflow:hidden;
visibility: hidden;
top: 470px;
width:64px;
height:16px;
|