Почему-то в игрушке управление "отрожателями" работает туго. Вот:
zaripov.nxt.ru/test/index.html.
В начале сдвигается, думает с полсекунды, и снова идет.
Код:
speed=4; // px/10ms
dead=0;
plSpeed=15;
time=2;
radius=5;
i=1;
function start () {
dead=document.getElementById('dead');
dead.number=0;
bool=document.getElementById('bool');
bool.left=500;
bool.top=200;
bool.destination=true;
bool.alpha=-0.3;
bool.move=function (x,y) {
bool.left+=x;
bool.top+=-y;
bool.style.left=Math.round(bool.left)+'px';
bool.style.top=Math.round(bool.top)+'px';
}
pl1=document.getElementById('pl1');
pl1.top=0;
pl1.height=100;
pl1.speed=30;
// думаю что тут-то и загвоздка ;-)
pl1.move=function (destination) {
window.status=i;
pl1.top+=destination*plSpeed;
pl1.style.top=Math.round(pl1.top)+'px';
}
pl2=document.getElementById('pl2');
pl2.top=0;
pl2.height=100;
pl2.speed=30;
pl2.move=function (destination) {
window.status=i;
pl2.top+=destination*plSpeed;
pl2.style.top=Math.round(pl2.top)+'px';
}
play_status=false;
playPause();
documentWidht=1366;
documentHeight=580;
window.addEventListener('keydown', pressKey, false);
}
function pressKey(event) {
if (!event) event=window.event;
if (event.keyCode==40) pl2.move(1);
if (event.keyCode==38) pl2.move(-1);
if (event.keyCode==83) pl1.move(1);
if (event.keyCode==87) pl1.move(-1);
if (event.keyCode==80) playPause();
}
function game() {
if (bool.top<=0 | bool.top>=documentHeight) {
bool.alpha=-bool.alpha;
}
if (bool.destination) {
if ((bool.left+radius)>=(documentWidht-10))
if ((bool.top>=pl2.top) & (bool.top<=(pl2.top+100))) {
bool.destination=!bool.destination;
bool.alpha=3.14-bool.alpha;
}
else {
Dead();
playPause();
}
bool.move(speed*Math.cos(bool.alpha),-speed*Math.sin(bool.alpha));
}
else {
if ((bool.left+radius)<=10)
if ((bool.top>=pl1.top) & (bool.top<=(pl1.top+100))) {
bool.destination=!bool.destination;
bool.alpha=3.14-bool.alpha;
}
else {
Dead();
playPause();
}
bool.move(speed*Math.cos(bool.alpha),-speed*Math.sin(bool.alpha));
}
}
function playPause () {
if (!play_status) {
game_go=setInterval (game, 1);
document.getElementById('play').style.background='url(./images/pause.png)';
play_status=true;
} else {
clearInterval(game_go);
document.getElementById('play').style.background='url(./images/play.png)';
play_status=false;
}
}
function Dead() {
dead.number++;
dead.value=dead.number;
bool.destination=true;
bool.left=documentWidht/2;
bool.top=documentHeight/2;
bool.move(0,0);
bool.alpha=0;
}