- this.block = function() { this.animate("block" ); return this; };
- this.cast = function() { this.animate("cast" ); return this; };
- this.die = function() { this.animate("die" ); return this; };
- this.hit = function() { this.animate("hit" ); return this; };
- this.run = function() { this.animate("run" ); return this; };
- this.shoot = function() { this.animate("shoot" ); return this; };
- this.stance = function() { this.animate("stance"); return this; };
- this.swing = function() { this.animate("swing" ); return this; };
+ this.block = () => this.animate("block" );
+ this.cast = () => this.animate("cast" );
+ this.die = () => this.animate("die" );
+ this.hit = () => this.animate("hit" );
+ this.run = () => this.animate("run" );
+ this.shoot = () => this.animate("shoot" );
+ this.stance = () => this.animate("stance");
+ this.swing = () => this.animate("swing" );
+}
+
+function Controls(hero, map){
+ var keys = [];
+
+ function input(){
+ var d = {};
+ d.l = keys[65] || keys[37]; d.r = keys[68] || keys[39];
+ d.u = keys[87] || keys[38]; d.d = keys[83] || keys[40];
+ if ( d.l ) hero.direct(0).run(); if ( d.r ) hero.direct(4).run();
+ if ( d.u ) hero.direct(2).run(); if ( d.d ) hero.direct(6).run();
+ if ( d.u && d.l ) hero.direct(1).run();
+ if ( d.u && d.r ) hero.direct(3).run();
+ if ( d.d && d.l ) hero.direct(7).run();
+ if ( d.d && d.r ) hero.direct(5).run();
+ if ( ! (d.l || d.r || d.u || d.d) ) hero.stance();
+ }
+ window.addEventListener("keydown", function(e){ keys[e.keyCode] = true ; input();} );
+ window.addEventListener("keyup" , function(e){ keys[e.keyCode] = false; input();} );