Вход

Просмотр полной версии : Не двигаются блоки, jquery


TBIKC
21.12.2011, 21:22
В чём ошибка ? Не двигаются блоки :-?
Помогите пожалуйста:yes:
var pingpong = {}
pingpong.pressedKeys = [];

$(function(){
pingpong.timer = setInterval(gameloop,30);

$(document).keydown(function(e){
pingpong.pressedKeys[e.which] = true;
)};

$(document).keyup(function(e){
pingpong.pressedKeys[e.which] = false;
)};
});

function gameloop(){
movePaddles();
}
function movePaddles(){
if(pingpong.pressedKeys[KEY.UP]){
var top = parseInt($("#paddleB").css("top"));
$("#paddleB").css("top",top-5);
}
if(pingpong.pressedKeys[KEY.DOWN]){
var top = parseInt($("#paddleB").css("top"));
$("#paddleB").css("top",top+5);
}
if(pingpong.pressedKeys[KEY.W]){
var top = parseInt($("#paddleA").css("top"));
$("#paddleA").css("top",top-5);
}
if(pingpong.pressedKeys[KEY.S]){
var top = parseInt($("#paddleA").css("top"));
$("#paddleA").css("top",top+5);
}
}


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ping pong</title>
<script src="jquery-1.4.4.min.js"></script>
<script src="pingpong.js"></script>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<header>
<h1>Ping Pong</h1>
</header>
<footer>
<script>

</script>
This is an example of creating a Ping Pong Game!<br><br>
<div id="game">
<div id="playground">
<div id="paddleA" class="paddle"></div>
<div id="paddleB" class="paddle"></div>
<div id="ball"></div>
</div>
</div>
</footer>
</body>
</html>

ksa
21.12.2011, 21:53
В чём ошибка ?
Например ты нигде не пишешь единицы измерения...
И пример твой как запустить? Что это за Лего ты выложил?
Что должно быть в итоге-то? :)

TBIKC
21.12.2011, 22:20
Написал всё до этого момента и вот следующий 6 шаг - запустить )
6. Let's test what we just coded. Save all the files and open index.html in the
web browser.
7. Try pressing the keys to control both paddles. The two paddles should move
smoothly and respond at the same time without interruption.
What just happened?
We have used another approach to capture the keyboard input. Instead of doing the action
once after the key press is detected, we store which keys are pressed and which are not.
Afterwards, we use a JavaScript interval to check the pressed keys every 30 milliseconds.
This approach enables us to know all the keys pressed at the time and so we can move both
paddles at the same time.
http://habrastorage.org/storage2/92b/2d1/b03/92b2d1b03951e9963eb031f11347a741.png

TBIKC
22.12.2011, 10:52
Ну так что ?

ksa
22.12.2011, 11:33
Ну так что ?
Забесплатно желание не появилось... :no:

TBIKC
22.12.2011, 11:45
эх, как же так то везде сплошная коррупция ( :-?

ksa
22.12.2011, 13:25
везде сплошная коррупция
В данном вопросе нет никапельки коррупционной сотавляющей. Исключительно оплата труда.

TBIKC
22.12.2011, 18:56
Всё исправил (firebug ура)