diff --git a/vs/PhaserTest001/PhaserTest001.csproj b/vs/PhaserTest001/PhaserTest001.csproj index 438d5a1..782f645 100644 --- a/vs/PhaserTest001/PhaserTest001.csproj +++ b/vs/PhaserTest001/PhaserTest001.csproj @@ -28,9 +28,10 @@ + - + @@ -43,6 +44,7 @@ + diff --git a/vs/PhaserTest001/app.js b/vs/PhaserTest001/app.js index 8b378bb..28ed978 100644 --- a/vs/PhaserTest001/app.js +++ b/vs/PhaserTest001/app.js @@ -3,15 +3,65 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; +var PhaserSwipe; +(function (PhaserSwipe) { + var Swipe = (function () { + function Swipe(g) { + this.game = g; + this.swipeDown = new Phaser.Signal; + this.swipeUp = new Phaser.Signal; + this.swipeLeft = new Phaser.Signal; + this.swipeRight = new Phaser.Signal; + this.swipeAny = new Phaser.Signal; + this.game.input.onDown.addOnce(this.BeginSwipe, this); + } + Swipe.prototype.BeginSwipe = function (e) { + this.game.input.onUp.addOnce(this.EndSwipe, this); + }; + Swipe.prototype.EndSwipe = function (e) { + this.game.input.onDown.addOnce(this.BeginSwipe, this); + var swipeTime = e.timeUp - e.timeDown; + var swipeDistance = Phaser.Point.subtract(e.position, e.positionDown); + var swipeMagnitude = swipeDistance.getMagnitude(); + var swipeNormal = Phaser.Point.normalize(swipeDistance); + if (swipeMagnitude > 20 && swipeTime < 1000 && (Math.abs(swipeNormal.x) > 0.8 || Math.abs(swipeNormal.y) > 0.8)) { + if (swipeNormal.x > 0.8) { + this.swipeRight.dispatch(); + } + if (swipeNormal.x < -0.8) { + this.swipeLeft.dispatch(); + } + if (swipeNormal.y > 0.8) { + this.swipeDown.dispatch(); + } + if (swipeNormal.y < -0.8) { + this.swipeUp.dispatch(); + } + } + this.swipeAny.dispatch(swipeDistance, swipeTime); + }; + return Swipe; + }()); + PhaserSwipe.Swipe = Swipe; +})(PhaserSwipe || (PhaserSwipe = {})); var GameCurling; (function (GameCurling) { - var SETTINGS = (function () { - function SETTINGS() { - this.SCREEN_WIDTH = 600; - this.SCREEN_HEIGHT = 800; + var ANIMATION_WAITER = (function () { + function ANIMATION_WAITER() { + this.refs = 0; } - return SETTINGS; - })(); + ANIMATION_WAITER.prototype.addRef = function (cb, ctx) { + this.refs++; + if (cb !== null && typeof cb == 'function') + cb.apply(ctx); + }; + ANIMATION_WAITER.prototype.releaseRef = function (cb, ctx) { + this.refs--; + if (this.refs == 0 && cb !== null && typeof cb == 'function') + cb.apply(ctx); + }; + return ANIMATION_WAITER; + }()); ; ; ; @@ -21,18 +71,44 @@ var GameCurling; function TitleScreenState() { _super.call(this); } - TitleScreenState.prototype.preload = function () { - this.game.load.image("title", "res/title.png"); - }; TitleScreenState.prototype.create = function () { this.game.add.sprite(0, 0, "title"); - this.input.onTap.addOnce(this.titleClicked, this); + this.sfx = this.game.add.audio("sfx_battery"); + var styleTextCommonButton = { font: "21px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + this.btnRules = this.game.add.button(this.game.world.centerX - 140, 470, 'btn', this.ShowRules, this, 1, 0, 1, 0); + var textRules = this.game.add.text(0, 0, "Посмотреть правила", styleTextCommonButton); + textRules.setTextBounds(0, 472, this.game.width, 50); + this.btnHighscoresEnabled = this.game.add.button(this.game.world.centerX - 140, 550, 'btn', this.ShowHighscores, this, 1, 0, 1, 0); + this.btnHighscoresEnabled.visible = false; + this.btnHighscoresDisabled = this.game.add.button(this.game.world.centerX - 140, 550, 'btn', null, null, 2, 2, 2, 2); + var textHighscores = this.game.add.text(0, 0, "Восхищаться рекордами", styleTextCommonButton); + textHighscores.setTextBounds(0, 552, this.game.width, 50); + this.btnStart = this.game.add.button(this.game.world.centerX - 140 * 1.3, 691, 'btn', this.StartGame, this, 1, 0, 1, 0); + var styleStart = { font: "40px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + var textStart = this.game.add.text(0, 0, "ЖМИ И ИГРАЙ!", styleStart); + textStart.setTextBounds(0, 702, this.game.width, 50); + this.btnStart.scale.set(1.3); + window['databaseAnonymousAuth'](this, this.EnableHighscoresButton); }; - TitleScreenState.prototype.titleClicked = function () { + TitleScreenState.prototype.StartGame = function () { + this.sfx.play(); this.game.state.start("GameRunningState"); }; + TitleScreenState.prototype.ShowRules = function () { + this.sfx.play(); + this.game.state.start("ShowRulesState"); + }; + TitleScreenState.prototype.ShowHighscores = function () { + this.sfx.play(); + window['showHighscores'](); + }; + TitleScreenState.prototype.EnableHighscoresButton = function () { + console.log("enable hs button"); + this.btnHighscoresEnabled.visible = true; + this.btnHighscoresDisabled.visible = false; + }; return TitleScreenState; - })(Phaser.State); + }(Phaser.State)); GameCurling.TitleScreenState = TitleScreenState; ; var EndGameScreenState = (function (_super) { @@ -43,274 +119,488 @@ var GameCurling; EndGameScreenState.prototype.init = function (pts) { this.points = pts; }; - EndGameScreenState.prototype.preload = function () { - this.game.load.image("bg", "res/empty.png"); - }; EndGameScreenState.prototype.create = function () { - this.game.add.sprite(0, 0, "bg"); - var style = { font: "bold 65px Courier", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" }; - this.textGameOver = this.game.add.text(0, 0, "ВОТ И ВСЕ", style); - this.textGameOver.setTextBounds(0, 150, this.game.width, 100); - style.font = "bold 30px Courier"; - this.textRecord = this.game.add.text(0, 0, "Камней сломалось: " + this.points, style); - this.textRecord.setTextBounds(0, 250, this.game.width, 50); - var styleoverall = { font: "20px Courier", fill: "#fff", align: "left", wordWrap: true, wordWrapWidth: this.game.width - 30 }; - this.textRecord = this.game.add.text(30, 350, "Не стоит отчаиваться! Если что, то приезжай в керлинг-клуб \ -'Пингвин' и там сможешь по- настоящему покатать камни и потереть щеткой!\n\n\ -Жду тебя в субботу к 13:30 прямо там (это что бы время было переодеться).\n\ -Адрес: Станционная, 102 (это практически Экспоцентр)\n\n\ -Возьми удобную одежду - это же спорт!", styleoverall); - this.input.onTap.addOnce(this.titleClicked, this); - }; - EndGameScreenState.prototype.titleClicked = function () { + this.game.stage.backgroundColor = "#001640"; + this.sfx = this.game.add.audio("sfx_battery"); + var style = { font: "bold 65px monospace", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" }; + var textGameOver = this.game.add.text(0, 0, "ВОТ И ВСЕ", style); + textGameOver.setTextBounds(0, 150, this.game.width, 100); + style.font = "bold 30px monospace"; + var textRecord = this.game.add.text(0, 0, "Камней сломалось: " + this.points, style); + textRecord.setTextBounds(0, 250, this.game.width, 50); + var styleTextCommonButton = { font: "21px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + this.btnMenu = this.game.add.button(this.game.world.centerX - 140, 600, 'btn', this.GoMainMenu, this, 1, 0, 1, 0); + var textMenu = this.game.add.text(0, 0, "Я буду ROGUE ONE!", styleTextCommonButton); + textMenu.setTextBounds(0, 602, this.game.width, 50); + this.btnSave = this.game.add.button(this.game.world.centerX - 140, 400, 'btn', this.SaveResult, this, 1, 0, 1, 0); + var textSave = this.game.add.text(0, 0, "Сохранить результат", styleTextCommonButton); + textSave.setTextBounds(0, 402, this.game.width, 50); + }; + EndGameScreenState.prototype.GoMainMenu = function () { + this.sfx.play(); this.game.state.start("TitleScreenState"); }; + EndGameScreenState.prototype.SaveResult = function () { + if (this.points !== undefined) { + this.sfx.play(); + window['showNameBox'](this.points, this, this.GoMainMenu); + } + else { + this.GoMainMenu(); + } + }; return EndGameScreenState; - })(Phaser.State); + }(Phaser.State)); GameCurling.EndGameScreenState = EndGameScreenState; ; var SimpleGame = (function (_super) { __extends(SimpleGame, _super); function SimpleGame() { - /* this.game = new Phaser.Game(this.SCREEN_WIDTH, this.SCREEN_HEIGHT, Phaser.AUTO, 'gamefield', - { - preload: this.preload, - create: this.create, - update: this.update - }); */ _super.call(this); - this.SCREEN_WIDTH = 600; - this.SCREEN_HEIGHT = 800; this.TILE_ROWS = 11; this.TILE_COLUMNS = 6; this.TILE_SIZE = 64; this.TILE_SPACE = 5; this.OFFSET_FIELD = 91; this.maxRow = 0; + this.lockInput = false; + this.aw = new ANIMATION_WAITER; } - // handle input function - SimpleGame.prototype.HandleTouchMouse = function (pointer) { - if (this.bottomRect.contains(pointer.x, pointer.y)) { - this.DropRowDown(); - } - if (this.topLeftRect.contains(pointer.x, pointer.y)) { - this.ShiftRowLeft(); - } - if (this.topRighRect.contains(pointer.x, pointer.y)) { - this.ShiftRowRight(); - } - }; SimpleGame.prototype.ShiftRowLeft = function () { var _this = this; + if (this.lockInput) { + return; + } + this.sfxWall.play(); var shifted = this.row.shift(); this.row.push(shifted); this.row.forEach(function (spr, idx) { - spr.position.set(_this.OFFSET_FIELD + _this.TILE_SPACE + idx * (_this.TILE_SPACE + _this.TILE_SIZE), _this.TILE_SPACE); + _this.TweenSpritePosition(spr, _this.OFFSET_FIELD + _this.TILE_SPACE + idx * (_this.TILE_SPACE + _this.TILE_SIZE), _this.TILE_SPACE); }, this); }; SimpleGame.prototype.ShiftRowRight = function () { var _this = this; + if (this.lockInput) { + return; + } + this.sfxWall.play(); var popped = this.row.pop(); this.row.unshift(popped); this.row.forEach(function (spr, idx) { - spr.position.set(_this.OFFSET_FIELD + _this.TILE_SPACE + idx * (_this.TILE_SPACE + _this.TILE_SIZE), _this.TILE_SPACE); + _this.TweenSpritePosition(spr, _this.OFFSET_FIELD + _this.TILE_SPACE + idx * (_this.TILE_SPACE + _this.TILE_SIZE), _this.TILE_SPACE); }, this); }; - SimpleGame.prototype.DropRowDown = function () { + SimpleGame.prototype.DropBlocks = function () { var _this = this; - // drop stones into field + if (this.lockInput) { + return; + } + this.sfxBattery.play(); this.row.forEach(function (spr, idx) { _this.field[idx] ? _this.field[idx] : _this.field[idx] = []; var fcy = _this.field[idx].filter(function (num) { return num.color >= 0; }).length; - _this.field[idx][fcy] = { color: parseInt(spr.key.toString()[1]), key: _this.sprtId }; + _this.field[idx][fcy] = { color: _this.ParseColorFromSprite(spr), key: _this.sprtId }; spr.anchor.set(0, 1); - spr.position.y = _this.SCREEN_HEIGHT - _this.TILE_SPACE - (fcy * (_this.TILE_SPACE + _this.TILE_SIZE)); - _this.fieldSprites.push({ key: _this.sprtId, sprt: spr }); - _this.sprtId += 1; + _this.TweenSpritePosition(spr, spr.position.x, _this.game.height - _this.TILE_SPACE - (fcy * (_this.TILE_SPACE + _this.TILE_SIZE)), null, _this.RemoveEmptySpaces); + _this.fieldSprites.push({ key: _this.sprtId++, sprt: spr }); }, this); this.row = []; - // check field - while (1) { - var bFieldChecked = true; - for (var x = 0; x < this.TILE_COLUMNS; x++) { - for (var y = 0; y < this.TILE_ROWS; y++) { - if (!this.field[x] || !this.field[x][y] || this.field[x][y].color < 0) + }; + SimpleGame.prototype.RemoveEmptySpaces = function () { + var _this = this; + this.field.forEach(function (line, fldidx) { + line = line.filter(function (val) { return val.color >= 0; }); + _this.field[fldidx] = line; + line.forEach(function (val, idx) { + var spr = _this.fieldSprites.filter(function (s) { return s.key == val.key; }, _this)[0].sprt; + if (spr.position.y != _this.game.height - _this.TILE_SPACE - (idx * (_this.TILE_SPACE + _this.TILE_SIZE))) { + _this.TweenSpritePosition(spr, spr.position.x, _this.game.height - _this.TILE_SPACE - (idx * (_this.TILE_SPACE + _this.TILE_SIZE)), null, _this.CheckField); + } + }, _this); + }, this); + this.TweenSpritePosition(this.dummySprite, this.dummySprite.position.x, this.dummySprite.position.y, null, this.CheckField); + }; + SimpleGame.prototype.CheckField = function () { + var localPoints = 0; + for (var x = 0; x < this.TILE_COLUMNS; x++) { + for (var y = 0; y < this.TILE_ROWS; y++) { + if (!this.field[x] || !this.field[x][y] || this.field[x][y].color < 0) + continue; + var stack = []; + var stackColor = -1; + var fc = { x: x, y: y }; + stack.push(fc); + var colorspace = []; + while (stack.length) { + var ccc = stack.pop(); + if (!ccc) continue; - var stack = []; - var fc = { x: x, y: y }; - stack.push(fc); - var colorspace = []; - while (stack.length) { - var ccc = stack.pop(); - if (!ccc) - continue; - var fval = this.field[ccc.x][ccc.y].color; - colorspace.push(ccc); - // check north - if ((ccc.y < this.TILE_ROWS - 1) && (this.field[ccc.x][ccc.y + 1] && this.field[ccc.x][ccc.y + 1].color == fval)) { - var nc = { x: ccc.x, y: ccc.y + 1 }; - // check for not in colorspace - if (colorspace.filter(function (csc, idx) { return csc.x == nc.x && csc.y == nc.y; }, this).length == 0) - stack.push(nc); - } - // check south - if (ccc.y > 0 && (this.field[ccc.x][ccc.y - 1] && this.field[ccc.x][ccc.y - 1].color == fval)) { - var nc = { x: ccc.x, y: ccc.y - 1 }; - if (colorspace.filter(function (csc, idx) { return csc.x == nc.x && csc.y == nc.y; }, this).length == 0) - stack.push(nc); - } - // check west - if (ccc.x > 0 && (this.field[ccc.x - 1][ccc.y] && this.field[ccc.x - 1][ccc.y].color == fval)) { - var nc = { x: ccc.x - 1, y: ccc.y }; - if (colorspace.filter(function (csc, idx) { return csc.x == nc.x && csc.y == nc.y; }, this).length == 0) - stack.push(nc); - } - // check east - if ((ccc.x < this.TILE_COLUMNS - 1) && (this.field[ccc.x + 1][ccc.y] && this.field[ccc.x + 1][ccc.y].color == fval)) { - var nc = { x: ccc.x + 1, y: ccc.y }; - if (colorspace.filter(function (csc, idx) { return csc.x == nc.x && csc.y == nc.y; }, this).length == 0) - stack.push(nc); - } + if (stackColor < 0) + stackColor = this.field[ccc.x][ccc.y].color; + colorspace.push(ccc); + if ((ccc.y < this.TILE_ROWS - 1) && this.CheckColor(ccc.x, ccc.y + 1, stackColor)) { + var nc = { x: ccc.x, y: ccc.y + 1 }; + if (this.FilterFieldCoord(nc, colorspace)) + stack.push(nc); + } + if (ccc.y > 0 && this.CheckColor(ccc.x, ccc.y - 1, stackColor)) { + var nc = { x: ccc.x, y: ccc.y - 1 }; + if (this.FilterFieldCoord(nc, colorspace)) + stack.push(nc); + } + if (ccc.x > 0 && this.CheckColor(ccc.x - 1, ccc.y, stackColor)) { + var nc = { x: ccc.x - 1, y: ccc.y }; + if (this.FilterFieldCoord(nc, colorspace)) + stack.push(nc); + } + if ((ccc.x < this.TILE_COLUMNS - 1) && this.CheckColor(ccc.x + 1, ccc.y, stackColor)) { + var nc = { x: ccc.x + 1, y: ccc.y }; + if (this.FilterFieldCoord(nc, colorspace)) + stack.push(nc); } - if (colorspace.length < 3) - continue; - bFieldChecked = false; - colorspace.forEach(function (ccc) { - var fval = _this.field[ccc.x][ccc.y]; - fval.color = -1; - var idx = -1; - _this.fieldSprites.filter(function (val, i) { - if (fval.key == val.key) { - idx = i; - return true; - } - return false; - }, _this)[0].sprt.destroy(); - _this.fieldSprites.splice(idx, 1); - }, this); - this.points += colorspace.length; } + if (colorspace.length < 3) + continue; + if (colorspace.length >= 6) { + var arr = this.CreateArray(colorspace.length - 5, 2); + this.bonuses = this.bonuses.concat(arr); + } + else if (colorspace.length > 3) { + this.bonuses.push(colorspace.length - 4); + } + var pt = this.RemoveBlocks(colorspace); + this.sfxPistol.play(); + localPoints += pt; } - if (bFieldChecked) { - console.log(this.field); - break; - } - else { - // this.ShiftFieldBlocks(); - this.field.forEach(function (line, fldidx) { - line = line.filter(function (val) { return val.color >= 0; }); - line.forEach(function (val, idx) { - var spr = _this.fieldSprites.filter(function (s) { return s.key == val.key; }, _this)[0].sprt; - spr.position.y = _this.SCREEN_HEIGHT - _this.TILE_SPACE - (idx * (_this.TILE_SPACE + _this.TILE_SIZE)); - }, _this); - _this.field[fldidx] = line; - }, this); - } } - // update maxRow + if (localPoints == 0) { + this.FinishUpdate(); + } + else { + this.points += localPoints; + this.textValue.text = this.points.toString(); + } + }; + SimpleGame.prototype.RemoveBlocks = function (cs) { + var _this = this; + var _loop_1 = function() { + var actionBlocks = []; + cs.forEach(function (ccc, idx) { + var fval = _this.field[ccc.x][ccc.y]; + if (fval && fval.color >= 0) { + _this.GetActionBlocks(ccc, cs, actionBlocks); + fval.color = -1; + var spr = _this.GetSprite(fval.key); + _this.TweenSpriteAlpha(spr, null, _this.RemoveEmptySpaces); + spr.destroy(); + } + }, this_1); + if (actionBlocks.length == 0) + return "break"; + cs = cs.concat(actionBlocks); + }; + var this_1 = this; + while (1) { + var state_1 = _loop_1(); + if (state_1 === "break") break; + } + return cs.length; + }; + SimpleGame.prototype.TweenSpritePosition = function (spr, newX, newY, onStartCB, onCompleteCB) { + var emptyAnimation = spr.position.x == newX && spr.position.y == newY; + var tw = this.game.add.tween(spr).to({ x: newX, y: newY }, 100, Phaser.Easing.Linear.None); + this.TweenSprite(tw, onStartCB, onCompleteCB); + }; + SimpleGame.prototype.TweenSpriteAlpha = function (spr, onStartCB, onCompleteCB) { + var tw = this.game.add.tween(spr).to({ alpha: 0 }, 100, Phaser.Easing.Linear.None); + this.TweenSprite(tw, onStartCB, onCompleteCB); + }; + SimpleGame.prototype.TweenSprite = function (tw, onStartCB, onCompleteCB) { + var _this = this; + if (onStartCB === null || typeof onStartCB != 'function') + onStartCB = function () { _this.lockInput = true; }; + tw.onStart.addOnce(function () { _this.aw.addRef(onStartCB, _this); }, this); + if (onCompleteCB === null || typeof onCompleteCB != 'function') + onCompleteCB = function () { _this.lockInput = false; }; + tw.onComplete.addOnce(function () { _this.aw.releaseRef(onCompleteCB, _this); }, this); + tw.start(); + }; + SimpleGame.prototype.GetSprite = function (key, splice) { + if (splice === void 0) { splice = false; } + var idx = -1; + var spr = this.fieldSprites.filter(function (val, i) { + if (key == val.key) { + idx = i; + return true; + } + return false; + }, this)[0].sprt; + if (splice) + this.fieldSprites.splice(idx, 1); + return spr; + }; + SimpleGame.prototype.FinishUpdate = function () { for (var c = 0; c < this.TILE_COLUMNS; c++) { - this.maxRow = Math.max(this.field[c].filter(function (num) { return num.color >= 0; }).length, this.maxRow); + this.maxRow = Math.max(this.field[c].length, this.maxRow); } - // spawn new row + this.lockInput = false; this.spawned = false; - // update score - this.textValue.text = this.points.toString(); }; - SimpleGame.prototype.preload = function () { - this.game.load.image('b0', 'res/square_green.png'); - this.game.load.image('b1', 'res/square_blue.png'); - this.game.load.image('b2', 'res/square_red.png'); - this.game.load.image('b3', 'res/square_stone.png'); - this.game.load.image('b4', 'res/square_wood.png'); - this.game.load.image('b5', 'res/square_yellow.png'); - this.game.load.image('field', 'res/cfield.png'); + SimpleGame.prototype.ShuffleArray = function (a) { + for (var i = a.length; i; i--) { + var j = Math.floor(Math.random() * i); + _a = [a[j], a[i - 1]], a[i - 1] = _a[0], a[j] = _a[1]; + } + var _a; + }; + SimpleGame.prototype.GenerateTopBlocks = function () { + var _this = this; + this.row = []; + for (var i = 0; i < this.bonuses.length && i < this.TILE_COLUMNS; i++) { + this.row.push(this.game.add.sprite(0, 0, "s" + this.bonuses[i])); + } + for (var s = this.bonuses.length; s < this.TILE_COLUMNS; s++) { + this.row.push(this.game.add.sprite(0, 0, "b" + this.game.rnd.between(0, this.TILE_COLORS - 1))); + } + this.ShuffleArray(this.row); + this.row.forEach(function (spr, idx) { + spr.position.set(_this.OFFSET_FIELD + _this.TILE_SPACE + idx * (_this.TILE_SPACE + _this.TILE_SIZE), -(_this.TILE_SPACE + _this.TILE_SIZE)); + _this.TweenSpritePosition(spr, spr.position.x, _this.TILE_SPACE); + }, this); + this.bonuses = []; + }; + SimpleGame.prototype.ParseColorFromSprite = function (spr) { + var offset = 0; + if (spr.key[0] == 's') { + offset = this.TILE_COLORS; + } + return parseInt(spr.key[1]) + offset; + }; + SimpleGame.prototype.CheckColor = function (x, y, c) { + if (!this.field[x][y]) + return false; + return (this.field[x][y].color == c || this.field[x][y].color >= this.TILE_COLORS); + }; + SimpleGame.prototype.CreateArray = function (len, val) { + var arr = []; + while (len--) + arr.push(val); + return arr; + }; + SimpleGame.prototype.GetActionBlocks = function (c, cs, ab) { + var fval = this.field[c.x][c.y]; + if (fval.color < this.TILE_COLORS) + return; + switch (fval.color) { + case 6: { + return; + } + case 7: { + { + var nc = { x: c.x, y: Math.min(this.TILE_ROWS - 1, c.y + 1) }; + if (this.FilterFieldCoord(nc, cs) && this.FilterFieldCoord(nc, ab)) + ab.push(nc); + } + { + var nec = { x: Math.min(this.TILE_COLUMNS - 1, c.x + 1), y: Math.min(this.TILE_ROWS - 1, c.y + 1) }; + if (this.FilterFieldCoord(nec, cs) && this.FilterFieldCoord(nec, ab)) + ab.push(nec); + } + { + var ec = { x: Math.min(this.TILE_COLUMNS - 1, c.x + 1), y: c.y }; + if (this.FilterFieldCoord(ec, cs) && this.FilterFieldCoord(ec, ab)) + ab.push(ec); + } + { + var sec = { x: Math.min(this.TILE_COLUMNS - 1, c.x + 1), y: Math.max(0, c.y - 1) }; + if (this.FilterFieldCoord(sec, cs) && this.FilterFieldCoord(sec, ab)) + ab.push(sec); + } + { + var sc = { x: c.x, y: Math.max(0, c.y - 1) }; + if (this.FilterFieldCoord(sc, cs) && this.FilterFieldCoord(sc, ab)) + ab.push(sc); + } + { + var swc = { x: Math.max(0, c.x - 1), y: Math.max(0, c.y - 1) }; + if (this.FilterFieldCoord(swc, cs) && this.FilterFieldCoord(swc, ab)) + ab.push(swc); + } + { + var wc = { x: Math.max(0, c.x - 1), y: c.y }; + if (this.FilterFieldCoord(wc, cs) && this.FilterFieldCoord(wc, ab)) + ab.push(wc); + } + { + var nwc = { x: Math.max(0, c.x - 1), y: Math.min(this.TILE_ROWS - 1, c.y + 1) }; + if (this.FilterFieldCoord(nwc, cs) && this.FilterFieldCoord(nwc, ab)) + ab.push(nwc); + } + break; + } + case 8: { + for (var i = 0; i < this.TILE_COLUMNS; i++) { + var newc = { x: i, y: c.y }; + if (this.FilterFieldCoord(newc, cs) && this.FilterFieldCoord(newc, ab)) + ab.push(newc); + } + break; + } + } + }; + SimpleGame.prototype.FilterFieldCoord = function (c, arr) { + return (arr.filter(function (csc, idx) { return csc.x == c.x && csc.y == c.y; }, this).length == 0); + }; + SimpleGame.prototype.GoToFinalState = function () { + this.game.state.start("EndGameState", true, false, this.points); }; SimpleGame.prototype.create = function () { - // constants - this.SCREEN_WIDTH = 600; - this.SCREEN_HEIGHT = 800; + this.TILE_COLORS = 6; this.TILE_ROWS = 11; this.TILE_COLUMNS = 6; this.TILE_SIZE = 64; this.TILE_SPACE = 5; this.OFFSET_FIELD = 91; - // game variables this.game.add.sprite(0, 0, 'field'); - this.spawned = false; // initial state + this.spawned = false; this.sprtId = 1; this.points = 0; this.field = []; this.fieldSprites = []; + this.bonuses = []; this.cursors = this.game.input.keyboard.createCursorKeys(); - this.cursors.down.onDown.add(SimpleGame.prototype.DropRowDown, this); + this.cursors.down.onDown.add(SimpleGame.prototype.DropBlocks, this); this.cursors.left.onDown.add(SimpleGame.prototype.ShiftRowLeft, this); this.cursors.right.onDown.add(SimpleGame.prototype.ShiftRowRight, this); - this.topLeftRect = new Phaser.Rectangle(0, 0, this.game.width / 2, this.game.height / 2); - this.topRighRect = new Phaser.Rectangle(this.game.width / 2 + 1, 0, this.game.width, this.game.height / 2); - this.bottomRect = new Phaser.Rectangle(0, this.game.height / 2 + 1, this.game.width, this.game.height); - this.game.input.onDown.add(SimpleGame.prototype.HandleTouchMouse, this); + this.swipe = new PhaserSwipe.Swipe(this.game); + this.swipe.swipeDown.add(SimpleGame.prototype.DropBlocks, this); + this.swipe.swipeLeft.add(SimpleGame.prototype.ShiftRowLeft, this); + this.swipe.swipeRight.add(SimpleGame.prototype.ShiftRowRight, this); this.maxRow = 0; - var style = { font: "bold 65px Courier", fill: "#ff0000", align: "right" }; + var style = { font: "bold 65px monospace", fill: "#ff0000", align: "right" }; this.textValue = this.game.add.text(0, 0, "0", style); + this.dummySprite = this.game.add.sprite(-1000, -1000, "b" + this.game.rnd.between(0, 5)); + this.sfxBattery = this.game.add.audio("sfx_battery"); + this.sfxNumKey = this.game.add.audio("sfx_numkey"); + this.sfxWall = this.game.add.audio("sfx_wall"); + this.sfxCells = this.game.add.audio("sfx_cells"); + this.sfxPistol = this.game.add.audio("sfx_pistol"); + this.lockInput = false; }; SimpleGame.prototype.update = function () { + if (this.lockInput) + return; if (this.maxRow >= this.TILE_ROWS) { - // game over - this.game.state.start("EndGameState", true, false, this.points); + this.sfxCells.play(); + for (var x = 0; x < this.TILE_COLUMNS; x++) { + for (var y = 0; y < this.TILE_ROWS; y++) { + if (!this.field[x] || !this.field[x][y] || this.field[x][y].color < 0) + continue; + var spr = this.GetSprite(this.field[x][y].key); + this.TweenSpriteAlpha(spr, null, this.GoToFinalState); + } + } return; } - // spawn if (!this.spawned) { - this.row = []; - for (var s = 0; s < this.TILE_COLUMNS; s++) { - var spr = this.game.add.sprite(this.OFFSET_FIELD + this.TILE_SPACE + s * (this.TILE_SPACE + this.TILE_SIZE), this.TILE_SPACE, "b" + this.game.rnd.between(0, 5)); - this.row.push(spr); - } + this.GenerateTopBlocks(); this.spawned = true; } - if (this.game.input.activePointer.isDown) { - this.game.input.mousePointer.x, this.game.input.mousePointer.y; - } - this.game.input.reset(); }; return SimpleGame; - })(Phaser.State); - var CurlingGame = (function () { - function CurlingGame() { + }(Phaser.State)); + var PreloadAssets = (function (_super) { + __extends(PreloadAssets, _super); + function PreloadAssets() { + _super.call(this); + } + PreloadAssets.prototype.create = function () { + this.game.stage.backgroundColor = "#001640"; + this.text = this.game.add.text(this.game.width / 2, this.game.height / 2, "Loading", { fill: '#ffffff', align: 'center' }); + this.game.load.onFileComplete.add(this.FileComplete, this); + this.game.load.onLoadComplete.add(this.LoadComplete, this); + this.game.load.image('b0', 'res/square_green.png'); + this.game.load.image('b1', 'res/square_blue.png'); + this.game.load.image('b2', 'res/square_red.png'); + this.game.load.image('b3', 'res/square_stone.png'); + this.game.load.image('b4', 'res/square_wood.png'); + this.game.load.image('b5', 'res/square_yellow.png'); + this.game.load.image('s0', 'res/square_any.png'); + this.game.load.image('s1', 'res/bomb.png'); + this.game.load.image('s2', 'res/line.png'); + this.game.load.image('field', 'res/cfield.png'); + this.game.load.audio("sfx_battery", "res/sfx/battery.mp3"); + this.game.load.audio("sfx_numkey", "res/sfx/numkey.mp3"); + this.game.load.audio("sfx_wall", "res/sfx/wall.mp3"); + this.game.load.audio("sfx_cells", "res/sfx/need_cells.mp3"); + this.game.load.audio("sfx_pistol", "res/sfx/pistol.mp3"); + this.game.load.image("title", "res/title.png"); + this.game.load.image("rules", "res/rules.png"); + this.game.load.spritesheet('btn', 'res/btn.png', 280, 50); + this.game.load.start(); + }; + PreloadAssets.prototype.FileComplete = function (progress, cacheKey, success, totalLoaded, totalFiles) { + this.text.setText("Loading " + progress + "% - " + totalLoaded + " out of " + totalFiles); + }; + PreloadAssets.prototype.LoadComplete = function () { + this.game.state.start("TitleScreenState"); + }; + return PreloadAssets; + }(Phaser.State)); + var ShowRulesState = (function (_super) { + __extends(ShowRulesState, _super); + function ShowRulesState() { + _super.call(this); + } + ShowRulesState.prototype.create = function () { + this.game.add.sprite(0, 0, "rules"); + var styleTextCommonButton = { font: "21px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + this.btnBack = this.game.add.button(this.game.world.centerX - 140, 650, 'btn', this.GoBack, this, 1, 0, 1, 0); + var textBack = this.game.add.text(0, 0, "Все понятно", styleTextCommonButton); + textBack.setTextBounds(0, 652, this.game.width, 50); + }; + ShowRulesState.prototype.GoBack = function () { + this.game.add.audio("sfx_battery").play(); + this.game.state.start("TitleScreenState"); + }; + return ShowRulesState; + }(Phaser.State)); + var CurlingGame = (function (_super) { + __extends(CurlingGame, _super); + function CurlingGame(width, height, renderer, parent, state, transparent, antialias, physicsConfig) { + _super.call(this, width, height, renderer, parent, state, transparent, antialias, physicsConfig); + } + return CurlingGame; + }(Phaser.Game)); + var CurlingGameLauncher = (function () { + function CurlingGameLauncher() { this.SCREEN_WIDTH = 600; this.SCREEN_HEIGHT = 800; - this.game = new Phaser.Game(this.SCREEN_WIDTH, this.SCREEN_HEIGHT, Phaser.AUTO, 'gamefield', { create: this.create }); + this.game = new CurlingGame(this.SCREEN_WIDTH, this.SCREEN_HEIGHT, Phaser.AUTO, '', { create: this.create, init: this.init }); this.game.state.add("GameRunningState", SimpleGame, false); this.game.state.add("TitleScreenState", TitleScreenState, false); this.game.state.add("EndGameState", EndGameScreenState, false); - this.game.state.start("TitleScreenState", true, true); + this.game.state.add("PreloadAssets", PreloadAssets, false); + this.game.state.add("ShowRulesState", ShowRulesState, false); } - // This function is called when a full screen request comes in - CurlingGame.prototype.onGoFullScreen = function () { - // tell Phaser how you want it to handle scaling when you go full screen - this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; - // and this causes it to actually do it - this.game.scale.refresh(); - }; - CurlingGame.prototype.goFullScreen = function () { + CurlingGameLauncher.prototype.init = function () { + this.game.input.maxPointers = 1; + if (this.game.device.desktop) { + this.game.scale.scaleMode = Phaser.ScaleManager.NO_SCALE; + this.game.scale.pageAlignHorizontally = true; + } + else { + this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; + } }; - CurlingGame.prototype.create = function () { - var _this = this; - // Set background to white to make effect clearer - this.game.stage.backgroundColor = 0xffffff; - // Add a function that will get called when the game goes fullscreen - this.game.scale.onFullScreenInit.add(CurlingGame.prototype.onGoFullScreen, this); - // Now add a function that will get called when user taps screen. - // Function declared inline using arrow (=>) function expression - // Simply calls startFullScreen(). True specifies you want anti aliasing. - // Unfortunately you can only make full screen requests in desktop browsers in event handlers - this.game.input.onTap.add(function () { _this.game.scale.startFullScreen(true); }, this); + CurlingGameLauncher.prototype.create = function () { + this.game.stage.backgroundColor = "#001640"; + this.game.state.start("PreloadAssets", true, true); }; - return CurlingGame; - })(); - GameCurling.CurlingGame = CurlingGame; + return CurlingGameLauncher; + }()); + GameCurling.CurlingGameLauncher = CurlingGameLauncher; })(GameCurling || (GameCurling = {})); window.onload = function () { - var game = new GameCurling.CurlingGame(); + var game = new GameCurling.CurlingGameLauncher(); }; -//# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/vs/PhaserTest001/app.ts b/vs/PhaserTest001/app.ts index 7f266f4..36d9015 100644 --- a/vs/PhaserTest001/app.ts +++ b/vs/PhaserTest001/app.ts @@ -1,101 +1,4 @@ -module Utils { - export class ScreenMetrics { - windowWidth: number; - windowHeight: number; - - defaultGameWidth: number; - defaultGameHeight: number; - maxGameWidth: number; - maxGameHeight: number - - gameWidth: number; - gameHeight: number; - scaleX: number; - scaleY: number; - offsetX: number; - offsetY: number; - } - - export enum Orientation { PORTRAIT, LANDSCAPE }; - - export class ScreenUtils { - public static screenMetrics: ScreenMetrics; - - // ------------------------------------------------------------------------- - public static calculateScreenMetrics(aDefaultWidth: number, aDefaultHeight: number, - aOrientation: Orientation = Orientation.LANDSCAPE, - aMaxGameWidth?: number, aMaxGameHeight?: number): ScreenMetrics { - // get dimension of window - let windowWidth: number = window.innerWidth; - let windowHeight: number = window.innerHeight; - // swap if window dimensions do not match orientation - if ((windowWidth < windowHeight && aOrientation === Orientation.LANDSCAPE) || - (windowHeight < windowWidth && aOrientation === Orientation.PORTRAIT)) { - let tmp: number = windowWidth; - windowWidth = windowHeight; - windowHeight = tmp; - } - // calculate max game dimension. The bounds are iPad and iPhone - if (typeof aMaxGameWidth === "undefined" || typeof aMaxGameHeight === "undefined") { - if (aOrientation === Orientation.LANDSCAPE) { - aMaxGameWidth = Math.round(aDefaultWidth * 1420 / 1280); - aMaxGameHeight = Math.round(aDefaultHeight * 960 / 800); - } else { - aMaxGameWidth = Math.round(aDefaultWidth * 960 / 800); - aMaxGameHeight = Math.round(aDefaultHeight * 1420 / 1280); - } - } - // default aspect and current window aspect - let defaultAspect: number = (aOrientation === Orientation.LANDSCAPE) ? 1280 / 800 : 800 / 1280; - let windowAspect: number = windowWidth / windowHeight; - - let offsetX: number = 0; - let offsetY: number = 0; - let gameWidth: number = 0; - let gameHeight: number = 0; - - // if (aOrientation === Orientation.LANDSCAPE) { - // "iPhone" landscape ... and "iPad" portrait - if (windowAspect > defaultAspect) { - gameHeight = aDefaultHeight; - gameWidth = Math.ceil((gameHeight * windowAspect) / 2.0) * 2; - gameWidth = Math.min(gameWidth, aMaxGameWidth); - offsetX = (gameWidth - aDefaultWidth) / 2; - offsetY = 0; - } else { // "iPad" landscpae ... and "iPhone" portrait - gameWidth = aDefaultWidth; - gameHeight = Math.ceil((gameWidth / windowAspect) / 2.0) * 2; - gameHeight = Math.min(gameHeight, aMaxGameHeight); - offsetX = 0; - offsetY = (gameHeight - aDefaultHeight) / 2; - } - - // calculate scale - let scaleX: number = windowWidth / gameWidth; - let scaleY: number = windowHeight / gameHeight; - // store values - this.screenMetrics = new ScreenMetrics(); - this.screenMetrics.windowWidth = windowWidth; - this.screenMetrics.windowHeight = windowHeight; - - this.screenMetrics.defaultGameWidth = aDefaultWidth; - this.screenMetrics.defaultGameHeight = aDefaultHeight; - this.screenMetrics.maxGameWidth = aMaxGameWidth; - this.screenMetrics.maxGameHeight = aMaxGameHeight; - - this.screenMetrics.gameWidth = gameWidth; - this.screenMetrics.gameHeight = gameHeight; - this.screenMetrics.scaleX = scaleX; - this.screenMetrics.scaleY = scaleY; - this.screenMetrics.offsetX = offsetX; - this.screenMetrics.offsetY = offsetY; - - return this.screenMetrics; - } - } -} - -module PhaserSwipe { +module PhaserSwipe { export class Swipe { private game: Phaser.Game; @@ -117,15 +20,7 @@ module PhaserSwipe { this.game.input.onDown.addOnce(this.BeginSwipe, this); } - TestBegin(e: Phaser.Pointer) { - console.log("Swipe.TestBegin", e); - } - TestEnd(e: Phaser.Pointer) { - console.log("SwipeTestEnd", e); - } - BeginSwipe(e: Phaser.Pointer) { - console.log("BeginSwipe", e); this.game.input.onUp.addOnce(this.EndSwipe, this); } @@ -178,13 +73,13 @@ module GameCurling { addRef(cb: Function, ctx: any) { this.refs++; -// console.log("AW add " + this.refs); + //console.log("AW add " + this.refs); if (cb !== null && typeof cb == 'function') cb.apply(ctx); } releaseRef(cb: Function, ctx: any) { -// console.log("AW release " + this.refs); + //console.log("AW release " + this.refs); this.refs--; if (this.refs == 0 && cb !== null && typeof cb == 'function') cb.apply(ctx); @@ -207,46 +102,70 @@ module GameCurling { }; export class TitleScreenState extends Phaser.State { - private spaceKey: Phaser.Key; - private sfx: Phaser.Sound; - game: Phaser.Game; + private btnRules: Phaser.Button; + private btnStart: Phaser.Button; + private btnHighscoresEnabled: Phaser.Button; + private btnHighscoresDisabled: Phaser.Button; constructor() { super(); } - preload() { - this.game.load.image("title", "res/title.png"); - this.game.load.audio("click", "res/sfx/battery.mp3"); - } - create() { this.game.add.sprite(0, 0, "title"); - this.input.onTap.addOnce(this.titleClicked, this); + this.sfx = this.game.add.audio("sfx_battery"); + + let styleTextCommonButton = { font: "21px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + + this.btnRules = this.game.add.button(this.game.world.centerX - 140, 470, 'btn', this.ShowRules, this, 1, 0, 1, 0); + let textRules = this.game.add.text(0, 0, "Посмотреть правила", styleTextCommonButton); + textRules.setTextBounds(0, 472, this.game.width, 50); + + this.btnHighscoresEnabled = this.game.add.button(this.game.world.centerX - 140, 550, 'btn', this.ShowHighscores, this, 1, 0, 1, 0); + this.btnHighscoresEnabled.visible = false; + this.btnHighscoresDisabled = this.game.add.button(this.game.world.centerX - 140, 550, 'btn', null, null, 2, 2, 2, 2); + let textHighscores = this.game.add.text(0, 0, "Восхищаться рекордами", styleTextCommonButton); + textHighscores.setTextBounds(0, 552, this.game.width, 50); - this.spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); - this.spaceKey.onDown.add(this.titleClicked, this); + this.btnStart = this.game.add.button(this.game.world.centerX - 140 * 1.3, 691, 'btn', this.StartGame, this, 1, 0, 1, 0); + let styleStart = { font: "40px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + let textStart = this.game.add.text(0, 0, "ЖМИ И ИГРАЙ!", styleStart); + textStart.setTextBounds(0, 702, this.game.width, 50); + this.btnStart.scale.set(1.3); - this.sfx = this.game.add.audio("click"); + window['databaseAnonymousAuth'](this, this.EnableHighscoresButton); } - titleClicked() { + StartGame() { this.sfx.play(); this.game.state.start("GameRunningState"); } + + ShowRules() { + this.sfx.play(); + this.game.state.start("ShowRulesState"); + } + + ShowHighscores() { + this.sfx.play(); + window['showHighscores'](); + } + + EnableHighscoresButton() { + console.log("enable hs button"); + this.btnHighscoresEnabled.visible = true; + this.btnHighscoresDisabled.visible = false; + } }; export class EndGameScreenState extends Phaser.State { - private spaceKey: Phaser.Key; + private btnMenu: Phaser.Button; + private btnSave: Phaser.Button; private sfx: Phaser.Sound; - game: Phaser.Game; - textGameOver: Phaser.Text; - textRecord: Phaser.Text; - textOverall: Phaser.Text; points: number; constructor() { @@ -257,39 +176,42 @@ module GameCurling { this.points = pts; } - preload() { - this.game.load.image("bg", "res/empty.png"); - this.game.load.audio("click", "res/sfx/battery.mp3"); - - this.game.load.text("invite", "res/invite.txt"); - } - create() { - this.game.add.sprite(0, 0, "bg"); - this.sfx = this.game.add.audio("click"); + this.game.stage.backgroundColor = "#001640"; + this.sfx = this.game.add.audio("sfx_battery"); let style = { font: "bold 65px monospace", fill: "#fff", boundsAlignH: "center", boundsAlignV: "middle" }; - this.textGameOver = this.game.add.text(0, 0, "ВОТ И ВСЕ", style); - this.textGameOver.setTextBounds(0, 150, this.game.width, 100); + let textGameOver = this.game.add.text(0, 0, "ВОТ И ВСЕ", style); + textGameOver.setTextBounds(0, 150, this.game.width, 100); style.font = "bold 30px monospace"; - this.textRecord = this.game.add.text(0, 0, "Камней сломалось: " + this.points, style); - this.textRecord.setTextBounds(0, 250, this.game.width, 50); + let textRecord = this.game.add.text(0, 0, "Камней сломалось: " + this.points, style); + textRecord.setTextBounds(0, 250, this.game.width, 50); - let styleoverall = { font: "20px monospace", fill: "#fff", align: "left", wordWrap: true, wordWrapWidth: this.game.width - 30 }; - let txt = this.game.cache.getText('invite'); - this.textRecord = this.game.add.text(30, 350, txt, styleoverall); + let styleTextCommonButton = { font: "21px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; - this.input.onTap.addOnce(this.titleClicked, this); + this.btnMenu = this.game.add.button(this.game.world.centerX - 140, 600, 'btn', this.GoMainMenu, this, 1, 0, 1, 0); + let textMenu = this.game.add.text(0, 0, "Я буду ROGUE ONE!", styleTextCommonButton); + textMenu.setTextBounds(0, 602, this.game.width, 50); - this.spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); - this.spaceKey.onDown.add(this.titleClicked, this); + this.btnSave = this.game.add.button(this.game.world.centerX - 140, 400, 'btn', this.SaveResult, this, 1, 0, 1, 0); + let textSave = this.game.add.text(0, 0, "Сохранить результат", styleTextCommonButton); + textSave.setTextBounds(0, 402, this.game.width, 50); } - titleClicked() { + GoMainMenu() { this.sfx.play(); this.game.state.start("TitleScreenState"); } + + SaveResult() { + if (this.points !== undefined) { + this.sfx.play(); + window['showNameBox'](this.points, this, this.GoMainMenu); + } else { + this.GoMainMenu(); + } + } }; class SimpleGame extends Phaser.State { @@ -329,31 +251,11 @@ module GameCurling { spawned: boolean; cursors: Phaser.CursorKeys; -// topLeftRect: Phaser.Rectangle; -// topRighRect: Phaser.Rectangle; -// bottomRect: Phaser.Rectangle; swipe: PhaserSwipe.Swipe; textValue: Phaser.Text; points: number; - // handle input function -/* - HandleTouchMouse(pointer) { - if (this.bottomRect.contains(pointer.x, pointer.y)) { -// this.DropRowDown(); - this.DropBlocks(); - } - - if (this.topLeftRect.contains(pointer.x, pointer.y)) { - this.ShiftRowLeft(); - } - - if (this.topRighRect.contains(pointer.x, pointer.y)) { - this.ShiftRowRight(); - } - } -*/ ShiftRowLeft() { if (this.lockInput) { return; @@ -714,30 +616,14 @@ module GameCurling { return (arr.filter((csc, idx) => { return csc.x == c.x && csc.y == c.y; }, this).length == 0); } - preload() { - this.game.load.image('b0', 'res/square_green.png'); - this.game.load.image('b1', 'res/square_blue.png'); - this.game.load.image('b2', 'res/square_red.png'); - this.game.load.image('b3', 'res/square_stone.png'); - this.game.load.image('b4', 'res/square_wood.png'); - this.game.load.image('b5', 'res/square_yellow.png'); - this.TILE_COLORS = 6; - - this.game.load.image('s0', 'res/square_any.png'); - this.game.load.image('s1', 'res/bomb.png'); - this.game.load.image('s2', 'res/line.png'); - - this.game.load.image('field', 'res/cfield.png'); - - this.game.load.audio("sfx_battery", "res/sfx/battery.mp3"); - this.game.load.audio("sfx_numkey", "res/sfx/numkey.mp3"); - this.game.load.audio("sfx_wall", "res/sfx/wall.mp3"); - this.game.load.audio("sfx_cells", "res/sfx/need_cells.mp3"); - this.game.load.audio("sfx_pistol", "res/sfx/pistol.mp3"); + GoToFinalState() { + this.game.state.start("EndGameState", true, false, this.points); } create() { // constants + this.TILE_COLORS = 6; + this.TILE_ROWS = 11; this.TILE_COLUMNS = 6; this.TILE_SIZE = 64; @@ -767,12 +653,6 @@ module GameCurling { this.swipe.swipeLeft.add(SimpleGame.prototype.ShiftRowLeft, this); this.swipe.swipeRight.add(SimpleGame.prototype.ShiftRowRight, this); -// this.topLeftRect = new Phaser.Rectangle(0, 0, this.game.width / 2, this.game.height / 2); -// this.topRighRect = new Phaser.Rectangle(this.game.width / 2 + 1, 0, this.game.width, this.game.height / 2); -// this.bottomRect = new Phaser.Rectangle(0, this.game.height / 2 + 1, this.game.width, this.game.height); - -// this.game.input.onDown.add(SimpleGame.prototype.HandleTouchMouse, this); - this.maxRow = 0; let style = { font: "bold 65px monospace", fill: "#ff0000", align: "right" }; @@ -788,46 +668,138 @@ module GameCurling { this.sfxWall = this.game.add.audio("sfx_wall"); this.sfxCells = this.game.add.audio("sfx_cells"); this.sfxPistol = this.game.add.audio("sfx_pistol"); + + this.lockInput = false; } update() { + if (this.lockInput) + return; + if (this.maxRow >= this.TILE_ROWS) { this.sfxCells.play(); // game over // play animation (remove all blocks in some way) - this.game.state.start("EndGameState", true, false, this.points); + + for (let x = 0; x < this.TILE_COLUMNS; x++) { + for (let y = 0; y < this.TILE_ROWS; y++) { + if (!this.field[x] || !this.field[x][y] || this.field[x][y].color < 0) + continue; + + let spr = this.GetSprite(this.field[x][y].key); + this.TweenSpriteAlpha(spr, null, this.GoToFinalState); + } + } + return; } - // spawn + // spawn new row if (!this.spawned) { this.GenerateTopBlocks(); this.spawned = true; } + } + } + + class PreloadAssets extends Phaser.State { + private text: Phaser.Text; + + constructor() { + super(); + } + + create() { + this.game.stage.backgroundColor = "#001640"; + + this.text = this.game.add.text(this.game.width / 2, this.game.height / 2, "Loading", { fill: '#ffffff', align: 'center' }); + + this.game.load.onFileComplete.add(this.FileComplete, this); + this.game.load.onLoadComplete.add(this.LoadComplete, this); + + // put all assets here + this.game.load.image('b0', 'res/square_green.png'); + this.game.load.image('b1', 'res/square_blue.png'); + this.game.load.image('b2', 'res/square_red.png'); + this.game.load.image('b3', 'res/square_stone.png'); + this.game.load.image('b4', 'res/square_wood.png'); + this.game.load.image('b5', 'res/square_yellow.png'); + + this.game.load.image('s0', 'res/square_any.png'); + this.game.load.image('s1', 'res/bomb.png'); + this.game.load.image('s2', 'res/line.png'); + + this.game.load.image('field', 'res/cfield.png'); + + this.game.load.audio("sfx_battery", "res/sfx/battery.mp3"); + this.game.load.audio("sfx_numkey", "res/sfx/numkey.mp3"); + this.game.load.audio("sfx_wall", "res/sfx/wall.mp3"); + this.game.load.audio("sfx_cells", "res/sfx/need_cells.mp3"); + this.game.load.audio("sfx_pistol", "res/sfx/pistol.mp3"); + this.game.load.image("title", "res/title.png"); + this.game.load.image("rules", "res/rules.png"); -// this.game.input.reset(); + this.game.load.spritesheet('btn', 'res/btn.png', 280, 50); + + this.game.load.start(); + } + + FileComplete(progress, cacheKey, success, totalLoaded, totalFiles) { + this.text.setText("Loading " + progress + "% - " + totalLoaded + " out of " + totalFiles); + } + + LoadComplete() { + this.game.state.start("TitleScreenState"); + } + } + + class ShowRulesState extends Phaser.State { + private btnBack: Phaser.Button; + + constructor() { + super(); + } + + create() { + this.game.add.sprite(0, 0, "rules"); + + let styleTextCommonButton = { font: "21px monospace", fill: "#fff", align: "center", wordWrap: false, boundsAlignH: "center", boundsAlignV: "middle" }; + + this.btnBack = this.game.add.button(this.game.world.centerX - 140, 650, 'btn', this.GoBack, this, 1, 0, 1, 0); + let textBack = this.game.add.text(0, 0, "Все понятно", styleTextCommonButton); + textBack.setTextBounds(0, 652, this.game.width, 50); + } + + GoBack() { + this.game.add.audio("sfx_battery").play(); + this.game.state.start("TitleScreenState"); + } + } + + class CurlingGame extends Phaser.Game { + constructor(width?: number | string, height?: number | string, renderer?: number, parent?: any, state?: any, transparent?: boolean, antialias?: boolean, physicsConfig?: any) { + super(width, height, renderer, parent, state, transparent, antialias, physicsConfig); } } - export class CurlingGame { - game: Phaser.Game; + export class CurlingGameLauncher { + game: CurlingGame; SCREEN_WIDTH: number = 600; SCREEN_HEIGHT: number = 800; constructor() { - let screenDims = Utils.ScreenUtils.calculateScreenMetrics( - this.SCREEN_WIDTH, this.SCREEN_HEIGHT, Utils.Orientation.PORTRAIT); - - this.game = new Phaser.Game(this.SCREEN_WIDTH, this.SCREEN_HEIGHT, Phaser.AUTO, '', { create: this.create, init: this.init }); + this.game = new CurlingGame(this.SCREEN_WIDTH, this.SCREEN_HEIGHT, Phaser.AUTO, '', { create: this.create, init: this.init }); this.game.state.add("GameRunningState", SimpleGame, false); this.game.state.add("TitleScreenState", TitleScreenState, false); this.game.state.add("EndGameState", EndGameScreenState, false); + this.game.state.add("PreloadAssets", PreloadAssets, false); + this.game.state.add("ShowRulesState", ShowRulesState, false); } init() { - this.game.input.maxPointers = 2; + this.game.input.maxPointers = 1; if (this.game.device.desktop) { this.game.scale.scaleMode = Phaser.ScaleManager.NO_SCALE; this.game.scale.pageAlignHorizontally = true; @@ -836,39 +808,15 @@ module GameCurling { } } - init2() { - this.game.input.maxPointers = 1; - this.game.stage.disableVisibilityChange = false; - - let screenDims = Utils.ScreenUtils.screenMetrics; - - if (this.game.device.desktop) { - console.log("DESKTOP"); - this.game.scale.scaleMode = Phaser.ScaleManager.NO_SCALE; -// this.game.scale.setUserScale(screenDims.scaleX, screenDims.scaleY); - this.game.scale.pageAlignHorizontally = true; -// this.game.scale.pageAlignVertically = true; - } - else { - console.log("MOBILE"); - this.game.scale.scaleMode = Phaser.ScaleManager.USER_SCALE; - this.game.scale.setUserScale(screenDims.scaleX, screenDims.scaleY); - this.game.scale.pageAlignHorizontally = true; - this.game.scale.pageAlignVertically = true; - this.game.scale.forceOrientation(true, false); - } - - console.log(screenDims); - } - create() { - this.game.state.start("TitleScreenState", true, true); + this.game.stage.backgroundColor = "#001640"; + this.game.state.start("PreloadAssets", true, true); } } } window.onload = () => { - var game = new GameCurling.CurlingGame(); + var game = new GameCurling.CurlingGameLauncher(); }; diff --git a/vs/PhaserTest001/index.html b/vs/PhaserTest001/index.html index c265c1c..273df12 100644 --- a/vs/PhaserTest001/index.html +++ b/vs/PhaserTest001/index.html @@ -4,19 +4,414 @@ - TypeScript HTML App + Все в кёрлинг! + - + + + + + + + + × + В рекорды! + + + Здесь необходимо ввести имя, что бы можно было потом узнать, кто это достиг такого результата () + + + + + + + СОХРАНИТЬ + + + + + + + + + + + + × + Рекорды + + + + + + + + + + + + + × + Ошибка! + + + Упс! Не получается подключиться к базе данных для сохранения этого выдающегося результата. Гугл подвел! + Шлите апельсины бочками, в смысле, достойные результаты скриншотами. + + + + + + + + + + + × + Ошибка! + + + Упс! Не получается подключиться к базе данных и показать самые выдающиеся результаты. Гугл подвел! + Но наверняка можно улучшить! Дерзай! Жми и играй! + + + + + + + + +
Здесь необходимо ввести имя, что бы можно было потом узнать, кто это достиг такого результата ()
Упс! Не получается подключиться к базе данных для сохранения этого выдающегося результата. Гугл подвел!
Шлите апельсины бочками, в смысле, достойные результаты скриншотами.
Упс! Не получается подключиться к базе данных и показать самые выдающиеся результаты. Гугл подвел!
Но наверняка можно улучшить! Дерзай! Жми и играй!