home *** CD-ROM | disk | FTP | other *** search
-
- /*
- ALL CODE WRITTEN BY HAND BY: ANDRE KING
- DATE: 5/8/2000
-
- PLEASE, FEEL FREE TO USE ANY CODE HEREIN,
- BUT I WOULD APPRECIATE AN EMAIL TO
- andrewtek@excite.com
- LETTING ME KNOW JUST HOW MUCH OF MY CODE IS OUT THERE
-
- */
-
- /*what browser is this? */
- var usingNetscape = navigator.appName=="Netscape";
-
- if(usingNetscape){
- document.captureEvents(Event.MOUSEMOVE);
- document.onMouseMove = mouseTrackerNN;
- }else{
- document.onmousemove = mouseTrackerIE;
- }
-
- //if (document.all&&window.print)
- // document.body.style.cssText="overflow-x:hidden;overflow-y:scroll"
-
- //this holds all the sprites in it
- var spriteVector = new Array()
-
- var twoPI = Math.PI * 2
- var mouseX = 0, mouseY = 0;
-
- //same as the start() and run() methods of JAVA (Oh, what a language)
- function startAnimation(){
- setInterval('moveSprites()', 30);
- }
-
- function addSprite(name, width, height, maxVel, minVel){
- var spriteName = new String(name)
- if(spriteName.indexOf(".") != -1)
- alert("Sprite's Name Should Not Contain File Extension: " + name)
- else{
- xStart = Number(150)
- yStart = Number(150)
- // alert(xStart + ", " + yStart)
- // document.writeln("<div id=\"directional" + name + "\" style=\"position: absolute;\"><img src=\"images/direction.gif\"></div>")
- // document.writeln("<div id=\"" + name + "\" style=\"position: absolute;\"><img name=\"" + name + "img\" src=\"images/"+name+".gif\" width=" + width+" height=" + height+"\"></div>")
- spriteVector[spriteVector.length] = new sprite(name, width, height, xStart, yStart, maxVel, minVel)
- }
- }
-
- /*A Sprite Object*/
- function sprite(name, width, height, xPos, yPos, maxVel, minVel){
- this.name = name; //name referring to div/layer tag
- this.width = width; //width of image
- this.height = height; //height of image
- this.xPos = xPos; //current x Position
- this.yPos = yPos; //current y Position
- this.xOld = xPos; //previous x Position
- this.yOld = yPos; //previous y Position
- this.maxVel = maxVel; //maximum speed of this sprite
- this.minVel = minVel; //minimum speed of this sprite
- this.actualVelocity = minVel; //current speed of this sprite
- if(usingNetscape){
- this.domObj = eval("document.sprite" + spriteVector.length)
- this.directional = eval("document.directional"+spriteVector.length)
- }else{
- this.domObj = eval("sprite" + spriteVector.length +".style")
- this.directional = eval("directional"+ spriteVector.length +".style")
- }
- this.currAngle = 0
- }
-
- /*Mouse Tracking Functions... used to find the exact position of the mouse.*/
- function mouseTrackerIE(){
- // mouseX = 150;
- // mouseY = 150;
- mouseX = window.event.x + document.body.scrollLeft;
- mouseY = window.event.y + document.body.scrollTop;
- }
- function mouseTrackerNN(mouse){
- // mouseX = 150;
- // mouseY = 150;
- mouseX = mouse.x;
- mouseY = mouse.y;
- }
-
- //sprite movement functiuons
- function moveSprites(){
- //code for moving sprites
- var curSpr
- for(var i = 0; i < spriteVector.length; i++){
- curSpr = spriteVector[i] //easier to type than sprite[i]
- //check if the sprite is within range
- if(getDistance(curSpr.xPos, curSpr.yPos, mouseX, mouseY) > 25){
- moveSpriteToMouse(curSpr)
- }else{
- moveSpriteInCircles(curSpr)
- }
- makeSpriteMovement(curSpr)
- }
- }function moveSpriteToMouse(curSpr){
- curSpr.xOld = curSpr.xPos;
- curSpr.yOld = curSpr.yPos;
- actualAngle = getAngle(curSpr.xPos, curSpr.yPos, mouseX, mouseY)
- var diffToZero = curSpr.currAngle
- var actualAngleMoved = actualAngle - diffToZero
- //code determins which direction to go towards mouse
- if(actualAngleMoved < -Math.PI)
- actualAngleMoved += twoPI
- else if(actualAngleMoved > Math.PI)
- actualAngleMoved -= twoPI
- if(Math.abs(actualAngleMoved) > (curSpr.minVel/50) * 2){
- if(actualAngleMoved < 0){
- curSpr.currAngle -= curSpr.minVel/50
- if (curSpr.currAngle < -Math.PI)curSpr.currAngle+=twoPI
- }
- else{
- curSpr.currAngle += curSpr.minVel/50
- if (curSpr.currAngle > Math.PI)curSpr.currAngle-=twoPI
- }
- }
- }function moveSpriteInCircles(curSpr){
- curSpr.currAngle += curSpr.minVel/50
- }function makeSpriteMovement(curSpr){//move sprites based on internally changed values
- newXY = movePointOnVector(curSpr.minVel, curSpr.currAngle, curSpr.xPos, curSpr.yPos)
- curSpr.xPos = newXY[0];
- curSpr.yPos = newXY[1];
- directionalXY = movePointOnVector(curSpr.width * .75, curSpr.currAngle, newXY[0], newXY[1])
- curSpr.domObj.left = curSpr.xPos - (curSpr.width / 2);
- curSpr.domObj.top = curSpr.yPos - (curSpr.height /2);
- curSpr.directional.left = directionalXY[0] - (7.5);
- curSpr.directional.top = directionalXY[1] - (7.5);
- }
- /*X, Y Manipulation Functions*/
- function getAngle(startX, startY, endX, endY){
- var x = startX - endX; //difference between x's (abs is not necessary since values will be squared)
- var y = startY - endY; //difference between y's (abs is not necessary since values will be squared)
- var newAngle = -Math.atan2(x, y)+Math.PI;
- return -newAngle;
- }//distance between two points
- function getDistance(startX, startY, endX, endY){
- xDist = startX - endX;
- yDist = startY - endY;
- return Math.sqrt((xDist * xDist) + (yDist * yDist))
- }//moves a point in a particular direction keeping actual velocity
- function movePointOnVector(velocity, angle, currX, currY){
- var cos = Math.cos(angle);
- var sin = Math.sin(angle);
- return returnVars = new Array(currX + velocity * sin, currY + velocity * cos);
- }
- //adds disclaimer to window
- function startDisclaimer(disclaimerText){
- setTimeout("disclaimerMoveUp(0)", 5000)
- }
- function disclaimerMoveUp(factor){
- var fctr = factor
- fctr -= 1.75
- if(usingNetscape)
- document.disclaimer.top = (15 + fctr)
- else
- disclaimer.style.top = (15 + fctr)
- if(fctr > -100)
- setTimeout("disclaimerMoveUp(" + fctr + ")", 20)
- }
-
-
- //add sprites and disclaimer
-
- startDisclaimer()