Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const Controller = function() {
  2.  
  3. this.left = new Controller.ButtonInput();
  4. this.right = new Controller.ButtonInput();
  5. this.up = new Controller.ButtonInput();
  6.  
  7. this.keyDownUp = function(type, key_code) {
  8.  
  9. var down = (type == "keydown") ? true : false;
  10.  
  11. switch(key_code) {
  12.  
  13. case 37: this.left.getInput(down); break;
  14. case 38: this.up.getInput(down); break;
  15. case 39: this.right.getInput(down);
  16.  
  17. }
  18.  
  19. };
  20.  
  21. };
  22.  
  23. Controller.prototype = {
  24.  
  25. constructor : Controller
  26.  
  27. };
  28.  
  29. Controller.ButtonInput = function() {
  30.  
  31. this.active = this.down = false;
  32.  
  33. };
  34.  
  35. Controller.ButtonInput.prototype = {
  36.  
  37. constructor : Controller.ButtonInput,
  38.  
  39. getInput : function(down) {
  40.  
  41. if (this.down != down) this.active = down;
  42. this.down = down;
  43.  
  44. }
  45.  
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement