jerry2810

Cryptext

Dec 20th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var COLD = COLD || {};
  2.  
  3. (function(){
  4.     COLD.PUZZLE = {
  5.        
  6.         Puzzle_Window : function(){this.initialize.apply(this, arguments);},
  7.        
  8.         Puzzle_Scene    : function(){this.initialize.apply(this, arguments);},
  9.  
  10.     };
  11.  
  12. })();
  13.  
  14. (function($){
  15.    
  16. ($.prototype = Object.create(Window_Selectable.prototype)).constructor = $;
  17.  
  18.     $.prototype.initialize = function(reorderedKey) {
  19.         this._currentOrder = reorderedKey;
  20.         this._maxItems = this._currentOrder.length;
  21.         var width = this.windowWidth();
  22.         var height = this.windowHeight();
  23.         this.windowX = (Graphics.width - width)/2;
  24.         this.windowY = (Graphics.height - 2 * height);
  25.         Window_Selectable.prototype.initialize.call(this, this.windowX, this.windowY, width, height);
  26.         this._pendingIndex = -1;
  27.         this.select(0);
  28.         this.refresh();
  29.         this._refreshArrows();
  30.     };
  31.    
  32.     $.prototype._possibleKeys = [
  33.         'A','B','C','D','E',
  34.         'F','G','H','I','J',
  35.         'K','L','M','N','O',
  36.         'P','Q','R','S','T',
  37.         'U','V','W','X','Y',
  38.         'Z','0','1','2','3',
  39.         '4','5','6','7','8','9','-',
  40.     ];
  41.  
  42.     $.prototype.windowWidth = function(){
  43.         return this.itemWidth()*this._maxItems+(this._maxItems+1)*this.spacing();
  44.     };
  45.  
  46.     $.prototype.windowHeight = function(){
  47.         return this.itemHeight()+this.spacing()*2;
  48.     };
  49.    
  50.     $.prototype.maxItems = function(){
  51.         return this._maxItems;
  52.     };
  53.    
  54.     $.prototype.itemHeight = function() {
  55.         return this.lineHeight();
  56.     };
  57.  
  58.     $.prototype.itemWidth = function() {
  59.         return 48;
  60.     };
  61.  
  62.     $.prototype.numVisibleRows = function() {
  63.         return 1;
  64.     };
  65.  
  66.     $.prototype.spacing = function() {
  67.         return this.standardPadding();
  68.     };
  69.  
  70.     $.prototype.maxCols = function() {
  71.         return this.maxItems();
  72.     };
  73.  
  74.     $.prototype.selectLast = function() {
  75.         this.select(0);
  76.     };
  77.    
  78.     $.prototype.drawItem = function(index){
  79.         this.drawKeys(index);
  80.     };
  81.    
  82.     $.prototype.drawKeys = function(index) {
  83.         var rect = this.itemRect(index);
  84.         this.drawText(this._currentOrder[index],rect.x,rect.y,rect.width,'center');
  85.     };
  86.    
  87.     $.prototype.cursorDown = function() {
  88.         var currentIndex = this._possibleKeys.indexOf(this._currentOrder[this.index()]);
  89.         if(currentIndex >= 1){
  90.             this._currentOrder[this.index()] = this._possibleKeys[currentIndex -1];
  91.         }else{
  92.             this._currentOrder[this.index()] = this._possibleKeys[this._possibleKeys.length-1]
  93.         };
  94.         SoundManager.playCursor();
  95.         this.redrawItem(this.index());
  96.     };
  97.  
  98.     $.prototype.cursorUp = function() {
  99.         var currentIndex = this._possibleKeys.indexOf(this._currentOrder[this.index()]);
  100.         if(currentIndex < (this._possibleKeys.length-1)){
  101.             this._currentOrder[this.index()] = this._possibleKeys[currentIndex + 1];
  102.         }else{
  103.             this._currentOrder[this.index()] = this._possibleKeys[0];      
  104.         };
  105.         SoundManager.playCursor();
  106.         this.redrawItem(this.index());
  107.     };
  108.    
  109.     $.prototype.processOk = function() {
  110.         this.updateInputData();
  111.         this.callOkHandler();
  112.     };
  113.    
  114.     $.prototype.updateArrows = function() {
  115.         this.downArrowVisible = true;
  116.         this.upArrowVisible = true;
  117.     };
  118.    
  119.     $.prototype.processCursorMove = function() {
  120.         if (this.isCursorMovable()) {
  121.             var lastIndex = this.index();
  122.             if (Input.isRepeated('right')) {
  123.                 this.cursorRight(Input.isTriggered('right'));
  124.                 this._refreshArrows();
  125.             }
  126.             if (Input.isRepeated('left')) {
  127.                 this.cursorLeft(Input.isTriggered('left'));
  128.                 this._refreshArrows();
  129.             }
  130.             if (this.index() !== lastIndex) {
  131.                 SoundManager.playCursor();
  132.             }
  133.         }
  134.        
  135.         if (Input.isTriggered('down')) {
  136.             this.cursorDown();
  137.         }
  138.         if (Input.isTriggered('up')) {
  139.             this.cursorUp();  
  140.         }    
  141.     };
  142.  
  143.  
  144.     $.prototype._refreshArrows = function() {
  145.         var w = this._width;
  146.         var h = this._height;
  147.         var p = 24;
  148.         var q = p/2;
  149.         var sx = 96+p;
  150.         var sy = 0+p;
  151.         var x = this.spacing()+ this.itemWidth()/2+(this.spacing()+this.itemWidth())*this.index();
  152.         this._downArrowSprite.bitmap = this._windowskin;
  153.         this._downArrowSprite.anchor.x = 0.5;
  154.         this._downArrowSprite.anchor.y = 0.5;
  155.         this._downArrowSprite.setFrame(sx+q, sy+q+p, p, q);
  156.         this._downArrowSprite.move(x, h-q);
  157.         this._upArrowSprite.bitmap = this._windowskin;
  158.         this._upArrowSprite.anchor.x = 0.5;
  159.         this._upArrowSprite.anchor.y = 0.5;
  160.         this._upArrowSprite.setFrame(sx+q, sy, p, q);
  161.         this._upArrowSprite.move(x, q);
  162.     };
  163.  
  164. })(COLD.PUZZLE.Puzzle_Window);
  165.  
  166. (function($){
  167.  
  168.     ($.prototype = Object.create(Scene_MenuBase.prototype)).constructor = $;
  169.  
  170.     $.prototype.initialize = function() {
  171.         Scene_MenuBase.prototype.initialize.call(this);
  172.     };
  173.    
  174.     $.prototype.create = function() {
  175.         Scene_MenuBase.prototype.create.call(this);
  176.         this.createTitle();
  177.         this.createWindows();
  178.     };
  179.    
  180.     $.prototype.prepare = function(key,variable){
  181.         this._puzzleKey = key;
  182.         this._reorderedKey = this.reorderKey(this._puzzleKey.length);
  183.         this._variable = variable;
  184.     };
  185.    
  186.     $.prototype.reorderKey = function(length){
  187.         var key = new Array(length);
  188.         for(var i =0; i < length; i++){
  189.             key[i]='-';
  190.         }
  191.         return key;
  192.     };
  193.    
  194.     $.prototype.createTitle = function(){
  195.         this._titleSprite = new Sprite();
  196.         this.addChild(this._titleSprite);
  197.         this._titleSprite.bitmap = new Bitmap(Graphics.width, Graphics.height);
  198.     };
  199.    
  200.     $.prototype.createWindows = function(){
  201.         this.createPuzzleWindow();
  202.     };
  203.    
  204.     $.prototype.update = function(){
  205.         Scene_MenuBase.prototype.update.call(this);
  206.         this.drawTitle();
  207.     };
  208.    
  209.     $.prototype.drawTitle = function(){
  210.         var bitmap = this._titleSprite.bitmap;
  211.         var x = this._puzzleWindow.windowX;
  212.         var y = this._puzzleWindow.windowY;
  213.         var width = this._puzzleWindow.windowWidth();
  214.         var height = Window_Base.prototype.lineHeight();
  215.         bitmap.clear();
  216.         bitmap.drawText('Please enter the code...', x, y - height, width, height, 'center');
  217.     };
  218.    
  219.     $.prototype.createPuzzleWindow = function() {
  220.         this._puzzleWindow = new COLD.PUZZLE.Puzzle_Window(this._reorderedKey);
  221.         this._puzzleWindow.setHandler('ok',     this.onSelectionOk.bind(this));
  222.         this._puzzleWindow.setHandler('cancel', this.popScene.bind(this));
  223.         this.addWindow(this._puzzleWindow);
  224.         this._puzzleWindow.activate();
  225.     };
  226.    
  227.     $.prototype.onSelectionOk = function(){
  228.         if(this.checkForSolved()){
  229.             SoundManager.playRecovery();
  230.             $gameVariables[this._variable] = true;
  231.             this.popScene();
  232.         }else{
  233.             SoundManager.playBuzzer();
  234.         }
  235.         this._puzzleWindow.activate();
  236.     };
  237.    
  238.     $.prototype.checkForSolved = function(){
  239.         for(var i = 0; i < this._puzzleKey.length;i++) {
  240.             if(this._puzzleWindow._currentOrder[i] !== this._puzzleKey[i]){
  241.                 return false;
  242.             };
  243.         };
  244.         return true;
  245.     };
  246.    
  247. })(COLD.PUZZLE.Puzzle_Scene);
Advertisement
Add Comment
Please, Sign In to add comment