html - Moving Divs in JavaScript with key presses -


i'm doing html/javascript based game, game objective 2 monsters collecting cakes , avoid other thing cakes. i've created 2 divs each 1 zone want characters move around. first i'm starting basic (space key jump), 1 of games if 1 character goes up, other 1 comes down. now, i'm testing code 1 character see if works, if i'm planning program other character opposite. code got key presses:

function onkeypressed(event) {     if(event.keycode == 37) {         left = true;     }     if(event.keycode == 39) {         right = true;     }     if(event.keycode == 38) {         = true;     }     if(event.keycode == 40) {         down = true;     }     if(event.keycode == 32) {     updatemonster1place();     updatemonster2place();     } }  // function called when key, in keyboard, released function onkeyreleased(event) {     if(event.keycode == 37) {         left = false;     }     if(event.keycode == 39) {         right = false;     }     if(event.keycode == 38) {         = false;     }     if(event.keycode == 40) {         down = false;     } } 

and first function called updatemonster1place();

function updatemonster1place() {      if (monster1.top >= 500){     for( var i=0; = 100; i++){     monster1.top = + "px";         }     } } 

i think code wrong, because, character placed @ top = 500px, , want happen, character slide, , stops when top = 100.

i hope understand im trying here. in advance!


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -