Advertisement
epitaque_

Untitled

Oct 17th, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // keybind_register.js
  2. "use strict";
  3.  
  4. function WrapFunction(name)
  5. {
  6.     return function() { Game[name](); };
  7. }
  8.  
  9. Game.AddCommand("+KeyPressUp", WrapFunction("OnPressUp"), "", 0);
  10. Game.AddCommand("+KeyPressLeft", WrapFunction("OnPressLeft"), "", 0);
  11. Game.AddCommand("+KeyPressDown", WrapFunction("OnPressDown"), "", 0);
  12. Game.AddCommand("+KeyPressRight", WrapFunction("OnPressRight"), "", 0);
  13.  
  14. Game.AddCommand("-KeyPressUp", WrapFunction("OnReleaseUp"), "", 0);
  15. Game.AddCommand("-KeyPressLeft", WrapFunction("OnReleaseLeft"), "", 0);
  16. Game.AddCommand("-KeyPressDown", WrapFunction("OnReleaseDown"), "", 0);
  17. Game.AddCommand("-KeyPressRight", WrapFunction("OnReleaseRight"), "", 0);
  18.  
  19. (function()
  20. {
  21.     $.Msg("controls/keybind_register.js loaded.");
  22. })();
  23.  
  24. // keys.js
  25. "use strict";
  26.  
  27. var ISPRESSED_UP, ISPRESSED_DOWN, ISPRESSED_RIGHT, ISPRESSED_LEFT = false;
  28. var localHeroIndex;
  29. var stopped;
  30. var keyHasChanged = true;
  31.  
  32. // Pressing keys
  33. Game.OnPressUp = function() {
  34.     keyHasChanged = true;
  35.     ISPRESSED_UP = true;
  36. }
  37. Game.OnPressDown = function() {
  38.     keyHasChanged = true;
  39.     ISPRESSED_DOWN = true;
  40. }
  41. Game.OnPressRight = function() {
  42.     keyHasChanged = true;
  43.     ISPRESSED_RIGHT = true;
  44. }
  45. Game.OnPressLeft = function() {
  46.     keyHasChanged = true;
  47.     ISPRESSED_LEFT = true;
  48. }
  49.  
  50. // Releasing keys
  51. Game.OnReleaseUp = function() {
  52.     keyHasChanged = true;
  53.     ISPRESSED_UP = false;
  54. }
  55. Game.OnReleaseDown = function() {
  56.     keyHasChanged = true;
  57.     ISPRESSED_DOWN = false;
  58. }
  59. Game.OnReleaseRight = function() {
  60.     keyHasChanged = true;
  61.     ISPRESSED_RIGHT = false;
  62. }
  63. Game.OnReleaseLeft = function() {
  64.     keyHasChanged = true;
  65.     ISPRESSED_LEFT = false;
  66. }
  67.  
  68. function Move()
  69. {
  70.     if(keyHasChanged == true)
  71.     {
  72.         GameEvents.SendCustomGameEventToServer("Player_ChangeKeys", {
  73.             "right" : ISPRESSED_RIGHT,
  74.             "left" : ISPRESSED_LEFT,
  75.             "up" : ISPRESSED_UP,
  76.             "down" : ISPRESSED_DOWN });
  77.         keyHasChanged = false;
  78.     }
  79.  
  80.     $.Schedule(1/30, Move);
  81. }
  82.  
  83. (function()
  84. {
  85.     $.Msg("controls/keys.js loaded.");
  86.     $.Schedule(1/30, Move);
  87. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement