diff --git a/src/game/global/define_variables_global.js b/src/game/global/define_variables_global.js new file mode 100644 index 0000000..92a4ee2 --- /dev/null +++ b/src/game/global/define_variables_global.js @@ -0,0 +1,30 @@ +const LANGUAGE_KOREAN = "korean"; +const LANGUAGE_ENGLISH = "english"; + +const MODE_RELEASE = "release"; +const MODE_DEBUG = "debug"; +const runMode = MODE_DEBUG; + +function isDebugMode() { + // console.log("debug mode ? " + runMode); + return runMode == MODE_DEBUG ? true : false; +} + +function isReleaseMode() { + // console.log("release mode ? " + runMode); + return runMode == MODE_RELEASE ? true : false; +} + + +const GAME_SCREEN_SIZE = { x: 1024, y: 768 +} + + +let playerName; +let playerUserID; +let bestRecord = 0; +let playingStageData; + +let textStyleBasic = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" }; + +let backButtonPosition = { x: 100, y: 70 }; diff --git a/src/game/global/loading/loading.js b/src/game/global/loading/loading.js new file mode 100644 index 0000000..abd72c9 --- /dev/null +++ b/src/game/global/loading/loading.js @@ -0,0 +1,114 @@ +///////////////////////////// +// Loading + +// var x = 32; +// var y = 80; + +var Loading = { + + preload: function() { + this.game.load.image('loadingbar', './image/phaser.png'); + }, + + create: function() { + // console.log('Loading'); + + this.game.stage.backgroundColor = '#4d4d4d'; + + // Progress report + this.textProgress = game.add.text(game.world.centerX, 100, '로딩중 . . .', textStyleBasic); + this.textProgress.anchor.setTo(0.5, 0.4); + this.textProgress.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); + + // Preload bar + this.preloadBar = this.add.sprite(game.world.centerX, game.world.centerY, 'loadingbar'); + this.preloadBar.anchor.setTo(0.5); + this.preloadBar.alpha = 0; + + this.game.load.onFileComplete.add(this.fileComplete, this); + this.game.load.onLoadComplete.add(this.loadComplete, this); + + this.startLoading(); + }, + + startLoading: function() { + // this.game.load.image('a', './image/phaser.png'); + // this.game.load.image('b', './image/phaser.png'); + // this.game.load.image('c', './image/phaser.png'); + // this.game.load.image('d', './image/phaser.png'); + // this.game.load.image('e', './image/phaser.png'); + // this.game.load.image('g', './image/phaser.png'); + // this.game.load.image('e', './image/phaser.png'); + // this.game.load.image('f', './image/phaser.png'); + // this.game.load.image('g', './image/phaser.png'); + // this.game.load.image('h', './image/phaser.png'); + + this.game.load.image('phaser', './image/phaser.png'); + this.game.load.spritesheet('button', './image/button_basic.png', 200, 100); + this.game.load.image('star', './image/star_particle.png'); + this.game.load.image('medal_gold', './image/medal_gold.png'); + this.game.load.image('medal_silver', './image/medal_silver.png'); + this.game.load.image('medal_bronze', './image/medal_bronze.png'); + + this.game.load.start(); + }, + + fileComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) { + this.preloadBar.alpha = progress / 100; + + // console.log('progress : ' + progress); + + /* + text.setText("File Complete: " + progress + "% - " + totalLoaded + " out of " + totalFiles); + + var newImage = game.add.image(x, y, cacheKey); + newImage.scale.set(0.3); + + x += newImage.width + 20; + if (x > 700) + { + x = 32; + y += 332; + } + */ + }, + + loadComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) { + this.preloadBar.alpha = 1; + + if(isReleaseMode()) { + this.state.start('Login'); + return; + } + + this.state.start('Login'); + // this.startMenu(); + // this.startTypingTestStage(); + // this.startTypingTestResult(); + }, + + startMenu: function() { + this.setupTestData(); + this.state.start('Menu'); + }, + + startTypingTestStage: function() { + this.setupTestData(); + this.state.start('TypingTestStage'); + }, + + startTypingTestResult: function() { + this.setupTestData(); + this.state.start('TypingTestResult'); + }, + + setupTestData: function() { + playerUserID = 1; + playerName = "박지상"; + + bestRecord = 300; + typingRecordTotal = 400; + playingStageData = new StageData(LANGUAGE_KOREAN, 1); + } + +} \ No newline at end of file diff --git a/src/game/lib/input_type_text.js b/src/game/lib/input_type_text.js new file mode 100644 index 0000000..0015a9a --- /dev/null +++ b/src/game/lib/input_type_text.js @@ -0,0 +1,1425 @@ +var InputTypeText = function(x, y) { + var bmd = game.add.bitmapData(400, 50); + var myInput = game.add.sprite(x, y, bmd); + + myInput.canvasInput = new CanvasInput({ + canvas: bmd.canvas, + fontSize: 30, + fontFamily: 'Arial', + fontColor: '#212121', + fontWeight: 'bold', + width: 400, + padding: 8, + borderWidth: 1, + borderColor: '#000', + borderRadius: 3, + boxShadow: '1px 1px 0px #fff', + innerShadow: '0px 0px 5px rgba(0, 0, 0, 0.5)', + placeHolder: 'Enter message here...' + }); + myInput.inputEnabled = true; + myInput.input.useHandCursor = true; + myInput.events.onInputUp.add(this.inputFocus, this); + + return myInput; +}; + +InputTypeText.prototype = { + inputFocus: function(sprite){ + sprite.canvasInput.focus(); + } +}; + +/* +var inputFocus = function(sprite){ + sprite.canvasInput.focus(); +} + +var createInput = function(x, y){ + var bmd = game.add.bitmapData(400, 50); + var myInput = game.add.sprite(x, y, bmd); + + myInput.canvasInput = new CanvasInput({ + canvas: bmd.canvas, + fontSize: 30, + fontFamily: 'Arial', + fontColor: '#212121', + fontWeight: 'bold', + width: 400, + padding: 8, + borderWidth: 1, + borderColor: '#000', + borderRadius: 3, + boxShadow: '1px 1px 0px #fff', + innerShadow: '0px 0px 5px rgba(0, 0, 0, 0.5)', + placeHolder: 'Enter message here...' + }); + myInput.inputEnabled = true; + myInput.input.useHandCursor = true; + myInput.events.onInputUp.add(this.inputFocus, this); + + return myInput; +} +*/ + + +/*! + * CanvasInput v1.2.0 + * https://goldfirestudios.com/blog/108/CanvasInput-HTML5-Canvas-Text-Input + * + * (c) 2013-2015, James Simpson of GoldFire Studios + * goldfirestudios.com + * + * MIT License + */ + +(function() { + // create a buffer that stores all inputs so that tabbing + // between them is made possible. + var inputs = []; + + // initialize the Canvas Input + var CanvasInput = window.CanvasInput = function(o) { + var self = this; + + o = o ? o : {}; + + // setup the defaults + self._canvas = o.canvas || null; + self._ctx = self._canvas ? self._canvas.getContext('2d') : null; + self._x = o.x || 0; + self._y = o.y || 0; + self._extraX = o.extraX || 0; + self._extraY = o.extraY || 0; + self._fontSize = o.fontSize || 14; + self._fontFamily = o.fontFamily || 'Arial'; + self._fontColor = o.fontColor || '#000'; + self._placeHolderColor = o.placeHolderColor || '#bfbebd'; + self._fontWeight = o.fontWeight || 'normal'; + self._fontStyle = o.fontStyle || 'normal'; + self._readonly = o.readonly || false; + self._maxlength = o.maxlength || null; + self._width = o.width || 150; + self._height = o.height || self._fontSize; + self._padding = o.padding >= 0 ? o.padding : 5; + self._borderWidth = o.borderWidth >= 0 ? o.borderWidth : 1; + self._borderColor = o.borderColor || '#959595'; + self._borderRadius = o.borderRadius >= 0 ? o.borderRadius : 3; + self._backgroundImage = o.backgroundImage || ''; + self._boxShadow = o.boxShadow || '1px 1px 0px rgba(255, 255, 255, 1)'; + self._innerShadow = o.innerShadow || '0px 0px 4px rgba(0, 0, 0, 0.4)'; + self._selectionColor = o.selectionColor || 'rgba(179, 212, 253, 0.8)'; + self._placeHolder = o.placeHolder || ''; + self._value = (o.value || self._placeHolder) + ''; + self._onsubmit = o.onsubmit || function() {}; + self._onkeydown = o.onkeydown || function() {}; + self._onkeyup = o.onkeyup || function() {}; + self._onfocus = o.onfocus || function() {}; + self._onblur = o.onblur || function() {}; + self._cursor = false; + self._cursorPos = 0; + self._hasFocus = false; + self._selection = [0, 0]; + self._wasOver = false; + + // parse box shadow + self.boxShadow(self._boxShadow, true); + + // calculate the full width and height with padding, borders and shadows + self._calcWH(); + + // setup the off-DOM canvas + self._renderCanvas = document.createElement('canvas'); + self._renderCanvas.setAttribute('width', self.outerW); + self._renderCanvas.setAttribute('height', self.outerH); + self._renderCtx = self._renderCanvas.getContext('2d'); + + // setup another off-DOM canvas for inner-shadows + self._shadowCanvas = document.createElement('canvas'); + self._shadowCanvas.setAttribute('width', self._width + self._padding * 2); + self._shadowCanvas.setAttribute('height', self._height + self._padding * 2); + self._shadowCtx = self._shadowCanvas.getContext('2d'); + + // setup the background color + if (typeof o.backgroundGradient !== 'undefined') { + self._backgroundColor = self._renderCtx.createLinearGradient( + 0, + 0, + 0, + self.outerH + ); + self._backgroundColor.addColorStop(0, o.backgroundGradient[0]); + self._backgroundColor.addColorStop(1, o.backgroundGradient[1]); + } else { + self._backgroundColor = o.backgroundColor || '#fff'; + } + + // setup main canvas events + if (self._canvas) { + self._canvas.addEventListener('mousemove', function(e) { + e = e || window.event; + self.mousemove(e, self); + }, false); + + self._canvas.addEventListener('mousedown', function(e) { + e = e || window.event; + self.mousedown(e, self); + }, false); + + self._canvas.addEventListener('mouseup', function(e) { + e = e || window.event; + self.mouseup(e, self); + }, false); + } + + // setup a global mouseup to blur the input outside of the canvas + window.addEventListener('mouseup', function(e) { + e = e || window.event; + + if (self._hasFocus && !self._mouseDown) { + self.blur(); + } + }, true); + + // create the hidden input element + self._hiddenInput = document.createElement('input'); + self._hiddenInput.type = 'text'; + self._hiddenInput.style.position = 'absolute'; + self._hiddenInput.style.opacity = 0; + self._hiddenInput.style.pointerEvents = 'none'; + self._hiddenInput.style.left = (self._x + self._extraX + (self._canvas ? self._canvas.offsetLeft : 0)) + 'px'; + self._hiddenInput.style.top = (self._y + self._extraY + (self._canvas ? self._canvas.offsetTop : 0)) + 'px'; + self._hiddenInput.style.width = self._width + 'px'; + self._hiddenInput.style.height = self._height + 'px'; + self._hiddenInput.style.zIndex = 0; + if (self._maxlength) { + self._hiddenInput.maxLength = self._maxlength; + } + document.body.appendChild(self._hiddenInput); + self._hiddenInput.value = self._value; + + // setup the keydown listener + self._hiddenInput.addEventListener('keydown', function(e) { + e = e || window.event; + + if (self._hasFocus) { + self.keydown(e, self); + } + }); + + // setup the keyup listener + self._hiddenInput.addEventListener('keyup', function(e) { + e = e || window.event; + + // update the canvas input state information from the hidden input + self._value = self._hiddenInput.value; + self._cursorPos = self._hiddenInput.selectionStart; + self.render(); + + if (self._hasFocus) { + self._onkeyup(e, self); + } + }); + + // add this to the buffer + inputs.push(self); + self._inputsIndex = inputs.length - 1; + + // draw the text box + self.render(); + }; + + // setup the prototype + CanvasInput.prototype = { + /** + * Get/set the main canvas. + * @param {Object} data Canvas reference. + * @return {Mixed} CanvasInput or current canvas. + */ + canvas: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._canvas = data; + self._ctx = self._canvas.getContext('2d'); + + return self.render(); + } else { + return self._canvas; + } + }, + + /** + * Get/set the x-position. + * @param {Number} data The pixel position along the x-coordinate. + * @return {Mixed} CanvasInput or current x-value. + */ + x: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._x = data; + + return self.render(); + } else { + return self._x; + } + }, + + /** + * Get/set the y-position. + * @param {Number} data The pixel position along the y-coordinate. + * @return {Mixed} CanvasInput or current y-value. + */ + y: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._y = data; + + return self.render(); + } else { + return self._y; + } + }, + + /** + * Get/set the extra x-position (generally used when no canvas is specified). + * @param {Number} data The pixel position along the x-coordinate. + * @return {Mixed} CanvasInput or current x-value. + */ + extraX: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._extraX = data; + + return self.render(); + } else { + return self._extraX; + } + }, + + /** + * Get/set the extra y-position (generally used when no canvas is specified). + * @param {Number} data The pixel position along the y-coordinate. + * @return {Mixed} CanvasInput or current y-value. + */ + extraY: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._extraY = data; + + return self.render(); + } else { + return self._extraY; + } + }, + + /** + * Get/set the font size. + * @param {Number} data Font size. + * @return {Mixed} CanvasInput or current font size. + */ + fontSize: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._fontSize = data; + + return self.render(); + } else { + return self._fontSize; + } + }, + + /** + * Get/set the font family. + * @param {String} data Font family. + * @return {Mixed} CanvasInput or current font family. + */ + fontFamily: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._fontFamily = data; + + return self.render(); + } else { + return self._fontFamily; + } + }, + + /** + * Get/set the font color. + * @param {String} data Font color. + * @return {Mixed} CanvasInput or current font color. + */ + fontColor: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._fontColor = data; + + return self.render(); + } else { + return self._fontColor; + } + }, + + /** + * Get/set the place holder font color. + * @param {String} data Font color. + * @return {Mixed} CanvasInput or current place holder font color. + */ + placeHolderColor: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._placeHolderColor = data; + + return self.render(); + } else { + return self._placeHolderColor; + } + }, + + /** + * Get/set the font weight. + * @param {String} data Font weight. + * @return {Mixed} CanvasInput or current font weight. + */ + fontWeight: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._fontWeight = data; + + return self.render(); + } else { + return self._fontWeight; + } + }, + + /** + * Get/set the font style. + * @param {String} data Font style. + * @return {Mixed} CanvasInput or current font style. + */ + fontStyle: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._fontStyle = data; + + return self.render(); + } else { + return self._fontStyle; + } + }, + + /** + * Get/set the width of the text box. + * @param {Number} data Width in pixels. + * @return {Mixed} CanvasInput or current width. + */ + width: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._width = data; + self._calcWH(); + self._updateCanvasWH(); + + return self.render(); + } else { + return self._width; + } + }, + + /** + * Get/set the height of the text box. + * @param {Number} data Height in pixels. + * @return {Mixed} CanvasInput or current height. + */ + height: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._height = data; + self._calcWH(); + self._updateCanvasWH(); + + return self.render(); + } else { + return self._height; + } + }, + + /** + * Get/set the padding of the text box. + * @param {Number} data Padding in pixels. + * @return {Mixed} CanvasInput or current padding. + */ + padding: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._padding = data; + self._calcWH(); + self._updateCanvasWH(); + + return self.render(); + } else { + return self._padding; + } + }, + + /** + * Get/set the border width. + * @param {Number} data Border width. + * @return {Mixed} CanvasInput or current border width. + */ + borderWidth: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._borderWidth = data; + self._calcWH(); + self._updateCanvasWH(); + + return self.render(); + } else { + return self._borderWidth; + } + }, + + /** + * Get/set the border color. + * @param {String} data Border color. + * @return {Mixed} CanvasInput or current border color. + */ + borderColor: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._borderColor = data; + + return self.render(); + } else { + return self._borderColor; + } + }, + + /** + * Get/set the border radius. + * @param {Number} data Border radius. + * @return {Mixed} CanvasInput or current border radius. + */ + borderRadius: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._borderRadius = data; + + return self.render(); + } else { + return self._borderRadius; + } + }, + + /** + * Get/set the background color. + * @param {Number} data Background color. + * @return {Mixed} CanvasInput or current background color. + */ + backgroundColor: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._backgroundColor = data; + + return self.render(); + } else { + return self._backgroundColor; + } + }, + + /** + * Get/set the background gradient. + * @param {Number} data Background gradient. + * @return {Mixed} CanvasInput or current background gradient. + */ + backgroundGradient: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._backgroundColor = self._renderCtx.createLinearGradient( + 0, + 0, + 0, + self.outerH + ); + self._backgroundColor.addColorStop(0, data[0]); + self._backgroundColor.addColorStop(1, data[1]); + + return self.render(); + } else { + return self._backgroundColor; + } + }, + + /** + * Get/set the box shadow. + * @param {String} data Box shadow in CSS format (1px 1px 1px rgba(0, 0, 0.5)). + * @param {Boolean} doReturn (optional) True to prevent a premature render. + * @return {Mixed} CanvasInput or current box shadow. + */ + boxShadow: function(data, doReturn) { + var self = this; + + if (typeof data !== 'undefined') { + // parse box shadow + var boxShadow = data.split('px '); + self._boxShadow = { + x: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[0], 10), + y: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[1], 10), + blur: self._boxShadow === 'none' ? 0 : parseInt(boxShadow[2], 10), + color: self._boxShadow === 'none' ? '' : boxShadow[3] + }; + + // take into account the shadow and its direction + if (self._boxShadow.x < 0) { + self.shadowL = Math.abs(self._boxShadow.x) + self._boxShadow.blur; + self.shadowR = self._boxShadow.blur + self._boxShadow.x; + } else { + self.shadowL = Math.abs(self._boxShadow.blur - self._boxShadow.x); + self.shadowR = self._boxShadow.blur + self._boxShadow.x; + } + if (self._boxShadow.y < 0) { + self.shadowT = Math.abs(self._boxShadow.y) + self._boxShadow.blur; + self.shadowB = self._boxShadow.blur + self._boxShadow.y; + } else { + self.shadowT = Math.abs(self._boxShadow.blur - self._boxShadow.y); + self.shadowB = self._boxShadow.blur + self._boxShadow.y; + } + + self.shadowW = self.shadowL + self.shadowR; + self.shadowH = self.shadowT + self.shadowB; + + self._calcWH(); + + if (!doReturn) { + self._updateCanvasWH(); + + return self.render(); + } + } else { + return self._boxShadow; + } + }, + + /** + * Get/set the inner shadow. + * @param {String} data In the format of a CSS box shadow (1px 1px 1px rgba(0, 0, 0.5)). + * @return {Mixed} CanvasInput or current inner shadow. + */ + innerShadow: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._innerShadow = data; + + return self.render(); + } else { + return self._innerShadow; + } + }, + + /** + * Get/set the text selection color. + * @param {String} data Color. + * @return {Mixed} CanvasInput or current selection color. + */ + selectionColor: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._selectionColor = data; + + return self.render(); + } else { + return self._selectionColor; + } + }, + + /** + * Get/set the place holder text. + * @param {String} data Place holder text. + * @return {Mixed} CanvasInput or current place holder text. + */ + placeHolder: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._placeHolder = data; + + return self.render(); + } else { + return self._placeHolder; + } + }, + + /** + * Get/set the current text box value. + * @param {String} data Text value. + * @return {Mixed} CanvasInput or current text value. + */ + value: function(data) { + var self = this; + + if (typeof data !== 'undefined') { + self._value = data + ''; + self._hiddenInput.value = data + ''; + + // update the cursor position + self._cursorPos = self._clipText().length; + + self.render(); + + return self; + } else { + return (self._value === self._placeHolder) ? '' : self._value; + } + }, + + /** + * Set or fire the onsubmit event. + * @param {Function} fn Custom callback. + */ + onsubmit: function(fn) { + var self = this; + + if (typeof fn !== 'undefined') { + self._onsubmit = fn; + + return self; + } else { + self._onsubmit(); + } + }, + + /** + * Set or fire the onkeydown event. + * @param {Function} fn Custom callback. + */ + onkeydown: function(fn) { + var self = this; + + if (typeof fn !== 'undefined') { + self._onkeydown = fn; + + return self; + } else { + self._onkeydown(); + } + }, + + /** + * Set or fire the onkeyup event. + * @param {Function} fn Custom callback. + */ + onkeyup: function(fn) { + var self = this; + + if (typeof fn !== 'undefined') { + self._onkeyup = fn; + + return self; + } else { + self._onkeyup(); + } + }, + + /** + * Place focus on the CanvasInput box, placing the cursor + * either at the end of the text or where the user clicked. + * @param {Number} pos (optional) The position to place the cursor. + * @return {CanvasInput} + */ + focus: function(pos) { + var self = this; + + // only fire the focus event when going from unfocussed + if (!self._hasFocus) { + self._onfocus(self); + + // remove focus from all other inputs + for (var i=0; i