krouzek:class

Toto je starší verze dokumentu!


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;
}
  • krouzek/class.1574268692.txt.gz
  • Poslední úprava: 2023/11/15 20:54
  • (upraveno mimo DokuWiki)