//chodec.js// Chodec = function(herniPlocha){ /* Pocatecni pozice */ this.x=200; this.y=200; this.rychlost=0; this.uhel=0; this.mujElement = document.createElement('div'); this.mujElement.className="chodec"; herniPlocha.appendChild(this.mujElement); } Chodec.prototype.vykresli = function(){ //Aktualizuj souradnice dle rychlosti var rychlostX = getXDiff (this.uhel, this.rychlost); var rychlostY = getYDiff (this.uhel, this.rychlost); this.x += rychlostX; this.y += rychlostY; //Zapis nove souradnice this.mujElement.style.top=this.y+"px"; this.mujElement.style.left=this.x+"px"; this.mujElement.style.transform="rotate("+this.uhel+"deg)"; } /* Pomocne funkce */ function getXDiff(angle,velocity){ var angleRad=((angle+90)/180)*Math.PI; return Math.cos(angleRad)*velocity; } function getYDiff(angle,velocity){ var angleRad=((angle+90)/180)*Math.PI; return Math.sin(angleRad)*velocity; } //index.html// Test