Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var COLD = COLD || {};
- (function(){
- COLD.PUZZLE = {
- Puzzle_Window : function(){this.initialize.apply(this, arguments);},
- Puzzle_Scene : function(){this.initialize.apply(this, arguments);},
- };
- })();
- (function($){
- ($.prototype = Object.create(Window_Selectable.prototype)).constructor = $;
- $.prototype.initialize = function(reorderedKey) {
- this._currentOrder = reorderedKey;
- this._maxItems = this._currentOrder.length;
- var width = this.windowWidth();
- var height = this.windowHeight();
- this.windowX = (Graphics.width - width)/2;
- this.windowY = (Graphics.height - 2 * height);
- Window_Selectable.prototype.initialize.call(this, this.windowX, this.windowY, width, height);
- this._pendingIndex = -1;
- this.select(0);
- this.refresh();
- this._refreshArrows();
- };
- $.prototype._possibleKeys = [
- 'A','B','C','D','E',
- 'F','G','H','I','J',
- 'K','L','M','N','O',
- 'P','Q','R','S','T',
- 'U','V','W','X','Y',
- 'Z','0','1','2','3',
- '4','5','6','7','8','9','-',
- ];
- $.prototype.windowWidth = function(){
- return this.itemWidth()*this._maxItems+(this._maxItems+1)*this.spacing();
- };
- $.prototype.windowHeight = function(){
- return this.itemHeight()+this.spacing()*2;
- };
- $.prototype.maxItems = function(){
- return this._maxItems;
- };
- $.prototype.itemHeight = function() {
- return this.lineHeight();
- };
- $.prototype.itemWidth = function() {
- return 48;
- };
- $.prototype.numVisibleRows = function() {
- return 1;
- };
- $.prototype.spacing = function() {
- return this.standardPadding();
- };
- $.prototype.maxCols = function() {
- return this.maxItems();
- };
- $.prototype.selectLast = function() {
- this.select(0);
- };
- $.prototype.drawItem = function(index){
- this.drawKeys(index);
- };
- $.prototype.drawKeys = function(index) {
- var rect = this.itemRect(index);
- this.drawText(this._currentOrder[index],rect.x,rect.y,rect.width,'center');
- };
- $.prototype.cursorDown = function() {
- var currentIndex = this._possibleKeys.indexOf(this._currentOrder[this.index()]);
- if(currentIndex >= 1){
- this._currentOrder[this.index()] = this._possibleKeys[currentIndex -1];
- }else{
- this._currentOrder[this.index()] = this._possibleKeys[this._possibleKeys.length-1]
- };
- SoundManager.playCursor();
- this.redrawItem(this.index());
- };
- $.prototype.cursorUp = function() {
- var currentIndex = this._possibleKeys.indexOf(this._currentOrder[this.index()]);
- if(currentIndex < (this._possibleKeys.length-1)){
- this._currentOrder[this.index()] = this._possibleKeys[currentIndex + 1];
- }else{
- this._currentOrder[this.index()] = this._possibleKeys[0];
- };
- SoundManager.playCursor();
- this.redrawItem(this.index());
- };
- $.prototype.processOk = function() {
- this.updateInputData();
- this.callOkHandler();
- };
- $.prototype.updateArrows = function() {
- this.downArrowVisible = true;
- this.upArrowVisible = true;
- };
- $.prototype.processCursorMove = function() {
- if (this.isCursorMovable()) {
- var lastIndex = this.index();
- if (Input.isRepeated('right')) {
- this.cursorRight(Input.isTriggered('right'));
- this._refreshArrows();
- }
- if (Input.isRepeated('left')) {
- this.cursorLeft(Input.isTriggered('left'));
- this._refreshArrows();
- }
- if (this.index() !== lastIndex) {
- SoundManager.playCursor();
- }
- }
- if (Input.isTriggered('down')) {
- this.cursorDown();
- }
- if (Input.isTriggered('up')) {
- this.cursorUp();
- }
- };
- $.prototype._refreshArrows = function() {
- var w = this._width;
- var h = this._height;
- var p = 24;
- var q = p/2;
- var sx = 96+p;
- var sy = 0+p;
- var x = this.spacing()+ this.itemWidth()/2+(this.spacing()+this.itemWidth())*this.index();
- this._downArrowSprite.bitmap = this._windowskin;
- this._downArrowSprite.anchor.x = 0.5;
- this._downArrowSprite.anchor.y = 0.5;
- this._downArrowSprite.setFrame(sx+q, sy+q+p, p, q);
- this._downArrowSprite.move(x, h-q);
- this._upArrowSprite.bitmap = this._windowskin;
- this._upArrowSprite.anchor.x = 0.5;
- this._upArrowSprite.anchor.y = 0.5;
- this._upArrowSprite.setFrame(sx+q, sy, p, q);
- this._upArrowSprite.move(x, q);
- };
- })(COLD.PUZZLE.Puzzle_Window);
- (function($){
- ($.prototype = Object.create(Scene_MenuBase.prototype)).constructor = $;
- $.prototype.initialize = function() {
- Scene_MenuBase.prototype.initialize.call(this);
- };
- $.prototype.create = function() {
- Scene_MenuBase.prototype.create.call(this);
- this.createTitle();
- this.createWindows();
- };
- $.prototype.prepare = function(key,variable){
- this._puzzleKey = key;
- this._reorderedKey = this.reorderKey(this._puzzleKey.length);
- this._variable = variable;
- };
- $.prototype.reorderKey = function(length){
- var key = new Array(length);
- for(var i =0; i < length; i++){
- key[i]='-';
- }
- return key;
- };
- $.prototype.createTitle = function(){
- this._titleSprite = new Sprite();
- this.addChild(this._titleSprite);
- this._titleSprite.bitmap = new Bitmap(Graphics.width, Graphics.height);
- };
- $.prototype.createWindows = function(){
- this.createPuzzleWindow();
- };
- $.prototype.update = function(){
- Scene_MenuBase.prototype.update.call(this);
- this.drawTitle();
- };
- $.prototype.drawTitle = function(){
- var bitmap = this._titleSprite.bitmap;
- var x = this._puzzleWindow.windowX;
- var y = this._puzzleWindow.windowY;
- var width = this._puzzleWindow.windowWidth();
- var height = Window_Base.prototype.lineHeight();
- bitmap.clear();
- bitmap.drawText('Please enter the code...', x, y - height, width, height, 'center');
- };
- $.prototype.createPuzzleWindow = function() {
- this._puzzleWindow = new COLD.PUZZLE.Puzzle_Window(this._reorderedKey);
- this._puzzleWindow.setHandler('ok', this.onSelectionOk.bind(this));
- this._puzzleWindow.setHandler('cancel', this.popScene.bind(this));
- this.addWindow(this._puzzleWindow);
- this._puzzleWindow.activate();
- };
- $.prototype.onSelectionOk = function(){
- if(this.checkForSolved()){
- SoundManager.playRecovery();
- $gameVariables[this._variable] = true;
- this.popScene();
- }else{
- SoundManager.playBuzzer();
- }
- this._puzzleWindow.activate();
- };
- $.prototype.checkForSolved = function(){
- for(var i = 0; i < this._puzzleKey.length;i++) {
- if(this._puzzleWindow._currentOrder[i] !== this._puzzleKey[i]){
- return false;
- };
- };
- return true;
- };
- })(COLD.PUZZLE.Puzzle_Scene);
Advertisement
Add Comment
Please, Sign In to add comment