+function Controls(hero){
+ // processes keyboard / touch / mouse
+ // causes according player actions
+ // single player only, conrol will be assigned to server in multi player
+ var kbdmap = {
+ up: 87, altup: 38,
+ down: 83, altdown: 40,
+ left: 65, altleft: 37,
+ right: 68, altright: 39,
+ }
+ var keys = [], click = [];
+
+ loadevents();
+
+ window.addEventListener("keydown", e => keys[e.keyCode] = true );
+ window.addEventListener("keyup" , e => keys[e.keyCode] = false);
+ window.addEventListener("click", m => click = [ map.mapX(m.clientX), map.mapY(m.clientY) ] );
+ setInterval(() => input(), 33.33)
+
+ // cause player to walk, processes blocked terrain and player speed
+ // x/y are factors of speed and direction
+ // i.e. +/-1 for diagonal movement
+ // and +/-1.4 for horizontal/vertical movement
+ function translate(x, y){
+ var sx = map.info.header.tilewidth * hero.stats.speed / 33.33;
+ var sy = map.info.header.tileheight * hero.stats.speed / 33.33;
+ var dx = x * sx, hx = hero.position[0];
+ var dy = y * sy, hy = hero.position[1];
+ var f = 2.1;
+ const col = map.info.layer.find(l => l.type == "collision").data;
+
+ if (col[map.tileAt(hx + dx, hy + dy)] == 0 )
+ hero.place(hx + dx, hy + dy);
+ else if ( dy == 0 && col[map.tileAt(hx + dx / f, hy + sy / 1.5)] == 0 )
+ hero.place(hx + dx / f, hy + sy / 1.5);
+ else if ( dy == 0 && col[map.tileAt(hx + dx / f, hy - sy / 1.5)] == 0 )
+ hero.place(hx + dx / f, hy - sy / 1.5);
+ else if ( dx == 0 && col[map.tileAt(hx + sx / 1.5, hy + dy / f)] == 0 )
+ hero.place(hx + sx / 1.5, hy + dy / f);
+ else if ( dx == 0 && col[map.tileAt(hx - sx / 1.5, hy + dy / f)] == 0 )
+ hero.place(hx - sx / 1.5, hy + dy / f);
+ else player.stance();