var LevelButton = function(t, e, s, a, i, h) { Phaser.Button.call(this, game, t, e, null, i, h), this.lvl_number = a, this.anchor.setTo(.5, .5), this.locked = !1, this.onInputDown.add(function() { game.add.tween(this.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0) }, this), this.miniature = new Phaser.Image(game, 0, 0, null), this.miniature.anchor.setTo(.5, .6), this.miniature.renderable = !1, this.addChild(this.miniature), this.stars = new Phaser.Image(game, 0, 8, null), this.stars.anchor.setTo(.5, 0), this.stars.renderable = !1, this.addChild(this.stars) }; LevelButton.prototype = Object.create(Phaser.Button.prototype), LevelButton.prototype.goToLevel = function() { if (!this.locked) { game.current_lvl = this.lvl_number; var t = game.add.tween(game.state.getCurrentState().fade_gfx).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.InOut, !0); game.lastRoom = "Category", t.onComplete.add(function() { game.state.start("Play") }) } }, LevelButton.prototype.refresh = function() { SaveLoad.unlocked_levels[game.current_category] < this.lvl_number ? (this.loadTexture("ssheet", "lvl_button_locked"), this.stars.renderable = !1, this.miniature.renderable = !1, this.locked = !0) : (this.loadTexture("ssheet", "lvl_highlight"), this.miniature.loadTexture("lvlmini", game.current_category.toString() + "_" + this.lvl_number.toString()), this.miniature.renderable = !0, this.stars.renderable = !0, this.stars.loadTexture("ssheet", "lvl_star_" + SaveLoad.level[game.current_category][this.lvl_number].toString()), this.locked = !1) }, LevelButton.prototype.constructor = LevelButton, Preload = function() {}, Preload.prototype = { preload: function() { this.cm_logo = game.add.image(210, 150, "circusmoth"), this.cm_logo.anchor.setTo(.5, .5), this.preload_bg = game.add.image(57, 250, "loading_bar_0"), this.preload_bar = game.add.image(57, 250, "loading_bar_1"), this.loading = game.add.image(210, 330, "loading"), this.loading.anchor.setTo(.5, .5), game.add.tween(this.loading.scale).to({ x: 1.2, y: 1.2 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0, 0, -1, !0), this.load.setPreloadSprite(this.preload_bar), game.load.bitmapFont("font_label", "assets/images/font_label.png", "assets/images/font_label.fnt", null, 0), game.load.bitmapFont("font_digits", "assets/images/font-digits.png", "assets/images/font-digits.fnt", null, 4), game.load.atlasJSONHash("ssheet","assets/images/spritesheet.png", "assets/images/spritesheet.json"), game.load.atlasJSONHash("lvlmini", "assets/images/lvlmini.png", "assets/images/lvlmini.json"), game.load.image("line_dbg", "assets/images/line_dbg.png"), game.load.audio("music_sfx", "assets/sounds/music.mp3"), game.load.audio("chainsaw_sfx", "assets/sounds/chainsaw_1s.mp3"), game.load.audio("chainsaw_alt_sfx", "assets/sounds/chainsaw_1s_alt.mp3"), game.load.audio("click_sfx", "assets/sounds/click.mp3"), game.load.audio("transition_sfx", "assets/sounds/transition.mp3"), game.load.audio("whoosh_sfx", "assets/sounds/whoosh.mp3"), game.load.audio("label_pop_sfx", "assets/sounds/label_pop.mp3"), game.load.audio("win_sfx", "assets/sounds/win.mp3"), game.load.audio("lose_sfx", "assets/sounds/lose.mp3") }, create: function() { this.game.stage.backgroundColor = "#FFFFFF", game.sfx = {}, game.sfx.music = game.add.audio("music_sfx", 1, !0), game.sfx.click = game.add.audio("click_sfx"), this.cm_logo.visible = !1, this.preload_bg.visible = !1, this.preload_bar.visible = !1, this.loading.visible = !1, game.sfx.chainsaw_index = 0, game.sfx.chainsaw = game.add.audio("chainsaw_sfx"), game.sfx.chainsaw_alt = game.add.audio("chainsaw_alt_sfx"), game.sfx.transition = game.add.audio("transition_sfx"), game.sfx.whoosh = game.add.audio("whoosh_sfx"), game.sfx.label_pop = game.add.audio("label_pop_sfx"), game.sfx.win = game.add.audio("win_sfx"), game.sfx.lose = game.add.audio("lose_sfx"), this.state.start("MainMenu") } }; var Slice = function(t, e) { this.point_0 = t, this.point_1 = e, this.f0t1 = !1, this.f1t0 = !1 }; Slice.prototype.checkLine = function(t) { return this.point_0.i == t ? (this.f0t1 = !0, [this.point_0, this.point_1]) : this.point_1.i == t ? (this.f1t0 = !0, [this.point_1, this.point_0]) : null }; var Shape = function(t) { Phaser.Polygon.call(this, t), this.to_kill = !1, this.dead = !1, this.slices = [], this.new_shapes = [], this.centroid = Phaser.Point.centroid(this.points) }; Shape.prototype = Object.create(Phaser.Polygon.prototype), Shape.prototype.constructor = Shape, Shape.prototype.update = function() {}, Shape.prototype.prepareSlices = function(t) { for (var e = [], s = 0; s < this.points.length; s++) { var a, i = this.points[s]; a = s == this.points.length - 1 ? this.points[0] : this.points[s + 1]; var h = Phaser.Line.intersectsPoints(t.start, t.end, i, a, !0); null != h && (h.i = s, e.push(h)) } e.sort(function(e, s) { var a = Phaser.Point.distance(t.start, e), i = Phaser.Point.distance(t.start, s); return a - i }), e.length > 0 && (this.contains(t.start.x, t.start.y) && e.splice(0, 1), this.contains(t.end.x, t.end.y) && e.splice(e.length - 1, 1)); for (var o = [], s = 0; s < e.length; s += 2) o.push(new Slice(e[s], e[s + 1])); this.slices = o }, Shape.prototype.makeNewPolygon = function(t, e) { for (var s = [t, e], a = t.i, i = e.i; i++, i == this.points.length && (i = 0), s.push(this.points[i]), i != a;) { var h = this.checkSliceLine(i); null != h && (i = h[1].i, s.push(h[0]), s.push(h[1])) } this.new_shapes.push(s) }, Shape.prototype.checkSliceLine = function(t) { for (var e = 0; e < this.slices.length; e++) { var s = this.slices[e].checkLine(t); if (null != s) return s } return null }, Shape.prototype.slice = function(t) { if (this.prepareSlices(t), 0 != this.slices.length) { this.to_kill = !0; for (var e = 0; e < this.slices.length; e++) { var s = this.slices[e]; s.f0t1 || (this.makeNewPolygon(s.point_0, s.point_1), s.f0t1 = !0), s.f1t0 || (s.f1t0 = !0, this.makeNewPolygon(s.point_1, s.point_0)) } Phaser.Point.centroid(this.points, this.centroid) } }; var Logo = function(t) { Phaser.Group.call(this, game, 0, 0), this.logo_0 = game.add.image(60, t, "ssheet", "logo_0"), this.logo_1 = game.add.image(117, t + 20, "ssheet", "logo_1"), this.logo_2 = game.add.image(172, t, "ssheet", "logo_2"), this.logo_3 = game.add.image(267, t + 5, "ssheet", "logo_3"), this.logo_4 = game.add.image(325, t, "ssheet", "logo_4"), this.logo_5 = game.add.image(382, t, "ssheet", "logo_5"), this.logo_0.anchor.setTo(.5, .5), this.logo_1.anchor.setTo(.5, .5), this.logo_2.anchor.setTo(.5, .5), this.logo_3.anchor.setTo(.5, .5), this.logo_4.anchor.setTo(.5, .5), this.logo_5.anchor.setTo(.5, .5), game.add.tween(this.logo_0).from({ y: -100 }, 1200, Phaser.Easing.Elastic.Out, !0, 1020), game.add.tween(this.logo_1).from({ y: -100 }, 1420, Phaser.Easing.Elastic.Out, !0, 1060), game.add.tween(this.logo_2).from({ y: -100 }, 1200, Phaser.Easing.Elastic.Out, !0, 1050), game.add.tween(this.logo_3).from({ y: -100 }, 1410, Phaser.Easing.Elastic.Out, !0, 1120), game.add.tween(this.logo_4).from({ y: -100 }, 1200, Phaser.Easing.Elastic.Out, !0, 1080), game.add.tween(this.logo_5).from({ y: -100 }, 1410, Phaser.Easing.Elastic.Out, !0, 1050), this.add(this.logo_0), this.add(this.logo_1), this.add(this.logo_2), this.add(this.logo_3), this.add(this.logo_4), this.add(this.logo_5), game.time.events.add(5 * Phaser.Timer.SECOND, this.init_bounce, this) }; Logo.prototype = Object.create(Phaser.Group.prototype), Logo.prototype.constructor = Logo, Logo.prototype.init_bounce = function() { game.time.events.loop(6 * Phaser.Timer.SECOND, this.bounce, this) }, Logo.prototype.bounce = function() { game.add.tween(this.logo_0).to({ y: this.logo_0.y - 30 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), game.add.tween(this.logo_1).to({ y: this.logo_0.y - 30 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 100, 0, !0), game.add.tween(this.logo_2).to({ y: this.logo_0.y - 30 }, 200, Phaser.Easing.Sinusoidal.Out, !0, 200, 0, !0), game.add.tween(this.logo_3).to({ y: this.logo_0.y - 30 }, 200, Phaser.Easing.Sinusoidal.Out, !0, 300, 0, !0), game.add.tween(this.logo_4).to({ y: this.logo_0.y - 30 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 400, 0, !0), game.add.tween(this.logo_5).to({ y: this.logo_0.y - 30 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 500, 0, !0) }; var Background = function(t) { Phaser.Sprite.call(this, game, 0, 0), this.fixedToCamera = !0, this.offset = t || 0, this.y_margin = game.height - 525, this.sky = this.game.add.image(0, 0, "ssheet", "bg"), this.sky.fixedToCamera = !0, this.sky.scale.y = (this.y_margin + 251) / 251, this.cloud = this.game.add.image(100, 50, "ssheet", "cloud_0"), this.cloud.fixedToCamera = !0, this.cloud.xx = 400, this.cloud2 = this.game.add.image(500, 70, "ssheet", "cloud_0"), this.cloud2.xx = 1e3, this.cloud2.fixedToCamera = !0, this.cloud3 = this.game.add.image(1e3, 60, "ssheet", "cloud_0"), this.cloud3.xx = 1600, this.cloud3.fixedToCamera = !0, this.grass_2 = this.game.add.tileSprite(0, this.y_margin + 200, game.width, 160, "ssheet", "bg_grass_2"), this.grass_2.fixedToCamera = !0, this.grass_2.tilePosition.set(-500, 0), this.grass_1 = this.game.add.tileSprite(0, this.y_margin + 240, game.width, 187, "ssheet", "bg_grass_1"), this.grass_1.fixedToCamera = !0, this.grass_1.tilePosition.set(-250, 0), this.grass_0 = this.game.add.tileSprite(0, this.y_margin + 310, game.width, 220, "ssheet", "bg_grass_0"), this.grass_0.fixedToCamera = !0 }; Background.prototype = Object.create(Phaser.Sprite.prototype), Background.prototype.update = function() { this.grass_2.tilePosition.set((this.game.camera.x + this.offset) * -.2, 0), this.grass_1.tilePosition.set((this.game.camera.x + this.offset) * -.5, 0), this.grass_0.tilePosition.set((this.game.camera.x + this.offset) * -.8, 0), this.cloud.cameraOffset.x = this.cloud.xx - .2 * this.game.camera.x, this.cloud.xx -= .2, this.cloud2.cameraOffset.x = this.cloud2.xx - .2 * this.game.camera.x, this.cloud2.xx -= .2, this.cloud3.cameraOffset.x = this.cloud2.xx - .2 * this.game.camera.x, this.cloud3.xx -= .2, this.cloud.xx < -200 && (this.cloud.xx = 1500), this.cloud2.xx < -200 && (this.cloud2.xx = 1500), this.cloud3.xx < -200 && (this.cloud3.xx = 1500) }, Background.prototype.destroyBg = function() { this.sky.destroy(), this.grass_2.destroy(), this.grass_1.destroy(), this.grass_0.destroy(), this.destroy() }, Background.prototype.rescale = function() { this.y_margin = game.height - 525, this.sky.scale.y = (this.y_margin + 251) / 251, this.grass_2.cameraOffset.y = this.y_margin + 200, this.grass_1.cameraOffset.y = this.y_margin + 240, this.grass_0.cameraOffset.y = this.y_margin + 310 }; var Tutorial = function() { Phaser.Group.call(this, game), this.y = 150, this.bg = game.add.image(-100, 125, "ssheet", "tut_bg"), this.bg.anchor.setTo(0, .5), this.addChild(this.bg), this.game.add.tween(this).from({ x: -750 }, 1500, Phaser.Easing.Elastic.InOut, !0, 0), game.time.events.add(300, function() { SaveLoad.SFX && game.sfx.whoosh.play() }, this), this.current_page = 0, this.page_1 = game.add.group(), this.addChild(this.page_1), this.title = game.add.image(210, 20, "ssheet", "tut_title"), this.title.anchor.setTo(.5, 0), this.page_1.addChild(this.title), this.shape_w = game.add.image(210, 125, "ssheet", "tut_shape_w"), this.shape_w.anchor.setTo(.5, .5), this.page_1.addChild(this.shape_w), this.shape_bottom = game.add.image(210, 125, "ssheet", "tut_shape_bottom"), this.shape_bottom.anchor.setTo(.5, .5), this.shape_bottom.visible = !1, this.page_1.addChild(this.shape_bottom), this.shape_top = game.add.image(210, 125, "ssheet", "tut_shape_top"), this.shape_top.anchor.setTo(.5, .5), this.shape_top.visible = !1, this.page_1.addChild(this.shape_top), this.slice = game.add.image(100, 160, "ssheet", "tut_slice"), this.slice.anchor.setTo(0, .5), this.slice.width = 0, this.slice.rotation = -.12435499454676144, this.page_1.addChild(this.slice), this.click_dot = game.add.image(100, 160, "ssheet", "tut_click_dot"), this.click_dot.scale.setTo(1.2, 1.2), this.click_dot.alpha = 0, this.click_dot.anchor.setTo(.5, .5), this.page_1.addChild(this.click_dot), this.hand = game.add.image(100, 160, "ssheet", "tut_hand"), this.page_1.addChild(this.hand), this.page_2 = game.add.image(210, 20, "ssheet", "tut_page2"), this.page_2.alpha = 0, this.page_2.anchor.setTo(.5, 0), this.addChild(this.page_2), game.time.events.add(2e3, function() { this.resetAnimation() }, this), console.log("TUTORIAL"), console.log(this) }; Tutorial.prototype = Object.create(Phaser.Group.prototype), Tutorial.prototype.constructor = Tutorial, Tutorial.prototype.update = function() { this.y = .28 * game.height }, Tutorial.prototype.resetAnimation = function() { this.shape_top.visible = !1, this.shape_top.y = 125, this.shape_bottom.y = 125, this.shape_bottom.visible = !1, this.shape_w.visible = !0, this.hand.x = 100, this.hand.y = 160, this.slice.width = 0, game.add.tween(this.hand).to({ x: 300, y: 135 }, 2e3, Phaser.Easing.Sinusoidal.InOut, !0, 0), game.add.tween(this.click_dot.scale).to({ x: .5, y: .5 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0), game.add.tween(this.click_dot).to({ alpha: .5 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0), game.add.tween(this.click_dot).to({ x: 300, y: 135 }, 2e3, Phaser.Easing.Sinusoidal.InOut, !0, 0), SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.slice).to({ width: 202 }, 2e3, Phaser.Easing.Sinusoidal.InOut, !0, 0), game.add.tween(this.slice).to({ alpha: 0 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 2500), game.time.events.add(2500, function() { SaveLoad.SFX && game.sfx.label_pop.play(), this.shape_top.visible = !0, this.shape_bottom.visible = !0, this.shape_w.visible = !1, game.add.tween(this.click_dot.scale).to({ x: 1.2, y: 1.2 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0), game.add.tween(this.click_dot).to({ alpha: 0 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0) }, this), game.add.tween(this.shape_bottom).to({ y: 140 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 2500), game.add.tween(this.shape_top).to({ y: 110 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 2500), game.add.tween(this.page_2).to({ alpha: 1 }, 500, Phaser.Easing.Sinusoidal.InOut, !0, 4500), game.add.tween(this.page_1).to({ alpha: 0 }, 500, Phaser.Easing.Sinusoidal.InOut, !0, 4200), game.add.tween(this).to({ x: 750 }, 1500, Phaser.Easing.Elastic.InOut, !0, 8500), game.time.events.add(8800, function() { SaveLoad.SFX && game.sfx.whoosh.play() }, this) }; var CategoryButton = function(t, e, s, a, i, h) { function o() { this.unlocked && (SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), game.current_category = this.category, game.add.tween(game.camera).to({ x: 840 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0)) } Phaser.Button.call(this, game, t, e, ""), this.onInputDown.add(o, this, 1), this.anchor.setTo(.5, .5), this.category = s, this.fill = new Phaser.Image(game, 0, 0, null), this.fill.anchor.setTo(.5, .5), this.addChild(this.fill), this.unlocked = !1, SaveLoad.all_stars < a ? (this.fill.loadTexture("ssheet", i), this.reqStar = new Phaser.BitmapText(game, -115, 20, "font_digits", a.toString(), 25), this.reqStar.anchor.setTo(1, 0), this.underline = new Phaser.Image(game, .5 * (this.reqStar.width + 47 + 153) - 165, 15, "ssheet", "to_unlock"), this.star_ico = new Phaser.Image(game, this.underline.x + 28, 17, "ssheet", "small_star"), this.star_ico.anchor.setTo(1, 0), this.reqStar.x = this.star_ico.x - 38, this.addChild(this.underline), this.addChild(this.reqStar), this.addChild(this.star_ico)) : (this.unlocked = !0, this.fill.loadTexture("ssheet", h), maxStars = 54, this.stars = new Phaser.BitmapText(game, 18, 20, "font_digits", SaveLoad.star[s] + "/" + maxStars, 25), this.stars.anchor.setTo(1, 0), this.stars.x = this.stars.width - .5 * (this.stars.width + 47) + 5, this.star_ico = new Phaser.Image(game, this.stars.x - 5, 17, "ssheet", "small_star"), this.addChild(this.stars), this.addChild(this.star_ico)) }; CategoryButton.prototype = Object.create(Phaser.Button.prototype), CategoryButton.prototype.constructor = CategoryButton; var TurnDevice = function() { Phaser.Group.call(this, game), this.fixedToCamera = !0, this.bg = game.add.graphics(0, 0), this.bg.beginFill("#000000", 1), this.bg.drawRect(0, 0, 420, 1500), this.bg.endFill(), this.add(this.bg), this.please_turn = game.add.image(210, .5 * game.height, "ssheet", "turn_device"), this.please_turn.anchor.setTo(.5, .5), this.please_turn.scale.setTo(2, 2), this.add(this.please_turn) }; TurnDevice.prototype = Object.create(Phaser.Group.prototype), TurnDevice.prototype.constructor = TurnDevice, TurnDevice.prototype.show = function() { this.visible = !0, this.please_turn.y = .5 * game.height }, TurnDevice.prototype.hide = function() { this.visible = !1 }, TurnDevice.prototype.test = function() { game.scale.isLandscape ? this.hide() : this.hide() }, MainMenu = function() {}, MainMenu.prototype = { create: function() { game.sfx.music.isPlaying || game.sfx.music.play(), SaveLoad.SFX || game.sfx.music.stop(), game.world.setBounds(0, 0, 4 * game.width, game.height), this.bg = new Background, game.add.existing(this.bg), this.sun_flare = game.add.image(210, 140, "ssheet", "sun"), this.sun_flare.anchor.setTo(.5, .5), game.add.tween(this.sun_flare).to({ angle: 359 }, 15e3, Phaser.Easing.Linear.InOut, !0, 0, -1), this.logo = new Logo(140), game.add.existing(this.logo), this.chainsaw = game.add.image(210, .8 * game.height, "ssheet", "chainsaw_play"), this.chainsaw.anchor.setTo(.5, .5), this.play_button = game.add.button(210, .8 * game.height, null, this.play_button_click, this), this.play_button.loadTexture("ssheet", "play"), this.play_button.anchor.setTo(.5, .5), this.play_button.onInputDown.add(function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.play_button.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0) }, this), this.page_1 = game.add.group(), this.page_1.add(this.play_button), this.categories = game.add.group(), this.categories.y = .19 * game.height, this.categories.add(new CategoryButton(630, -25, 0, 0, "very_easy_0", "very_easy_1")), this.categories.add(new CategoryButton(630, 75, 1, 30, "easy_0", "easy_1")), this.categories.add(new CategoryButton(630, 175, 2, 60, "medium_0", "medium_1")), this.categories.add(new CategoryButton(630, 275, 3, 90, "hard_0", "hard_1")), this.categories.forEach(function(t) { t.onInputDown.add(this.refresh_buttons, this, -1) }, this), this.page_1.add(this.categories), this.UI_buttons = game.add.group(), this.UI_buttons.y = .92 * game.height, this.back_button = game.add.button(470, 0, null, this.back_button_click, this), this.back_button.anchor.setTo(.5, .5), this.back_button.onInputDown.add(function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.back_button.scale).to({ x: -1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0) }, this), this.back_button.loadTexture("ssheet", "arrow_button"), this.back_button.scale.x = -1, this.UI_buttons.add(this.back_button), this.lvl_buttons = game.add.group(), this.lvl_row = [], this.lvl_row[0] = game.add.group(), this.lvl_row[1] = game.add.group(), this.lvl_row[2] = game.add.group(), this.lvl_row[0].y = .17 * game.height, this.lvl_row[1].y = .41 * game.height, this.lvl_row[2].y = .64 * game.height, this.lvl_buttons.add(this.lvl_row[0]), this.lvl_buttons.add(this.lvl_row[1]), this.lvl_buttons.add(this.lvl_row[2]); for (var t = 0; 9 > t; t++) this.lvl_row[Math.floor(t / 3)].add(new LevelButton(930 + t % 3 * 120, 0, game.current_category, t, this.goToLevel)); for (var t = 9; 18 > t; t++) this.lvl_row[Math.floor((t - 9) / 3)].add(new LevelButton(1260 + (90 + t % 3 * 120), 0, game.current_category, t, this.goToLevel)); this.back_to_cat = game.add.button(890, 0, null, function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.back_to_cat.scale).to({ x: -1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), game.add.tween(game.camera).to({ x: 420 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0) }, this), this.back_to_cat.scale.x = -1, this.back_to_cat.loadTexture("ssheet", "arrow_button"), this.back_to_cat.anchor.setTo(.5, .5), this.UI_buttons.add(this.back_to_cat), this.next_lvl = game.add.button(1210, 0, null, function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.next_lvl.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), game.add.tween(game.camera).to({ x: 1260 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0) }, this), this.next_lvl.loadTexture("ssheet", "arrow_button"), this.next_lvl.anchor.setTo(.5, .5), this.UI_buttons.add(this.next_lvl), this.prev_lvl = game.add.button(1310, 0, null, function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.prev_lvl.scale).to({ x: -1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), game.add.tween(game.camera).to({ x: 840 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0) }, this), this.prev_lvl.scale.x = -1, this.prev_lvl.loadTexture("ssheet", "arrow_button"), this.prev_lvl.anchor.setTo(.5, .5), this.UI_buttons.add(this.prev_lvl), this.refresh_buttons(), this.tb_music = game.add.button(0, 0, null, this.tb_music_click, this), this.tb_music.anchor.setTo(0, 0), this.tb_music.fixedToCamera = !0, this.tb_music.loadTexture("ssheet", "music_button"), SaveLoad.SFX || (this.tb_music.alpha = .5), this.fade_gfx = game.add.graphics(0, 0), this.fade_gfx.beginFill(16777215, 1), this.fade_gfx.drawRect(0, 0, game.width, game.height), this.fade_gfx.endFill(), this.fade_gfx.fixedToCamera = !0, "Play" == game.lastRoom && (game.current_lvl < 10 && (game.camera.x = 840), game.current_lvl > 9 && (game.camera.x = 1260)), game.add.tween(this.fade_gfx).to({ alpha: 0 }, 300, Phaser.Easing.Sinusoidal.Out, !0), game.camera.x < 100 && game.time.events.add(500, function() { SaveLoad.SFX && game.sfx.whoosh.play() }, this), this.scale.onSizeChange.add(this.resize_layout, this), game.device.desktop || (this.turndevice = new TurnDevice, game.add.existing(this.turndevice), this.turndevice.test()) }, update: function() {}, resize_layout: function() { this.categories.y = .19 * game.height, this.bg.rescale(), this.lvl_row[0].y = .17 * game.height, this.lvl_row[1].y = .41 * game.height, this.lvl_row[2].y = .64 * game.height, this.play_button.y = .8 * game.height, this.chainsaw.y = this.play_button.y, this.UI_buttons.y = .92 * game.height, game.device.desktop || this.turndevice.test() }, tb_info_click: function() {}, tb_music_click: function() { SaveLoad.SFX ? (game.add.tween(this.tb_music).to({ alpha: .5 }, 300, Phaser.Easing.Sinusoidal.InOut, !0), game.sfx.music.stop(), SaveLoad.SFX = !1, SaveLoad.saveSFX()) : (game.add.tween(this.tb_music).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.InOut, !0), SaveLoad.SFX = !0, SaveLoad.saveSFX(), game.sfx.music.play("", 0, 1, !0)) }, play_button_click: function() { game.add.tween(game.camera).to({ x: 420 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0) }, back_button_click: function() { game.add.tween(game.camera).to({ x: 0 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0) }, refresh_buttons: function() { this.lvl_row.forEach(function(t) { t.forEach(function(t) { t.refresh() }) }) }, goToLevel: function() { if (!this.locked) { SaveLoad.SFX && (game.sfx.transition.play(), game.sfx.click.play()), game.current_lvl = this.lvl_number; var t = game.add.tween(game.state.getCurrentState().fade_gfx).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.InOut, !0); game.lastRoom = "Category", t.onComplete.add(function() { game.state.start("Play") }) } }, shutdown: function() { this.bg.destroyBg(), this.tb_music.destroy(), this.page_1.destroy(), this.back_button.destroy() } }, Boot = function() {}, Boot.prototype = { preload: function() { this.load.image("circusmoth", "assets/images/circusmoth.png"), this.load.image("loading", "assets/images/loading.png"), this.load.image("loading_bar_0", "assets/images/loading_bar_0.png"), this.load.image("loading_bar_1", "assets/images/loading_bar_1.png"), game.time.advancedTiming = !0 }, create: function() { this.game.stage.backgroundColor = "#000000", game.current_category = 0, game.current_lvl = 0, game.lastRoom = null, this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL, this.scale.pageAlignHorizontally = !0, this.scale.setScreenSize(!0), this.game.scale.setResizeCallback(scaleGameSizeUpdate, this.game), game.main_menu_screen = 0, game.time.events.add(1e3, function() { SaveLoad.loadSave(), this.state.start("Preload") }, this) } }; var scaleGameSizeUpdate = function() { var t = window.innerHeight / window.innerWidth; 420 * t > 525 ? this.scale.setGameSize(420, Math.floor(420 * t)) : this.scale.setGameSize(420, 525) }; SaveLoad = {}, SaveLoad.loadSave = function() { this.unlocked_levels = [], this.star = [0, 0, 0, 0], this.unlocked_levels[0] = 0, this.unlocked_levels[1] = 0, this.unlocked_levels[2] = 0, this.unlocked_levels[3] = 0, this.all_stars = 0; try { this.level = window.localStorage.getItem("cutit_level") } catch (t) { console.log("CAN'T ACCESS localStorage"), this.level = null } if (null == this.level) { this.level = [ [], [], [], [] ]; for (var e = 0; 4 > e; e++) for (var s = 0; 18 > s; s++) this.level[e][s] = 0 } else { if (this.level = JSON.parse(this.level), !Array.isArray(this.level)) for (var e = 0; 4 > e; e++) for (var s = 0; 18 > s; s++) this.level[e][s] = 0; for (var e = 0; 4 > e; e++) for (var s = 0; 18 > s; s++) this.level[e][s] > 0 && (this.unlocked_levels[e]++, this.star[e] += this.level[e][s]); this.all_stars = this.star[0] + this.star[1] + this.star[2] + this.star[3] } try { this.SFX = window.localStorage.getItem("SFX") } catch (t) { console.log("CAN'T ACCESS localStorage"), this.SFX = null } this.SFX = null == this.SFX ? !0 : "true" == this.SFX ? !0 : !1 }, SaveLoad.saveSFX = function() { try { window.localStorage.setItem("SFX", this.SFX) } catch (t) { console.log("CAN'T ACCESS localStorage") } }, SaveLoad.savePassLevel = function(t, e, s) { if (this.level[t][e] < s) { this.all_stars += s - this.level[t][e], this.star[t] += s - this.level[t][e], 0 == this.level[t][e] && this.unlocked_levels[t]++, this.level[t][e] = s; try { window.localStorage.setItem("cutit_level", JSON.stringify(this.level)) } catch (a) { console.log("CAN'T ACCESS localStorage") } return !0 } return !1 }, Level = [ [ [ [2, 4], [128, 164, 128, 324, 288, 324, 288, 164] ], [ [2, 6], [112, 148, 112, 340, 176, 340, 176, 148], [240, 148, 240, 340, 304, 340, 304, 148] ], [ [3, 4], [64, 356, 352, 356, 208, 132] ], [ [2, 4], [112, 148, 112, 276, 176, 276, 176, 340, 304, 340, 304, 212, 240, 212, 240, 148] ], [ [2, 3], [80, 212, 80, 340, 144, 340, 144, 276, 272, 276, 272, 212, 336, 212, 336, 148, 208, 148, 208, 212] ], [ [3, 4], [96, 148, 96, 212, 224, 212, 224, 276, 160, 276, 160, 340, 288, 340, 352, 276, 288, 276, 288, 212, 224, 148] ], [ [3, 6], [72, 156, 128, 212, 184, 212, 184, 268, 128, 268, 72, 324, 352, 324, 296, 268, 240, 268, 240, 212, 296, 212, 352, 156] ], [ [2, 3], [184, 156, 72, 268, 128, 268, 184, 324, 296, 324, 352, 268, 296, 268, 296, 212, 240, 212] ], [ [3, 4], [144, 180, 80, 244, 80, 308, 144, 308, 144, 244, 272, 244, 272, 308, 336, 308, 336, 244, 272, 180] ], [ [2, 3], [144, 324, 312, 324, 144, 156] ], [ [2, 4], [176, 172, 104, 316, 248, 316, 320, 172] ], [ [5, 6], [96, 220, 96, 316, 336, 316, 336, 220, 288, 220, 288, 268, 240, 268, 240, 172, 192, 172, 192, 268, 144, 268, 144, 220] ], [ [3, 6], [128, 164, 128, 324, 288, 324, 288, 164] ], [ [1, 3], [64, 172, 64, 284, 120, 340, 288, 340, 344, 284, 344, 172, 232, 172, 232, 284, 176, 284, 176, 172] ], [ [2, 3], [184, 148, 120, 212, 120, 276, 184, 340, 248, 340, 312, 276, 312, 212, 248, 148, 248, 212, 184, 212] ], [ [3, 6], [136, 148, 184, 196, 88, 196, 136, 244, 136, 292, 232, 292, 232, 340, 328, 340, 328, 244, 232, 148] ], [ [2, 3], [72, 332, 352, 332, 352, 276, 296, 276, 296, 220, 240, 220, 240, 164, 184, 164, 128, 220, 128, 276] ], [ [3, 5], [104, 212, 104, 324, 328, 324, 272, 268, 272, 156, 160, 156, 160, 212, 216, 212, 216, 268, 160, 268, 160, 212] ] ], [ [ [3, 4], [80, 148, 80, 340, 336, 340, 336, 148, 272, 212, 208, 148, 144, 212] ], [ [2, 4], [112, 140, 112, 220, 152, 220, 152, 260, 112, 260, 112, 340, 312, 340, 312, 260, 272, 260, 272, 220, 312, 220, 312, 140, 232, 140, 232, 260, 192, 260, 192, 140] ], [ [2, 3], [88, 148, 88, 276, 152, 276, 152, 340, 280, 340, 280, 212, 344, 212, 344, 148] ], [ [2, 3], [88, 212, 88, 340, 216, 340, 152, 276, 280, 276, 344, 212, 344, 148, 280, 148, 280, 212] ], [ [3, 4], [192, 148, 192, 196, 144, 196, 144, 244, 192, 244, 192, 340, 288, 340, 288, 292, 240, 292, 240, 148] ], [ [3, 6], [136, 300, 176, 340, 256, 340, 296, 300, 256, 300, 256, 180, 216, 180, 216, 140, 176, 140, 176, 260, 216, 260, 216, 300] ], [ [4, 5], [272, 140, 152, 140, 152, 340, 272, 340, 272, 300, 192, 300, 192, 260, 232, 260, 232, 220, 192, 220, 192, 180, 272, 180] ], [ [3, 4], [104, 156, 104, 268, 160, 324, 216, 324, 216, 268, 272, 324, 328, 324, 328, 156, 272, 156, 272, 268, 216, 212, 160, 268, 160, 156] ], [ [2, 4], [64, 156, 64, 252, 112, 300, 304, 300, 304, 348, 352, 348, 352, 252, 304, 252, 208, 156, 160, 156, 160, 204, 112, 204] ], [ [2, 4], [160, 132, 216, 188, 216, 244, 160, 244, 104, 188, 104, 300, 160, 300, 160, 356, 216, 300, 272, 356, 272, 300, 328, 300, 328, 244, 272, 244, 272, 132] ], [ [2, 4], [152, 188, 152, 244, 96, 244, 152, 300, 152, 356, 208, 356, 208, 244, 264, 244, 320, 300, 320, 244, 264, 188, 264, 132, 208, 188] ], [ [2, 4], [96, 244, 96, 292, 240, 292, 240, 340, 288, 340, 288, 292, 336, 292, 336, 148, 288, 196, 240, 148, 192, 148, 192, 196, 144, 196, 144, 244] ], [ [3, 4], [152, 132, 152, 244, 96, 244, 96, 300, 152, 300, 152, 356, 208, 356, 208, 300, 264, 244, 208, 244, 208, 188, 264, 188, 320, 244, 320, 132] ], [ [3, 4], [160, 148, 160, 180, 128, 180, 128, 212, 160, 212, 160, 244, 128, 244, 128, 340, 160, 340, 192, 308, 160, 308, 160, 276, 192, 276, 192, 212, 224, 212, 224, 244, 256, 244, 256, 276, 288, 276, 320, 244, 288, 244, 288, 212, 256, 212, 256, 180, 192, 180, 192, 148] ], [ [2, 4], [264, 148, 216, 148, 168, 196, 120, 196, 120, 292, 168, 292, 168, 340, 216, 292, 264, 340, 312, 340, 264, 292, 312, 244, 264, 196] ], [ [2, 4], [280, 148, 160, 148, 120, 188, 120, 228, 160, 268, 120, 308, 160, 308, 200, 348, 200, 308, 280, 308, 320, 268, 320, 228, 280, 268, 200, 268, 160, 228, 200, 188, 240, 188, 280, 228, 320, 188, 280, 188] ], [ [2, 3], [208, 196, 112, 292, 112, 340, 160, 292, 208, 292, 256, 340, 256, 292, 304, 292, 304, 148, 256, 196] ], [ [2, 3], [72, 236, 112, 236, 112, 316, 352, 316, 352, 236, 312, 276, 312, 236, 272, 236, 272, 276, 232, 236, 192, 236, 152, 196, 112, 156, 72, 196] ] ], [ [ [3, 4], [64, 228, 64, 324, 96, 356, 320, 356, 352, 324, 352, 228, 320, 228, 320, 164, 288, 164, 288, 228, 256, 228, 256, 132, 224, 132, 224, 228, 192, 228, 192, 164, 160, 164, 160, 228, 128, 228, 128, 132, 96, 132, 96, 228] ], [ [3, 6], [128, 132, 64, 196, 128, 356, 160, 260, 192, 324, 224, 324, 256, 260, 288, 356, 352, 196, 288, 132] ], [ [2, 4], [64, 132, 64, 228, 96, 228, 96, 292, 160, 292, 160, 356, 256, 356, 256, 292, 352, 292, 352, 196, 288, 196, 288, 132, 192, 132, 192, 196, 160, 196, 160, 132] ], [ [3, 6], [64, 260, 96, 260, 96, 164, 160, 164, 160, 228, 192, 228, 192, 196, 224, 196, 224, 132, 288, 132, 288, 196, 320, 196, 320, 228, 352, 228, 352, 356, 64, 356] ], [ [4, 5], [192, 132, 64, 196, 64, 292, 160, 356, 224, 292, 320, 292, 352, 196, 320, 132, 288, 132, 288, 196, 224, 196, 224, 260, 160, 260, 160, 196, 192, 196, 192, 164, 224, 164, 224, 132] ], [ [2, 3], [64, 292, 128, 292, 128, 324, 160, 356, 256, 356, 288, 324, 288, 292, 352, 292, 288, 196, 256, 228, 224, 132, 192, 132, 160, 228, 128, 196] ], [ [2, 3], [64, 260, 160, 260, 160, 356, 256, 356, 256, 260, 352, 260, 352, 132, 64, 132] ], [ [3, 5], [64, 260, 64, 356, 352, 356, 352, 132, 288, 228, 256, 164, 224, 196, 192, 164, 160, 196, 128, 132, 96, 196, 96, 260, 64, 228] ], [ [3, 4], [64, 260, 192, 356, 224, 292, 288, 356, 352, 292, 352, 196, 288, 164, 256, 196, 224, 132, 128, 132, 160, 196, 96, 164] ], [ [3, 6], [128, 132, 64, 196, 64, 292, 128, 356, 288, 356, 352, 292, 352, 196, 288, 132] ], [ [4, 5], [352, 196, 256, 132, 160, 132, 64, 196, 64, 292, 160, 356, 288, 356, 352, 292, 224, 260] ], [ [3, 4], [64, 356, 352, 356, 352, 260, 288, 292, 256, 132, 160, 228, 128, 132, 96, 292, 64, 260] ], [ [3, 4], [320, 132, 192, 132, 256, 196, 160, 196, 128, 132, 64, 196, 96, 260, 128, 228, 160, 292, 96, 292, 160, 356, 224, 292, 288, 356, 352, 292, 288, 260, 352, 196] ], [ [4, 5], [192, 132, 128, 228, 64, 260, 96, 356, 192, 356, 192, 324, 224, 324, 224, 356, 320, 356, 352, 260, 288, 228] ], [ [2, 4], [64, 292, 64, 356, 352, 356, 352, 292, 320, 324, 256, 324, 256, 260, 320, 228, 352, 196, 320, 164, 256, 132, 160, 132, 96, 164, 64, 196, 96, 228, 160, 260, 160, 324, 96, 324] ], [ [3, 4], [64, 132, 64, 356, 192, 356, 192, 292, 256, 356, 320, 356, 192, 228, 256, 228, 352, 292, 352, 164, 288, 132] ], [ [3, 6], [160, 132, 64, 228, 64, 292, 160, 356, 288, 356, 352, 260, 320, 164, 256, 132] ], [ [4, 5], [192, 132, 64, 132, 64, 292, 192, 292, 192, 356, 256, 356, 288, 324, 320, 356, 352, 356, 352, 228, 320, 228, 320, 292, 288, 260, 256, 292, 224, 292, 224, 228, 192, 228, 192, 260, 96, 260, 96, 228, 160, 228, 160, 196, 96, 196, 96, 164, 192, 164] ] ], [ [ [2, 4], [64, 260, 352, 356, 256, 132] ], [ [2, 3], [64, 196, 128, 356, 224, 228, 256, 356, 352, 196, 256, 132, 160, 196, 128, 164] ], [ [2, 4], [64, 228, 128, 324, 256, 324, 288, 356, 320, 356, 352, 260, 288, 164, 192, 196, 128, 164] ], [ [5, 6], [96, 132, 64, 164, 96, 196, 96, 292, 64, 324, 96, 356, 128, 324, 128, 228, 160, 228, 160, 260, 192, 292, 224, 292, 256, 260, 256, 228, 288, 228, 288, 324, 320, 356, 352, 324, 320, 292, 320, 196, 352, 164, 320, 132, 288, 164, 256, 164, 224, 196, 192, 196, 160, 164, 128, 164] ], [ [3, 5], [64, 356, 352, 356, 256, 132, 160, 132] ], [ [4, 5], [96, 292, 192, 324, 224, 228, 288, 324, 288, 356, 352, 356, 320, 132, 160, 132, 160, 196, 64, 196] ], [ [2, 4], [64, 228, 64, 260, 96, 292, 128, 292, 128, 324, 160, 324, 192, 324, 192, 356, 288, 356, 352, 324, 352, 196, 288, 196, 288, 260, 224, 260, 224, 164, 256, 164, 224, 132, 128, 132, 96, 164] ], [ [3, 6], [64, 196, 64, 260, 128, 324, 192, 324, 224, 292, 288, 356, 352, 356, 352, 260, 288, 228, 288, 164, 192, 132, 128, 132] ], [ [2, 4], [64, 356, 352, 356, 320, 324, 320, 292, 288, 292, 288, 196, 320, 196, 320, 164, 288, 132, 224, 132, 192, 164, 192, 196, 224, 196, 224, 260, 192, 292, 160, 260, 128, 260, 128, 292, 96, 324, 64, 292] ], [ [2, 6], [64, 132, 160, 356, 192, 196, 160, 164, 128, 132], [256, 132, 224, 228, 320, 356, 352, 228] ], [ [2, 4], [128, 132, 160, 228, 64, 260, 160, 292, 160, 356, 224, 292, 320, 356, 288, 292, 352, 196, 256, 228, 288, 132, 224, 196] ], [ [3, 6], [96, 132, 64, 260, 256, 356, 352, 260, 288, 228, 288, 132, 224, 164, 160, 164] ], [ [3, 5], [64, 356, 352, 356, 256, 228, 352, 164, 224, 164, 256, 132, 160, 132, 192, 164, 64, 164, 160, 228] ], [ [4, 6], [192, 132, 160, 228, 96, 132, 64, 260, 128, 356, 192, 324, 256, 324, 352, 260, 320, 164, 256, 228, 256, 132] ], [ [3, 4], [320, 196, 128, 132, 64, 196, 128, 324, 192, 324, 160, 228, 288, 324, 352, 356, 352, 260, 256, 228] ], [ [3, 4], [64, 228, 64, 292, 192, 356, 192, 260, 320, 324, 320, 228, 352, 260, 352, 132, 256, 164, 256, 196, 192, 164, 128, 196, 128, 228, 96, 196] ], [ [3, 6], [128, 132, 64, 196, 64, 260, 128, 292, 128, 324, 160, 324, 160, 356, 288, 356, 288, 324, 320, 292, 352, 260, 352, 164, 320, 132] ], [ [3, 5], [96, 132, 64, 260, 192, 324, 192, 356, 288, 324, 352, 196, 256, 164, 192, 196, 192, 132] ] ] ], Play = function() {}, Play.prototype = { create: function() { this.bg = new Background, game.add.existing(this.bg), this.sun_flare = game.add.image(350, 40, "ssheet", "sun"), this.sun_flare.scale.setTo(1.5, 1.5), this.sun_flare.anchor.setTo(.5, .5), game.add.tween(this.sun_flare).to({ angle: 359.9 }, 3e4, Phaser.Easing.Linear.InOut, !0, 0, -1), this.prime_shape = [], this.shapes = []; for (var t = 1; t < Level[game.current_category][game.current_lvl].length; t++) this.shapes[this.shapes.length] = new Shape(Level[game.current_category][game.current_lvl][t]), this.prime_shape[this.shapes.length - 1] = new Shape(Level[game.current_category][game.current_lvl][t]); this.wood = game.add.group(), this.wood.x = 210, this.wood_texture = game.add.image(0, 0, "ssheet", "wood_bg"), this.wood_texture.anchor.setTo(.5, 0), this.wood_shape = game.add.graphics(0, 0), this.shapes.forEach(function(t) { this.wood_shape.beginFill(16711731, 1), this.wood_shape.drawPolygon(t.points), this.wood_shape.endFill() }, this), this.wood_shape.x = -210, this.wood_texture.mask = this.wood_shape, this.graphics = game.add.graphics(0, 0), this.bitmapka = game.add.bitmapData(game.width, game.height), bitmap_test = this.bitmapka, this.bitmapka_img = this.bitmapka.addToWorld(), this.bitmapka_img.anchor.setTo(.5, 0), this.wood.add(this.wood_texture), this.wood.add(this.wood_shape), this.wood.add(this.bitmapka_img), this.drawAllShapes(), this.cuts_left = Level[game.current_category][game.current_lvl][0][0], this.cuts_start = Level[game.current_category][game.current_lvl][0][0], this.shapes_goal = Level[game.current_category][game.current_lvl][0][1], this.cut_line = game.add.tileSprite(0, 0, 0, 32, "ssheet", "cut_line_hl_line"), this.cut_line.line = game.add.tileSprite(0, 0, 0, 3, "ssheet", "cut_line"), this.cut_line.addChild(this.cut_line.line), this.cut_line.line.anchor.setTo(0, .5), this.cut_line.end1 = game.add.image(0, 0, "ssheet", "cut_line_hl_end"), this.cut_line.end1.anchor.setTo(.5, .5), this.cut_line.addChild(this.cut_line.end1), this.cut_line.end2 = game.add.image(0, 0, "ssheet", "cut_line_hl_end"), this.cut_line.end2.anchor.setTo(.5, .5), this.cut_line.addChild(this.cut_line.end2), this.cut_line.anchor.setTo(0, .5), this.cut_line.visible = !1, this.cut_line.update = function() { this.visible && (this.rotation = game.math.angleBetween(this.x, this.y, game.input.x, game.input.y), this.width = game.math.distance(this.x, this.y, game.input.x, game.input.y), this.line.width = this.width, this.end2.angle = 180, this.end2.x = this.width) }, this.input.onDown.add(this.startCut, this), this.input.onUp.add(this.endCut, this), this.cuts_txt_label = game.add.image(130, 10, "ssheet", "cuts_ico"), this.cuts_txt = game.add.bitmapText(220, 20, "font_digits", "x" + this.cuts_left.toString(), 25), this.shapes_txt_label = game.add.image(280, 10, "ssheet", "pieces_ico"), this.shapes_txt = game.add.bitmapText(405, 20, "font_digits", this.shapes.length + "/" + this.shapes_goal, 25), this.shapes_txt.anchor.setTo(1, 0), this.slice_line_line = game.add.image(0, 0, "ssheet", "slice_line"), this.slice_line_line.anchor.setTo(0, .5), this.slice_line_line.alpha = 0, this.slice_line = game.add.image(0, 0, "ssheet", "cut_chinesaw"), this.slice_line.anchor.setTo(.16, .5), this.slice_line.visible = !1, this.labels = game.add.group(), this.labels.x = -210, this.wood.add(this.labels), this.result = game.add.group(), this.result.x = -420, this.result.y = .58 * game.height, this.low_buttons = game.add.group(), this.low_buttons.y = .92 * game.height, this.restart = game.add.button(210, 0, null, this.restart_level, this), this.restart.loadTexture("ssheet", "restart_button"), this.restart.anchor.setTo(.5, .5), this.restart.onInputDown.add(function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.restart.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0) }, this), this.low_buttons.add(this.restart), this.back_to_cat = game.add.button(60, 0, null, this.tb_exit_click, this), this.back_to_cat.loadTexture("ssheet", "menu_button"), this.back_to_cat.anchor.setTo(.5, .5), this.back_to_cat.onInputDown.add(function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.back_to_cat.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0) }, this), this.low_buttons.add(this.back_to_cat), this.next_button = null, SaveLoad.unlocked_levels[game.current_category] >= game.current_lvl + 1 && game.current_lvl != Level[game.current_category].length - 1 && (this.next_button = game.add.button(360, 0, null, this.next_level, this), this.next_button.loadTexture("ssheet", "arrow_button"), this.next_button.anchor.setTo(.5, .5), this.next_button.onInputDown.add(function() { SaveLoad.SFX && game.sfx.click.play(), game.add.tween(this.next_button.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0) }, this), this.low_buttons.add(this.next_button)), this.tb_music = game.add.button(80, 0, null, this.tb_music_click, this), this.tb_music.anchor.setTo(.5, 0), SaveLoad.SFX || (this.tb_music.alpha = .5), this.cut_offset = .4 * (game.height - 525), this.wood.y = this.cut_offset, this.tb_music = game.add.button(0, 0, null, this.tb_music_click, this), this.tb_music.anchor.setTo(0, 0), this.tb_music.fixedToCamera = !0, this.tb_music.loadTexture("ssheet", "music_button"), SaveLoad.SFX || (this.tb_music.alpha = .5), 0 == SaveLoad.all_stars ? (this.tutorial = new Tutorial(0, 150), game.add.existing(this.tutorial), this.tutorial_lock = !0, game.time.events.add(1e4, function() { this.tutorial_lock = !1 }, this)) : this.tutorial_lock = !1, this.info_text = game.add.image(210, 250, null), this.info_text.anchor.setTo(.5, .5), this.fade_gfx = game.add.graphics(0, 0), this.fade_gfx.fixedToCamera = !0, this.fade_gfx.beginFill(16777215, 1), this.fade_gfx.drawRect(0, 0, game.width, game.height), this.fade_gfx.endFill(), game.add.tween(this.fade_gfx).to({ alpha: 0 }, 300, Phaser.Easing.Sinusoidal.Out, !0), this.scale.onSizeChange.add(this.resize_layout, this), this.staremitter = game.add.emitter(0, 0, 50), this.staremitter.width = 29, this.staremitter.height = 29, this.staremitter.makeParticles("ssheet", "star_particle"), this.staremitter.gravity = 300, this.staremitter.setXSpeed(-400, 400), this.staremitter.setYSpeed(-500, 100), this.staremitter.setAlpha(1, 0, 1500), game.device.desktop || (this.turndevice = new TurnDevice, game.add.existing(this.turndevice), this.turndevice.test()) }, update: function() { this.slice_line.visible && (this.slice_line_line.width = game.math.distance(this.slice_line.x, this.slice_line.y, this.slice_line_line.x, this.slice_line_line.y) + 15, this.prime_contains(this.slice_line.x, this.slice_line.y - this.cut_offset)) }, tb_music_click: function() { SaveLoad.SFX ? (game.add.tween(this.tb_music).to({ alpha: .5 }, 300, Phaser.Easing.Sinusoidal.InOut, !0), game.sfx.music.stop(), SaveLoad.SFX = !1, SaveLoad.saveSFX()) : (game.add.tween(this.tb_music).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.InOut, !0), SaveLoad.SFX = !0, SaveLoad.saveSFX(), game.sfx.music.play("", 0, 1, !0)) }, prime_contains: function(t, e) { for (var s = 0; s < this.prime_shape.length; s++) if (this.prime_shape[s].contains(t, e)) return !0; return !1 }, resize_layout: function() { this.cut_offset = .4 * (game.height - 520), 0 == this.result.x ? (this.wood.y = this.cut_offset, this.labels.y = this.cut_offset) : (this.wood.y = this.cut_offset, this.labels.y = this.cut_offset), this.fade_gfx.clear(), this.fade_gfx.beginFill(16777215, 1), this.fade_gfx.drawRect(0, 0, game.width, game.height), this.fade_gfx.endFill(), this.low_buttons.y = .91 * game.height, this.result.y = .58 * game.height, this.bg.rescale(), game.device.desktop || this.turndevice.test() }, tb_exit_click: function() { var t = this; t.really_tb_exit_click() }, really_tb_exit_click: function() { game.lastRoom = "Play"; var t = game.add.tween(this.fade_gfx).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.In, !0); SaveLoad.SFX && game.sfx.transition.play(), t.onComplete.add(function() { this.state.start("MainMenu") }, this) }, startCut: function() { game.input.y < 70 || game.input.y > .84 * game.height || 0 != this.cuts_left && (this.slice_line.visible || this.shapes.length != this.shapes_goal && (this.tutorial_lock || (SaveLoad.SFX && game.sfx.click.play(), this.cut_line.width = 0, this.cut_line.x = this.input.x, this.cut_line.y = this.input.y, this.cut_line.visible = !0))) }, endCut: function() { this.cut_line.visible && (this.cut_line.visible = !1, this.cut_line.end_x = game.input.x, this.cut_line.end_y = game.input.y, this.cut_line.width > 20 && this.cut(new Phaser.Line(this.cut_line.x, this.cut_line.y - this.cut_offset, this.input.x, this.input.y - this.cut_offset)), this.cut_line.width = 0) }, cut: function(t) { for (var e = 0; e < this.shapes.length; e++) this.shapes[e].slice(t); this.makeNewShapes(), this.shapes_txt.setText(this.shapes.length + "/" + this.shapes_goal) }, endProcedure: function() { var t = this; t.reallyEndProcedure() }, reallyEndProcedure: function() { /*window.famobi.levelUp(), */this.makeLabels(), game.add.tween(this.wood).to({ y: this.wood.y - 10 }, 500, Phaser.Easing.Sinusoidal.InOut, !0), game.add.tween(this.wood.scale).to({ x: .8, y: .8 }, 500, Phaser.Easing.Sinusoidal.InOut, !0), SaveLoad.SFX && game.sfx.whoosh.play(), this.result_score = new Phaser.Image(game, 84 + 100 / this.shapes_goal * 6, 0, null), this.result_score.anchor.setTo(.5, 0), this.result_bar = new Phaser.Image(game, 210, 0, "ssheet", "result_bar"), this.result_bar.anchor.setTo(.5, 0), this.result.add(this.result_score), this.result.add(this.result_bar), this.result_star = []; for (var t = 0; 3 > t; t++) this.result_star[t] = game.add.image(110 + 100 * t, 80, "ssheet", "result_star_0"), this.result_star[t].highlight = new Phaser.Image(game, 0, 0, "ssheet", "result_star_2"), this.result_star[t].anchor.setTo(.5, .5), this.result_star[t].highlight.alpha = 0, this.result_star[t].highlight.anchor.setTo(.5, .5), this.result_star[t].addChild(this.result_star[t].highlight), this.result.add(this.result_star[t]); game.add.tween(this.result).to({ x: 0 }, 500, Phaser.Easing.Sinusoidal.InOut, !0); for (var t = 0; t < this.labels.length; t++) game.time.events.add(Phaser.Timer.SECOND + 300 * t, this.revelLabel, this, t); game.time.events.add(Phaser.Timer.SECOND + 300 * (2 + this.labels.length), this.revealStars, this) }, revelLabel: function(t) { var e = this.labels.getChildAt(t); game.add.tween(e).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.InOut, !0), game.add.tween(e.scale).to({ x: 2, y: 2 }, 300, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), this.resultAddDot(e.percent), SaveLoad.SFX && game.sfx.label_pop.play() }, revealStars: function() { // window.famobi.levelUp(); console.log('levelUp'); for (var t = this.countResult(), e = 0; t > e; e++) game.add.tween(this.result_star[e].highlight).to({ alpha: 1 }, 500, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0); 0 == t && (game.add.tween(this.result_star[0]).to({ y: 65 }, 300, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), game.add.tween(this.result_star[1]).to({ y: 65 }, 300, Phaser.Easing.Sinusoidal.InOut, !0, 100, 0, !0), game.add.tween(this.result_star[2]).to({ y: 65 }, 300, Phaser.Easing.Sinusoidal.InOut, !0, 200, 0, !0)), SaveLoad.savePassLevel(game.current_category, game.current_lvl, t), game.time.events.add(250, function() { SaveLoad.SFX && (t > 0 ? game.sfx.win.play() : game.sfx.lose.play()); for (var e = 0; t > e; e++) this.result_star[e].loadTexture("ssheet", "result_star_1"), this.staremitter.emitX = this.result_star[e].x, this.staremitter.emitY = this.result.y + this.result_star[e].y, this.staremitter.explode(1500, 15), game.add.tween(this.result_star[e]).to({ angle: 359 }, 3e3, Phaser.Easing.Sinusoidal.InOut, !0, 0, -1, !0) }, this), t > 0 && void 0 == this.next_button && game.current_lvl != Level[game.current_category].length - 1 && (this.next_button = game.add.button(360, 0, null, function() { this.next_level(), SaveLoad.SFX && game.sfx.click.play() }, this), this.next_button.loadTexture("ssheet", "arrow_button"), this.next_button.anchor.setTo(.5, .5), this.low_buttons.add(this.next_button), game.add.tween(this.next_button).from({ alpha: 0 }, 500, Phaser.Easing.Sinusoidal.InOut, !0), game.add.tween(this.next_button.scale).to({ x: 1.2, y: 1.2 }, 500, Phaser.Easing.Sinusoidal.InOut, !0, 0, -1, !0)); // updateShare(SaveLoad.all_stars); // Play68.setRankingScoreDesc(SaveLoad.all_stars,Play68.rankingShowType.RANKING_SHOW_NO); }, countResult: function() { var t = 100 / this.shapes_goal, e = 0; this.labels.forEach(function() { e = Math.max(e, Math.abs(arguments[0].percent - t)) }, this); var s = 100 / this.shapes_goal; return .1 * s > e ? 3 : .2 * s > e ? 2 : .3 * s > e ? 1 : 0 }, resultAddDot: function(t) { var e = new Phaser.Image(game, 35 + 3.5 * t, 5, "ssheet", "result_point"); game.add.tween(e.scale).to({ x: 2, y: 2 }, 300, Phaser.Easing.Sinusoidal.InOut, !0, 0, 0, !0), e.anchor.setTo(.5, .4), this.result.add(e) }, cleanShapes: function() { for (var t = 0; t < this.shapes.length; t++)(this.shapes[t].to_kill || Math.abs(this.shapes[t].area) < 25) && (this.shapes.splice(t, 1), t = -1) }, drawAllShapes: function() { this.bitmapka.clear(); for (var t = 0; t < this.shapes.length; t++) this.drawShapeBitmap(this.shapes[t].points) }, makeNewShapes: function() { for (var t = !1, e = 0; e < this.shapes.length; e++) if (this.shapes[e].new_shapes.length > 0) for (var s = 0; s < this.shapes[e].new_shapes.length; s++) t = !0, this.shapes[this.shapes.length] = new Shape(this.shapes[e].new_shapes[s]); if (this.cleanShapes(), t) { this.cuts_left -= 1, this.cuts_txt.setText("x" + this.cuts_left.toString()), this.slice_line.x = this.cut_line.x, this.slice_line.y = this.cut_line.y, this.slice_line.scale.x = 1.5, this.slice_line.scale.y = 1.5, this.slice_line.alpha = 1, this.slice_line.rotation = this.cut_line.rotation + game.math.degToRad(90), this.slice_line.visible = !0, this.slice_line_line.x = this.cut_line.x, this.slice_line_line.y = this.cut_line.y, this.slice_line_line.alpha = 1, this.slice_line_line.rotation = this.cut_line.rotation, this.slice_line_line.width = 0, SaveLoad.SFX && (game.sfx.chainsaw_index % 2 == 0 ? game.sfx.chainsaw.play() : game.sfx.chainsaw_alt.play(), game.sfx.chainsaw_index++); var a = game.add.tween(this.slice_line).to({ x: this.cut_line.end_x, y: this.cut_line.end_y }, 800, Phaser.Easing.Sinusoidal.InOut).to({ alpha: 0 }, 300, Phaser.Easing.Linear.InOut).start(); a.onComplete.add(function() { this.slice_line.visible = !1, this.drawAllShapes() }, this), game.add.tween(this.slice_line_line).to({ alpha: 0 }, 300, Phaser.Easing.Sinusoidal.InOut, !0, 1100), this.shapes.length > this.shapes_goal ? this.wrongShapeNumber() : this.shapes.length == this.shapes_goal ? a.onComplete.add(function() { game.time.events.add(500, this.endProcedure, this) }, this) : 0 == this.cuts_left && this.wrongShapeNumber() } }, wrongShapeNumber: function() { game.time.events.add(1e3, function() { SaveLoad.SFX && game.sfx.lose.play() }, this), this.shapes.length > this.shapes_goal ? this.info_text.loadTexture("ssheet", "too_many") : this.info_text.loadTexture("ssheet", "not_enough"), game.add.tween(this.info_text).from({ alpha: 0 }, 500, Phaser.Easing.Sinusoidal.InOut, !0, 700), game.add.tween(this.info_text.scale).to({ x: 1.2, y: 1.2 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0, 700, -1, !0), game.add.tween(this.restart.scale).to({ x: 1.15, y: 1.15 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0, 700, -1, !0), game.add.tween(this.shapes_txt.scale).to({ x: 1.3, y: 1.3 }, 1e3, Phaser.Easing.Sinusoidal.InOut, !0, 700, -1, !0) }, drawShapeGraphics: function(t) { var e = t.length; this.graphics.lineStyle(6, 0, 1), this.graphics.beginFill(16724736, 0), this.graphics.moveTo(t[0].x, t[0].y); for (var s = 0; e > s; s++) p_1 = t[s], p_2 = t[(s + 1) % e], this.graphics.lineTo(p_2.x, p_2.y + this.cut_offset); this.graphics.endFill() }, drawShapeBitmap: function(t) { for (var e = t.length, s = 0; e > s; s++) p_1 = t[s], p_2 = t[(s + 1) % e], this.bitmapka.textureLine(new Phaser.Line(p_1.x, p_1.y, p_2.x, p_2.y), "line_dbg") }, totalArea: function() { for (var t = 0, e = 0; e < this.shapes.length; e++) t += Math.abs(this.shapes[e].area); return t }, makeLabels: function() { for (var t = this.totalArea(), e = 0; e < this.shapes.length; e++) { var s = Math.abs(this.shapes[e].area) / t * 100, a = new Phaser.Image(game, this.shapes[e].centroid.x, this.shapes[e].centroid.y, "ssheet", "result_label"); a.percent = s; var i = game.add.bitmapText(0, 0, "font_label", parseFloat(Math.round(100 * s) / 100).toFixed(2) + "%", 20); i.anchor.setTo(.5, .5), a.anchor.setTo(.5, .5), a.addChild(i), a.alpha = 0, this.labels.add(a) } }, shutdown: function() { this.bg.destroy(), this.tb_music.destroy(), this.shapes = null, this.bitmapka_img.destroy(), this.bitmapka = null, this.cut_line.destroy(), this.slice_line.destroy(), this.labels.destroy(), this.result.destroy(), this.restart.destroy(), this.fade_gfx.destroy() }, restart_level: function() { var t = this; t.really_restart_level() }, really_restart_level: function() { game.lastRoom = "Play"; var t = game.add.tween(this.fade_gfx).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.In, !0); t.onComplete.add(function() { this.state.start("Play") }, this) }, next_level: function() { var t = this; t.really_next_level() }, really_next_level: function() { game.lastRoom = "Play"; var t = game.add.tween(this.fade_gfx).to({ alpha: 1 }, 300, Phaser.Easing.Sinusoidal.In, !0); game.current_lvl++, t.onComplete.add(function() { this.state.start("Play") }, this) } };