<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <script type="text/javascript"> $(document).ready(function() { $(".health div").animate({ width: 25 }, 1000); var last_walk = 0; $("html").keydown(function(e) { if (new Date().getTime() - last_walk < 300) {//predkosc return true; } var char = $("#bum").position(); if (e.keyCode == 37) { setTimeout(function() { $("#character").css({ backgroundPosition: "-70px 0px", left: char.left - 3 }); }, 100);//szybkosc setTimeout(function() { $("#character").css({ backgroundPosition: "-35px 0px", left: char.left - 6 }); }, 200);//szybkosc setTimeout(function() { $("#character").css({ backgroundPosition: "0px 0px", left: char.left - 9 }); }, 300);//szybkosc } else if (e.keyCode == 38) { setTimeout(function() { $("#character").css({ backgroundPosition: "-70px -35px", top: char.top - 3 }); }, 100); setTimeout(function() { $("#character").css({ backgroundPosition: "-35px -35px", top: char.top - 6 }); }, 200); setTimeout(function() { $("#character").css({ backgroundPosition: "0px -35px", top: char.top - 9 }); }, 300); } else if (e.keyCode == 39) { setTimeout(function() { $("#character").css({ backgroundPosition: "-70px -70px", left: char.left + 3 }); }, 100); setTimeout(function() { $("#character").css({ backgroundPosition: "-35px -70px", left: char.left + 6 }); }, 200); setTimeout(function() { $("#character").css({ backgroundPosition: "0px -70px", left: char.left + 9 }); }, 300); } else if (e.keyCode == 40) { setTimeout(function() { $("#character").css({ backgroundPosition: "-70px -105px", top: char.top + 3 }); }, 100); setTimeout(function() { $("#character").css({ backgroundPosition: "-35px -105px", top: char.top + 6 }); }, 200); setTimeout(function() { $("#character").css({ backgroundPosition: "0px -105px", top: char.top + 9 }); }, 300); } last_walk = new Date().getTime(); }); }); </script> <style type="text/css"> #bum{ background: #FFF url(bg.jpg); width: 800px; height: 800px; left: 0px; top: 0px; } #gra{ background: #000; width: 300px; height: 300px; color: #000; font: normal 11px Verdana, sans-serif; } #character { background: transparent url(assassin.png) no-repeat; height: 35px; left: 150px; top: 150px; position: absolute; width: 35px; } #character .health { background-color: #060; border: 1px solid #060; height: 2px; margin: -7px auto 0 auto; width: 25px; } #character .health div { background-color: #6F0; height: 2px; width: 1px; } </style> </head> <body> <div id="gra"> <div id="bum"> <div id="character"> </div> </div> </div> </body> </html>
pomocy