personal garden & website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
528 B

const monster = document.getElementById('monster')
let x = window.innerWidth / 2
let y = window.innerHeight / 2
let dx = 2.5
let dy = 2.5
function init(){
monster.style.top = + "px"
monster.style.left = window.innerWidth / 2 + "px"
movement()
}
function movement(){
if( x > window.innerWidth - 100 || x <= 0 ){
dx *= -1;
}
if( y > (window.innerHeight - 100) || y <= 100 ){
dy *= -1;
}
x += dx
y += dy
monster.style.top = y + "px"
monster.style.left = x + "px"
requestAnimationFrame(movement)
}
init()