1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| /* zelda 2*/
var can, ctx, timer, posX=-1935, posY=-1170, vX=0, vY=0,
hauteur =400,
largeur = 600,
img = new Image(),
zoomX=5000,
zoomY=5000;
function initGraph() {
document.body.innerHTML += "<canvas id='can1' width='" + largeur + "' height='" + hauteur + "'></canvas>"
can=document.getElementById('can1');
ctx=can.getContext('2d');
}
function scroll_on(e) {
if (e.keyCode=='37') {vX -= 15;}
if (e.keyCode=='38') {vY = 15;}
if (e.keyCode=='39') {vX = 15;}
if (e.keyCode=='40') {vY -= 15;}
}
function scroll_off(e) {
if (e.keyCode=='37') {vX = 0;}
if (e.keyCode=='38') {vY -= 0;}
if (e.keyCode=='39') {vX -= 0;}
if (e.keyCode=='40') {vY = 0;}
}
function moveIt() {
if (((posX - vX)>(-zoomX+largeur/2))&((posX - vX)<(largeur/2))) { posX -= vX;}
if (((posY + vY)>(-zoomY+hauteur/2))&((posY + vY)<(hauteur/2))) { posY += vY;}
ctx.clearRect(0,0,largeur,hauteur);
ctx.drawImage(img,posX,posY,zoomX,zoomY);
ctx.strokeRect(largeur/2-5,hauteur/2-5,30,30);
}
function go(){
initGraph();
img.src = "http://danielhagnoul.developpez.com/images/imageTest.png";
img.onload = function(){
document.addEventListener("keydown", scroll_on);
document.addEventListener("keyup", scroll_off);
timer = setInterval( moveIt, 20 );
};
} |
Partager