var resolution = 2; var isPrivate = false; var gamePaused = false; var auto_camera = false; var map = null; var move_car_level = false; var EnemySpeed = [150 * resolution, 170 * resolution, 190 * resolution, 200 * resolution, 210 * resolution, 220 * resolution, 230 * resolution, 240 * resolution, 240 * resolution, 250 * resolution]; var ScoreGoal = [200, 230, 250, 330, 280, 320, 280, 450, 370, 330]; var vect_awards = [false, false, false, false, false]; var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; if (iOS) { window.PhaserGlobal = { audioContext: createAudioContext(44100) }; function createAudioContext(desiredSampleRate) { var AudioCtor = window.AudioContext || window.webkitAudioContext; desiredSampleRate = typeof desiredSampleRate === "number" ? desiredSampleRate : 44100; var context = new AudioCtor; if (/(iPhone|iPad)/i.test(navigator.userAgent) && context.sampleRate !== desiredSampleRate) { var buffer = context.createBuffer(1, 1, desiredSampleRate); var dummy = context.createBufferSource(); dummy.buffer = buffer; dummy.connect(context.destination); dummy.start(0); dummy.disconnect(); context.close(); context = new AudioCtor } return context } } var Music = { enableMisic: true, music: null }; var sauvegarde = []; var level; var nombre_levels = 10; function Save_setItem(name, value) { if (!isPrivate) localStorage.setItem(name, value) } function Save_getItem(name, pardefaut) { if (!isPrivate) return localStorage.getItem(name); else return pardefaut } function save_lire(str1) { sauvegarde = []; var str = str1.split(","); var ligne = 0; var ii = 0; while (ligne < str.length) { sauvegarde[ii] = { numetoile: 0, bestscore: 0 }; sauvegarde[ii].numetoile = +str[ligne++]; sauvegarde[ii].bestscore = +str[ligne++]; ii++ } } function save_ecrit() { var str = ""; for (var i = 0; i < nombre_levels; i++) { str += "" + sauvegarde[i].numetoile; str += ","; str += "" + sauvegarde[i].bestscore; if (i < nombre_levels - 1) str += "," } Save_setItem("candycar_sauvegarde", str) } CandyCarEscape = {}; CandyCarEscape.Boot = function(game) { var logo_data = null } ; CandyCarEscape.Boot.prototype = { preload: function() { game.load.image("rotate", "assets/rotate" + resolution + ".png"); this.game.load.image("preloadSprite01", "assets/preloadBar" + resolution + ".png"); game.load.image("bgPreload", "assets/bgPreload" + resolution + ".png"); game.load.atlasXML("sprites", "assets/sprites.png", "assets/sprites.xml"); game.load.bitmapFont("fontc", "assets/fonts/fontc.png", "assets/fonts/fontc.xml"); game.load.bitmapFont("fontOrg", "assets/fonts/fontOrg.png", "assets/fonts/fontOrg.xml"); game.load.image("chrome", "assets/chrome.png") }, create: function() { this.input.maxPointers = 1; if (this.game.device.desktop) { this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true } else { this.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT; this.scale.forceOrientation(false, true, "rotate") } this.game.scale.enterPortrait.add(this.rescale, this); this.game.scale.enterLandscape.add(this.rescale, this); this.game.onResume.add(this.rescale, this); this.scale.setScreenSize(true); var SpilData = { id: "576742227280299939" }; GameAPI.loadAPI(function(apiInstance) { apiInstance.Branding.displaySplashScreen(continueGame); logo_data = apiInstance.Branding.getLogo(); if (logo_data.image) {} this.game.state.start("preload") }, SpilData) }, rescale: function() { var _game = this.game; setTimeout(function() { _game.scale.refresh(); setTimeout(function() { _game.scale.refresh() }, 400) }, 400) } }; function continueGame() {} text = { textCongratulations: "Congrats!", textAllLevels: "You finished all levels\nplay again and try to\nbeat your records!", youwin: "YOU WIN!", txtPause: "PAUSED!", txtgameover: "GAME OVER!", txtlevel: "Level ", txtscore: "Score", txttuto1: "Tap left or right\non the screen to turn\nthe car", txttuto1_keyboard: "Use left and right\narrows to turn\nthe car", txttuto2: "Collect the coins\nrequested before\nyou run out of time", txttuto3: "Be carful, if you collide\nwith police cars\nyou lose coins", txtTutorial: "Tutorial", txtLoading: "Loading", txtTime: "Time", txtGoal: "Goal", txtGoals: "Collect $", txtGo: "Go!", txtBestScore: "New Best Score !", txtBest: "Best: ", txtloadinglevel: "Loading Level ..." }; CandyCarEscape.Preload = function(game) { this.isbug = false; this.bgmenu = null } ; CandyCarEscape.Preload.prototype = { preload: function() { this.bgmenu = game.add.tileSprite(0, 0, 640, 960, "bgPreload"); var player_menu = game.add.sprite(game.width / 2, game.height * 2, "sprites"); player_menu.frameName = "player_menu" + resolution + ".png"; player_menu.anchor.setTo(.5, .5); game.add.tween(player_menu).to({ y: 200 * resolution }, 500, Phaser.Easing.Quadratic.Out).start(); var police_menu = game.add.sprite(game.width / 2, game.height * 2, "sprites"); police_menu.frameName = "police_menu" + resolution + ".png"; police_menu.anchor.setTo(.5, .5); game.add.tween(police_menu).to({ y: 335 * resolution }, 500, Phaser.Easing.Quadratic.Out, false, 150).start().onComplete.add(function() { var red_light = game.add.sprite(150 * resolution, 295 * resolution, "sprites"); red_light.frameName = "red_light" + resolution + ".png"; red_light.anchor.setTo(.5, .5); game.add.tween(red_light).to({ alpha: .1 }, 150, Phaser.Easing.Quadratic.None).to({ alpha: 1 }, 150, Phaser.Easing.Quadratic.None).start().loop(); game.time.events.add(150, function() { var blue_light = game.add.sprite(170 * resolution, 295 * resolution, "sprites"); blue_light.frameName = "blue_light" + resolution + ".png"; blue_light.anchor.setTo(.5, .5); game.add.tween(blue_light).to({ alpha: .1 }, 150, Phaser.Easing.Quadratic.None).to({ alpha: 1 }, 150, Phaser.Easing.Quadratic.None).start().loop() }, this) }, this); game.add.sprite(98 * resolution, 400 * resolution, "sprites").frameName = "preload_bar_back" + resolution + ".png"; var progressBar = game.add.image(98 * resolution, 400 * resolution, "preloadSprite01"); game.load.setPreloadSprite(progressBar); game.add.bitmapText(120 * resolution, 368 * resolution, "fontc", text.txtLoading, 25 * resolution); var txt_progress = game.add.bitmapText(142 * resolution, 415 * resolution, "fontc", "", 16 * resolution); txt_progress.x = game.width / 2 - txt_progress.textWidth / 2; txt_progress.updateText(); game.load.onFileComplete.add(function(progress) { txt_progress.setText(progress + "%"); txt_progress.updateText(); txt_progress.x = game.width / 2 - txt_progress.textWidth / 2 }, this); game.load.spritesheet("levelbnt", "assets/levelbnt" + resolution + ".png", 32 * resolution, 39.5 * resolution); game.load.image("map1", "assets/map1" + resolution + ".png"); game.load.image("bgMenu", "assets/bgMenu" + resolution + ".png"); game.load.tilemap("LevelsMap", "assets/LevelsMap" + resolution + ".json", null, Phaser.Tilemap.TILED_JSON); game.load.image("tiles", "assets/tiles" + resolution + ".png"); game.load.image("moregames_bnt", "assets/moregames_bnt" + resolution + ".png"); game.load.image("etoile", "assets/etoile" + resolution + ".png"); game.load.image("w_particule", "assets/w_particule" + resolution + ".png"); game.load.image("p_particule", "assets/p_particule" + resolution + ".png"); game.load.image("a_particule", "assets/a_particule" + resolution + ".png"); game.load.spritesheet("car_enemy", "assets/car_enemy" + resolution + ".png", 35 * resolution, 25 * resolution); game.load.image("line", "assets/line" + resolution + ".png"); game.load.image("bgwhite", "assets/bgwhite" + resolution + ".png"); game.load.spritesheet("breaks", "assets/breaks" + resolution + ".png", 7.5 * resolution, 22 * resolution); game.load.spritesheet("objects", "assets/objects" + resolution + ".png", 50 * resolution, 50 * resolution); game.load.spritesheet("bomb_effect", "assets/bomb_effect" + resolution + ".png", 100 * resolution, 100 * resolution); game.load.spritesheet("revive_effect", "assets/revive_effect" + resolution + ".png", 85 * resolution, 69.5 * resolution); game.load.spritesheet("bubble_collect", "assets/bubble_collect" + resolution + ".png", 81 * resolution, 71.5 * resolution); game.load.image("bgnoire", "assets/bgnoire" + resolution + ".png"); game.load.image("credits", "assets/credits" + resolution + ".png"); game.load.image("logo_spil", logo_data.image); game.load.audio("song17", ["assets/music/song17.mp3", "assets/music/song17.ogg"]); if (this.game.device.ie) { game.load.audio("sounds", ["assets/music/sounds.ogg", "assets/music/sounds.mp3"]); game.load.audio("brakes", ["assets/music/brakes.mp3", "assets/music/brakes.ogg"]) } else if (this.game.sound.usingWebAudio) { game.load.audio("sounds", ["assets/music/sounds.ogg", "assets/music/sounds.mp3"]); game.load.audio("brakes", ["assets/music/brakes.mp3", "assets/music/brakes.ogg"]) } this.ready = false }, create: function() { var isS5 = window.navigator.userAgent.indexOf("SM-G900") > -1; var isDefaultBrowser = window.navigator.userAgent.indexOf("SamsungBrowser") > -1; if (isS5 && isDefaultBrowser) { this.bgmenu.loadTexture("bgMenu"); game.world.bringToTop(this.bgmenu); this.isbug = true; game.add.sprite(0, 0, "bgnoire").alpha = .6; game.add.bitmapText(120, 500, "fontc", "PLEASE LAUNCH\nGOOGLE CHROME\nTO PLAY THIS GAME", 55).align = "center"; game.add.sprite(this.world.centerX, 320, "chrome").anchor.setTo(.5, .5); return } if (GameAPI.Branding.getSplashScreen().show) { this.bgmenu.inputEnabled = true; this.bgmenu.events.onInputUp.add(GameAPI.Branding.getSplashScreen().action, this) } auto_camera = false; if (game.device.localStorage) { this.TestPrivate(); var str = Save_getItem("candycar_sauvegarde", null); level = Save_getItem("candycar_level", 0); if (str == null || str == "null" || level == null || level == "null") { sauvegarde = []; for (var i = 0; i < nombre_levels; i++) { sauvegarde[i] = { numetoile: 0, bestscore: 0 } } save_ecrit(); level = 0; Save_setItem("candycar_level", level) } else { save_lire(str) } } map = game.add.tilemap("LevelsMap") }, TestPrivate: function() { var testKey = "qeTest" , storage = window.sessionStorage; try { storage.setItem(testKey, "1"); storage.removeItem(testKey) } catch (error) { if (error.code === DOMException.QUOTA_EXCEEDED_ERR && storage.length === 0) { isPrivate = true } else { isPrivate = false } } }, update: function() { if (this.isbug) return; if (game.cache.isSoundDecoded("song17") && this.ready == false) { this.ready = true; game.onPause.add(function() { gamePaused = true; Music.music.pause(); Music.sounds.pause() }, this); game.onResume.add(function() { gamePaused = false; if (Music.enableMisic) { Music.music.resume(); Music.sounds.resume() } }, this); this.game.state.start("menu"); play.numLevel = parseInt(level) + 1; Music.music = this.game.add.audio("song17"); Music.brakes = this.game.add.audio("brakes"); Music.sounds = this.game.add.audio("sounds"); Music.sounds.addMarker("bomb", 0, 1.51); Music.sounds.addMarker("button", 3, .2568027210884356); Music.sounds.addMarker("car_hit", 5, .4327437641723355); Music.sounds.addMarker("collect_coin", 7, .560181405895691); Music.sounds.addMarker("collect_powerup", 9, 1.002585034013606); Music.sounds.addMarker("collision_map", 12, .43); Music.sounds.addMarker("countdown", 14, .399274376417234); Music.sounds.addMarker("countdown2", 16, .32780045351474); Music.sounds.addMarker("frozen", 18, .92142857142857); Music.sounds.addMarker("whoosh", 20, .99265306122449); Music.sounds.addMarker("win", 22, 1.30360544217687); Music.music.play(); Music.music.onStop.add(function() { if (gamePaused) return; if (Music.enableMisic) Music.music.play() }, this) } } }; var Bouton = function(game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { Phaser.Button.call(this, game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame); this.anchor.setTo(.5, .5); this.onInputDown.add(function() { game.add.tween(this.scale).to({ x: 1.15, y: .8 }, 200, Phaser.Easing.Back.Out).to({ x: 1, y: 1 }, 400, Phaser.Easing.Elastic.Out).start(); game.add.tween(this).to({ angle: 3 }, 150, Phaser.Easing.Quadratic.Out).to({ angle: -5 }, 150, Phaser.Easing.Quadratic.Out).to({ angle: 0 }, 200, Phaser.Easing.Quadratic.Out).start(); if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("button"); if (this.txt) { game.world.bringToTop(this.txt); game.add.tween(this.txt.scale).to({ x: 1.15, y: .8 }, 200, Phaser.Easing.Back.Out).to({ x: 1, y: 1 }, 400, Phaser.Easing.Elastic.Out).start(); game.add.tween(this.txt).to({ angle: 3 }, 150, Phaser.Easing.Quadratic.Out).to({ angle: -5 }, 150, Phaser.Easing.Quadratic.Out).to({ angle: 0 }, 200, Phaser.Easing.Quadratic.Out).start() } }, this); this.onInputUp.add(function() { if (this.txt) { game.world.bringToTop(this.txt) } }, this); this.onInputOver.add(function() {}, this) }; Bouton.prototype = Object.create(Phaser.Button.prototype); Bouton.prototype.constructor = Bouton; CandyCarEscape.Menu = function(game) { this.musicbnt = null; this.bnt_play = null; this.bnt_credits = null; this.bnt_moregames = null; this.logo = null; this.tween_play = null; this.state = null; this.vect_shinings = null } ; CandyCarEscape.Menu.prototype = { create: function() { this.add.image(0, 0, "bgMenu"); var police_menu1 = game.add.sprite(game.width * 2 + 25 * resolution, 0, "sprites"); police_menu1.frameName = "police_menu" + resolution + ".png"; police_menu1.anchor.setTo(.5, .5); police_menu1.angle = -130; game.add.tween(police_menu1).to({ x: game.width + 25 * resolution, y: 105 * resolution }, 500, Phaser.Easing.Quadratic.Out, false, 150).start().onComplete.add(function() { var red_light = game.add.sprite(321 * resolution, 136 * resolution, "sprites"); red_light.frameName = "red_light" + resolution + ".png"; red_light.anchor.setTo(.5, .5); game.add.tween(red_light).to({ alpha: .1 }, 150, Phaser.Easing.Quadratic.None).to({ alpha: 1 }, 150, Phaser.Easing.Quadratic.None).start().loop(); game.time.events.add(150, function() { var blue_light = game.add.sprite(307 * resolution, 124 * resolution, "sprites"); blue_light.frameName = "blue_light" + resolution + ".png"; blue_light.anchor.setTo(.5, .5); game.add.tween(blue_light).to({ alpha: .1 }, 150, Phaser.Easing.Quadratic.None).to({ alpha: 1 }, 150, Phaser.Easing.Quadratic.None).start().loop() }, this) }, this); var police_menu2 = game.add.sprite(-game.width - 25 * resolution, 0, "sprites"); police_menu2.frameName = "police_menu" + resolution + ".png"; police_menu2.anchor.setTo(.5, .5); police_menu2.angle = 130; game.add.tween(police_menu2).to({ x: -25 * resolution, y: 130 * resolution }, 500, Phaser.Easing.Quadratic.Out, false, 300).start().onComplete.add(function() { var red_light = game.add.sprite(11.5 * resolution, 149 * resolution, "sprites"); red_light.frameName = "red_light" + resolution + ".png"; red_light.anchor.setTo(.5, .5); game.add.tween(red_light).to({ alpha: .1 }, 150, Phaser.Easing.Quadratic.None).to({ alpha: 1 }, 150, Phaser.Easing.Quadratic.None).start().loop(); game.time.events.add(150, function() { var blue_light = game.add.sprite(-2 * resolution, 162 * resolution, "sprites"); blue_light.frameName = "blue_light" + resolution + ".png"; blue_light.anchor.setTo(.5, .5); game.add.tween(blue_light).to({ alpha: .1 }, 150, Phaser.Easing.Quadratic.None).to({ alpha: 1 }, 150, Phaser.Easing.Quadratic.None).start().loop() }, this) }, this); this.logo = game.add.sprite(-game.width, 80 * resolution, "sprites"); this.logo.frameName = "logo" + resolution + ".png"; this.logo.anchor.setTo(1, .5); game.add.tween(this.logo).to({ x: game.width - 10 * resolution }, 500, Phaser.Easing.Back.Out, false, 1200).start(); var menu_coins = game.add.sprite(game.width / 2, 250 * resolution, "sprites"); menu_coins.frameName = "menu_coins" + resolution + ".png"; menu_coins.anchor.setTo(.5, .5); menu_coins.scale.setTo(0, 0); game.add.tween(menu_coins.scale).to({ x: 1, y: 1 }, 250, Phaser.Easing.Back.Out, false, 550).start().onComplete.add(function() { this.create_shinings(); this.Bright_shinings() }, this); var player_menu = game.add.sprite(game.width / 2, game.height * 2, "sprites"); player_menu.frameName = "player_menu" + resolution + ".png"; player_menu.anchor.setTo(.5, .5); game.add.tween(player_menu).to({ y: 320 * resolution }, 500, Phaser.Easing.Quadratic.Out).start(); this.bnt_play = new Bouton(this.game,game.width / 2,378 * resolution,"sprites",this.actionPlay,this); this.bnt_play.frameName = "playbtn" + resolution + ".png"; this.bnt_play.scale.setTo(0, 0); game.add.tween(this.bnt_play.scale).to({ x: 1, y: 1 }, 400, Phaser.Easing.Back.Out, false, 900).start().onComplete.add(function() { game.add.tween(this.bnt_play.scale).to({ x: 1.15, y: 1.15 }, 1e3, Phaser.Easing.Quadratic.Out).to({ x: .85, y: .85 }, 1e3, Phaser.Easing.Quadratic.Out).start().loop() }, this); this.world.add(this.bnt_play); this.bnt_credits = new Bouton(this.game,60,407 * resolution,"sprites",this.funccredits,this); this.bnt_credits.frameName = "creditsBnt" + resolution + ".png"; this.bnt_credits.scale.setTo(0, 0); game.add.tween(this.bnt_credits.scale).to({ x: 1, y: 1 }, 400, Phaser.Easing.Back.Out, false, 800).start(); this.world.add(this.bnt_credits); this.musicbnt = new Bouton(this.game,290 * resolution,407 * resolution,"sprites",this.actionMusic,this); this.musicbnt.frameName = "musicbnt" + resolution + ".png"; this.musicbnt.scale.setTo(0, 0); game.add.tween(this.musicbnt.scale).to({ x: 1, y: 1 }, 400, Phaser.Easing.Back.Out, false, 1100).start(); this.world.add(this.musicbnt); if (Music.enableMisic) { this.musicbnt.frameName = "musicbnt" + resolution + ".png" } else { this.musicbnt.frameName = "Mutemusicbnt" + resolution + ".png" } if (GameAPI.Branding.getLogo().image) { var spil_logo = new Bouton(this.game,0,0,"logo_spil",GameAPI.Branding.getLogo().action,this); spil_logo.x = 15 * resolution + spil_logo.width / 2; spil_logo.y = game.height - spil_logo.height / 2 - 5 * resolution; this.world.add(spil_logo) } }, actionMusic: function() { Music.enableMisic = !Music.enableMisic; if (Music.enableMisic) { this.musicbnt.frameName = "musicbnt" + resolution + ".png"; Music.music.resume() } else { this.musicbnt.frameName = "Mutemusicbnt" + resolution + ".png"; Music.music.pause() } }, actionPlay: function() { play.InitialiseFade("levels") }, funccredits: function() { return play.InitialiseFade("credits") }, funcmoregames: function() {}, create_shinings: function() { this.vect_shinings = []; var shining1 = game.add.sprite(22.5 * resolution, 233 * resolution, "sprites"); shining1.frameName = "etoile_particule" + resolution + ".png"; shining1.anchor.setTo(.5, .5); shining1.alpha = 0; this.vect_shinings.push(shining1); var shining2 = game.add.sprite(298 * resolution, 298 * resolution, "sprites"); shining2.frameName = "etoile_particule" + resolution + ".png"; shining2.anchor.setTo(.5, .5); shining2.alpha = 0; this.vect_shinings.push(shining2); var shining3 = game.add.sprite(73.5 * resolution, 318.5 * resolution, "sprites"); shining3.frameName = "etoile_particule" + resolution + ".png"; shining3.anchor.setTo(.5, .5); shining3.alpha = 0; this.vect_shinings.push(shining3); var shining4 = game.add.sprite(283 * resolution, 213 * resolution, "sprites"); shining4.frameName = "etoile_particule" + resolution + ".png"; shining4.anchor.setTo(.5, .5); shining4.alpha = 0; this.vect_shinings.push(shining4); var shining5 = game.add.sprite(232 * resolution, 177 * resolution, "sprites"); shining5.frameName = "etoile_particule" + resolution + ".png"; shining5.anchor.setTo(.5, .5); shining5.alpha = 0; this.vect_shinings.push(shining5) }, Bright_shinings: function() { var rnd_index = Math.floor(Math.random() * (this.vect_shinings.length - .1)); game.add.tween(this.vect_shinings[rnd_index]).to({ alpha: 1 }, 500, Phaser.Easing.Linear.None).to({ alpha: 0 }, 500, Phaser.Easing.Linear.None, false, 200).start(); game.add.tween(this.vect_shinings[rnd_index]).to({ angle: 360 }, 1200, Phaser.Easing.Linear.None).start(); game.time.events.add(1300, this.Bright_shinings, this) } }; CandyCarEscape.Credits = function(game) { this.bnt_home = null } ; CandyCarEscape.Credits.prototype = { create: function() { this.add.sprite(0, 0, "credits"); this.bnt_home = new Bouton(this.game,game.width / 2,75 * resolution,"sprites",this.funcHome,this); this.bnt_home.frameName = "menubnt" + resolution + ".png"; this.bnt_home.scale.setTo(0, 0); this.world.add(this.bnt_home); game.add.tween(this.bnt_home.scale).to({ x: 1, y: 1 }, 400, Phaser.Easing.Back.Out, false, 200).start() }, funcHome: function() { play.InitialiseFade("menu") } }; CandyCarEscape.Map_Levels = function(game) { this.debut_swip = null; this.moveto = null; this.bnt_home = null; this.isbegin = null; this.vitess_camera = null; this.bnt_level = null; this.vect_positions = null; this.group_bnt = null; this.play_objectif = null; this.exit_objectif = null; this.group_objectif = null; this.is_cam_moving = null; this.stop_position = null; this.car = null } ; CandyCarEscape.Map_Levels.prototype = { create: function() { this.vect_positions = [{ x: 250 * resolution, y: 440 * resolution, num: 1 }, { x: 160 * resolution, y: 437 * resolution, num: 2 }, { x: 160 * resolution, y: 339 * resolution, num: 3 }, { x: 260 * resolution, y: 335 * resolution, num: 4 }, { x: 260 * resolution, y: 238 * resolution, num: 5 }, { x: 155 * resolution, y: 235 * resolution, num: 6 }, { x: 155 * resolution, y: 139 * resolution, num: 7 }, { x: 260 * resolution, y: 135 * resolution, num: 8 }, { x: 260 * resolution, y: 40 * resolution, num: 9 }, { x: 141 * resolution, y: 23 * resolution, num: 10 }]; this.vect_position_car = [{ x: 230 * resolution, y: 462 * resolution, angle: -115, marge: 0 }, { x: 146 * resolution, y: 440 * resolution, angle: -180, marge: 20 * resolution }, { x: 85 * resolution, y: 367 * resolution, angle: -72, marge: 50 * resolution }, { x: 175 * resolution, y: 340 * resolution, angle: 0, marge: 25 * resolution }, { x: 236 * resolution, y: 268 * resolution, angle: -105, marge: 50 * resolution }, { x: 145 * resolution, y: 240 * resolution, angle: -180, marge: 25 * resolution }, { x: 83 * resolution, y: 172 * resolution, angle: -72, marge: 50 * resolution }, { x: 175 * resolution, y: 140 * resolution, angle: 0, marge: 28 * resolution }, { x: 233 * resolution, y: 70 * resolution, angle: -105, marge: 50 * resolution }, { x: 127 * resolution, y: 40 * resolution, angle: -180, marge: 28 * resolution }]; this.add.sprite(0, 0, "map1"); this.isbegin = auto_camera; this.vitess_camera = 0; this.debut_swip = 0; this.moveto = 0; this.is_cam_moving = true; game.input.onDown.add(this.start_swipe, this); this.group_bnt = game.add.group(); var framebnt = 0; for (var i = 0; i < nombre_levels; i++) { framebnt = 0; this.bnt_level = new Bouton(this.game,this.vect_positions[i].x - 50 * resolution,this.vect_positions[i].y,"levelbnt",null,null); this.bnt_level.onInputUp.add(function() { if (this.frame != 0 && !lv.isbegin && !lv.is_cam_moving) { play.numLevel = parseInt(this.txt.text); lv.Activer_Input(false); play.InitialiseFade("play"); play.bgnoire.y = game.camera.y } }, this.bnt_level); this.bnt_level.txt = new Phaser.BitmapText(this.game,this.bnt_level.x - 5.5 * resolution,this.bnt_level.y - 12 * resolution,"fontOrg","" + this.vect_positions[i].num,18 * resolution); this.bnt_level.txt.updateText(); this.bnt_level.txt.x = this.bnt_level.x - this.bnt_level.txt.textWidth / 2; this.bnt_level.scale.setTo(0, 0); game.add.tween(this.bnt_level.scale).to({ x: 1, y: 1 }, 400, Phaser.Easing.Back.Out, false, 30 * this.group_bnt.length).start(); this.bnt_level.txt.alpha = 0; game.add.tween(this.bnt_level.txt).to({ alpha: 1 }, 400, Phaser.Easing.Back.Out, false, 30 * this.group_bnt.length).start(); this.group_bnt.add(this.bnt_level); this.group_bnt.add(this.bnt_level.txt); if (+this.bnt_level.txt.text <= +level + 1) { framebnt = sauvegarde[+this.bnt_level.txt.text - 1].numetoile + 1 } else { framebnt = 0 } this.bnt_level.frame = framebnt } this.bnt_home = new Bouton(this.game,30 * resolution,30 * resolution,"sprites",this.func_home,this); this.bnt_home.frameName = "menubnt" + resolution + ".png"; this.bnt_home.fixedToCamera = true; this.world.add(this.bnt_home); this.stop_position = this.vect_positions[+level].y - this.group_bnt.getAt(0).height / 2 - 100 * resolution; if (this.stop_position > 0) this.stop_position = 0; if (auto_camera) game.camera.y = -480 * resolution; else game.camera.y = this.stop_position; if (level == 0 || !move_car_level) { this.car = game.add.sprite(this.vect_position_car[level].x, this.vect_position_car[level].y, "sprites"); this.car.angle = this.vect_position_car[level].angle } else { this.car = game.add.sprite(this.vect_position_car[level - 1].x, this.vect_position_car[level - 1].y, "sprites"); this.car.angle = this.vect_position_car[level - 1].angle; if (level % 2 != 0) { game.add.tween(this.car).to({ angle: this.vect_position_car[level].angle }, 800, Phaser.Easing.Quadratic.In, false, 30 * this.group_bnt.length).start(); game.add.tween(this.car).to({ x: this.car.x + Math.cos(this.car.rotation) * this.vect_position_car[level].marge, y: this.car.y + Math.sin(this.car.rotation) * this.vect_position_car[level].marge }, 600, Phaser.Easing.Quadratic.In, false, 30 * this.group_bnt.length).start().onComplete.add(function() { game.add.tween(this.car).to({ x: this.vect_position_car[level].x, y: this.vect_position_car[level].y }, 1e3, Phaser.Easing.Quadratic.InOut).start() }, this) } else { game.add.tween(this.car).to({ x: this.car.x + Math.cos(this.car.rotation) * this.vect_position_car[level].marge, y: this.car.y + Math.sin(this.car.rotation) * this.vect_position_car[level].marge }, 600, Phaser.Easing.Quadratic.In, false, 30 * this.group_bnt.length).start().onComplete.add(function() { game.add.tween(this.car).to({ angle: this.vect_position_car[level].angle }, 1250, Phaser.Easing.Quadratic.Out).start(); game.add.tween(this.car).to({ x: this.vect_position_car[level].x, y: this.vect_position_car[level].y }, 1e3, Phaser.Easing.Quadratic.InOut).start() }, this) } move_car_level = false } this.car.frameName = "car" + resolution + ".png"; this.car.anchor.setTo(.5, .5); if (GameAPI.Branding.getLogo().image) { var spil_logo = new Bouton(this.game,0,0,"logo_spil",GameAPI.Branding.getLogo().action,this); spil_logo.x = 15 * resolution + spil_logo.width / 2; spil_logo.y = game.height - spil_logo.height / 2 - 5 * resolution; this.world.add(spil_logo) } }, start_swipe: function() { this.debut_swip = game.input.activePointer.y; if (this.is_cam_moving) this.is_cam_moving = false }, swipe_to: function() { if (game.input.activePointer.isDown) { this.moveto = game.input.activePointer.y } if (Math.abs(this.moveto - this.debut_swip) > .5) { game.camera.y -= game.time.elapsed * .001 * (40 * resolution) * (this.moveto - this.debut_swip) / 7; this.debut_swip += (this.moveto - this.debut_swip) / 7; if (!this.is_cam_moving) this.is_cam_moving = true } }, update: function() { if (this.isbegin) { if (this.camera.y >= -480 * resolution && this.camera.y < (this.stop_position - 480 * resolution) / 2) { this.vitess_camera++; this.camera.y += game.time.elapsed * .1 * (this.vitess_camera / (240 * resolution)) * (15 * resolution) } else if (this.camera.y >= (this.stop_position - 480 * resolution) / 2 && this.camera.y < this.stop_position) { if (this.vitess_camera > 10) { this.vitess_camera--; this.camera.y += game.time.elapsed * .1 * (this.vitess_camera / (240 * resolution)) * (15 * resolution) } else { this.camera.y++ } } else if (this.camera.y >= this.stop_position) { this.isbegin = false; this.camera.y = this.stop_position; auto_camera = false } } else if (game.input.onDown.active) { this.swipe_to() } }, func_home: function() { if (this.isbegin) return; play.InitialiseFade("menu"); play.bgnoire.y = game.camera.y }, Activer_Input: function(bool) { lv.group_bnt.forEach(function(sp) { game.input.onDown.active = bool }, this) } }; CandyCarEscape.Play = function(game) { this.numLevel = null; this.gameOver = false; this.next_level = null; this.bnt_pause = null; this.bnt_replay = null; this.bgPause = null; this.start = null; this.groupPause = null; this.groupNexLevel = null; this.textPause = null; this.textPauseLevel = null; this.etoilEnd1 = null; this.etoilEnd2 = null; this.etoilEnd3 = null; this.timerEndLevel = null; this.timerEndLevelAndLose = null; this.istimerEndLevel = null; this.istimerEndLevelAndLose = null; this.isEndAllLevels = null; this.stateMusic = null; this.bgnoire = null; this.you_win = null; this.taille = null; this.rows = null; this.cols = null; this.current_score = null; this.txt_score = null; this.number_etoiles = null; this.txt_score_win = null; this.record_container = null; this.tuto_title = null; this.tuto = null; this.tuto_container = null; this.bnt_tuto = null; this.minutes = null; this.secondss = null; this.bonus_timer = null; this.bonus_time = null; this.current_score = null; this.txt_score = null; this.txt_score_word = null; this.number_etoiles = null; this.txt_score_win = null; this.car = null; this.group_freins = null; this.cursors = null; this.map = null; this.layer = null; this.group_enemies = null; this.group_objects = null; this.vect_zones = null; this.txt_time_game = null; this.txt_time_word = null; this.txt_goal = null; this.txt_goal_word = null; this.vect_powerups = null; this.shield_sprite = null; this.objectif_container = null; this.txt_goals = null; this.txt_countdown = null; this.GameStart = null; this.upLine = null; this.downLine = null; this.leftLine = null; this.rightLine = null; this.group_objects_top = null; this.emitter_snow = null; this.sound_brakes = null; this.bnt_music = null; this.ispause_music = null; this.bg_loading = null; this.text_loading_level = null } ; CandyCarEscape.Play.prototype = { preload: function() { this.bg_loading = game.add.sprite(0, 0, "bgMenu"); this.text_loading_level = game.add.bitmapText(game.width / 2, game.height / 2, "fontc", text.txtloadinglevel, 35 * resolution); this.text_loading_level.updateText(); this.text_loading_level.x -= this.text_loading_level.textWidth / 2; for (var i = 1; i <= nombre_levels; i++) { if (i != play.numLevel && game.cache.checkImageKey("ground" + i)) { game.cache.removeImage("ground" + i) } } game.load.image("ground" + play.numLevel, "assets/ground" + play.numLevel + "" + resolution + ".jpg") }, create: function() { this.bg_loading.destroy(); this.text_loading_level.destroy(); this.initAtributs(); if (this.numLevel <= 10) game.add.image(0, 0, "ground" + this.numLevel); else game.add.image(0, 0, "ground10"); game.world.setBounds(0, 0, 1e3 * resolution, 1e3 * resolution); if (this.numLevel > nombre_levels) { this.createCongratulations(); this.gameOver = true; return } this.number_etoiles = 0; this.sound_brakes = false; this.cursors = game.input.keyboard.createCursorKeys(); this.shield_sprite = null; this.taille = 5 * resolution; this.rows = 200; this.cols = 200; this.ispause_music = false; this.current_score = 0; this.minutes = 1; this.secondss = 0; this.bonus_time = this.minutes * 60 + this.secondss; this.bonus_timer = 1e3; this.map = map; this.map.currentLayer = this.numLevel - 1; this.map.setCollisionBetween(2, 2); this.layer = this.map.createLayer(this.numLevel - 1); this.group_freins = game.add.group(); this.group_enemies = game.add.group(); this.group_objects = game.add.group(); this.vect_powerups = []; for (var i = 0; i < 4; i++) { this.vect_powerups.push(0) } for (var i = 0; i < 200; i++) { for (var j = 0; j < 200; j++) { if (this.map.getTile(j, i).index == 3) { this.CreateCarEnemy(i, j) } else if (this.map.getTile(j, i).index == 4) { this.CreateObject(j * this.taille, i * this.taille, 1, false) } else if (this.map.getTile(j, i).index == 5) { var rnd_index = Math.floor(Math.random() * 3.9 + 2); while (this.vect_powerups[rnd_index - 2] == 1) { rnd_index = Math.floor(Math.random() * 3.9 + 2) } this.vect_powerups[rnd_index - 2] = 1; this.CreateObject(j * this.taille, i * this.taille, rnd_index, false) } else if (this.map.getTile(j, i).index == 6) { this.CreatePlayer(j * this.taille, i * this.taille) } else if (this.map.getTile(j, i).index == 7) {} } } this.group_objects_top = game.add.group(); for (var i = 0; i < 200; i++) { for (var j = 0; j < 200; j++) { if (this.map.getTile(j, i).index == 7 || this.map.getTile(j, i).index == 8) { var object = new Phaser.Sprite(game,j * this.taille,i * this.taille,"sprites"); object.frameName = play.map.layers[play.map.currentLayer].name[0] + "_big_tree" + resolution + ".png"; object.anchor.setTo(.5, .5); if (this.map.getTile(j, i).index == 8) object.scale.x = -1; this.group_objects_top.add(object) } else if (this.map.getTile(j, i).index == 9 || this.map.getTile(j, i).index == 10) { var object = new Phaser.Sprite(game,j * this.taille,i * this.taille,"sprites"); object.frameName = "flags" + resolution + ".png"; object.anchor.setTo(.5, .5); if (this.map.getTile(j, i).index == 10) object.angle = -90; this.group_objects_top.add(object) } } } this.vect_zones = []; this.vect_zones.push({ x: 0, y: 0 }); this.vect_zones.push({ x: 20 * resolution, y: 0 }); this.vect_zones.push({ x: -20 * resolution, y: 0 }); this.vect_zones.push({ x: 0, y: 20 * resolution }); this.vect_zones.push({ x: 0, y: -20 * resolution }); if (game.device.desktop && play.map.layers[play.map.currentLayer].name[0] != "s") { this.emitter_snow = game.add.emitter(game.world.width / 2, -10 * resolution, 500); this.emitter_snow.makeParticles(play.map.layers[play.map.currentLayer].name[0] + "_particule"); this.emitter_snow.setRotation(0, 180); this.emitter_snow.maxParticleScale = 1.2; this.emitter_snow.minParticleScale = .2; this.emitter_snow.setYSpeed(20, 50); this.emitter_snow.setXSpeed(-10, -50); this.emitter_snow.width = game.world.width; this.emitter_snow.height = game.world.height; this.emitter_snow.start(false, 2e4, 100) } this.createButtonsPlay(); var timer_container = game.add.sprite(5 * resolution, 5 * resolution, "sprites"); timer_container.frameName = "timer_container" + resolution + ".png"; timer_container.fixedToCamera = true; this.txt_time_word = game.add.bitmapText(27 * resolution, 37 * resolution, "fontc", text.txtTime, 17 * resolution); this.txt_time_word.fixedToCamera = true; this.txt_time_game = game.add.bitmapText(0, 13 * resolution, "fontc", this.minutes + ":" + this.secondss, 17 * resolution); if (this.secondss == 0) this.txt_time_game.setText(this.minutes + ":0" + this.secondss); else this.txt_time_game.setText(this.minutes + ":" + this.secondss); this.txt_time_game.updateText(); this.txt_time_game.x = this.txt_time_word.x + this.txt_time_word.textWidth / 2 - this.txt_time_game.textWidth / 2 + 10 * resolution; this.txt_time_game.fixedToCamera = true; var score_container = game.add.sprite(85 * resolution, 5 * resolution, "sprites"); score_container.frameName = "score_container" + resolution + ".png"; score_container.fixedToCamera = true; this.txt_score_word = game.add.bitmapText(103 * resolution, 37 * resolution, "fontc", text.txtscore, 17 * resolution); this.txt_score_word.fixedToCamera = true; this.txt_score = game.add.bitmapText(0, 13 * resolution, "fontc", "" + this.current_score, 17 * resolution); this.txt_score.updateText(); this.txt_score.x = this.txt_score_word.x + this.txt_score_word.textWidth / 2 - this.txt_score.textWidth / 2 + 6 * resolution; this.txt_score.fixedToCamera = true; var goal_container = game.add.sprite(165 * resolution, 5 * resolution, "sprites"); goal_container.frameName = "score_container" + resolution + ".png"; goal_container.fixedToCamera = true; this.txt_goal_word = game.add.bitmapText(185 * resolution, 37 * resolution, "fontc", text.txtGoal, 17 * resolution); this.txt_goal_word.fixedToCamera = true; this.txt_goal = game.add.bitmapText(0, 13 * resolution, "fontc", ScoreGoal[play.numLevel - 1] + "", 17 * resolution); this.txt_goal.updateText(); this.txt_goal.x = this.txt_goal_word.x + this.txt_goal_word.textWidth / 2 - this.txt_goal.textWidth / 2 + 12 * resolution; this.txt_goal.fixedToCamera = true; this.upLine = game.add.sprite(0, 30 * resolution, "line"); this.upLine.width = game.world.width; this.downLine = game.add.sprite(0, 965 * resolution, "line"); this.downLine.width = game.world.width; this.leftLine = game.add.sprite(30 * resolution, 0, "line"); this.leftLine.width = game.world.height; this.leftLine.angle = 90; this.rightLine = game.add.sprite(970 * resolution, 0, "line"); this.rightLine.width = game.world.height; this.rightLine.angle = 90; game.input.onDown.add(function() { if (!this.sound_brakes) { this.sound_brakes = true; game.time.events.add(400, function() { if (game.input.activePointer.isDown || this.cursors.right.isDown || this.cursors.left.isDown) { if (Music.enableMisic && game.sound.usingWebAudio) Music.brakes.play(); this.sound_brakes = false } }, this) } }, this); game.input.onUp.add(function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.brakes.stop(); this.sound_brakes = false }, this); this.cursors.right.onDown.add(function() { if (!this.sound_brakes) { this.sound_brakes = true; game.time.events.add(400, function() { if (game.input.activePointer.isDown || this.cursors.right.isDown || this.cursors.left.isDown) { if (Music.enableMisic && game.sound.usingWebAudio) Music.brakes.play(); this.sound_brakes = false } }, this) } }, this); this.cursors.right.onUp.add(function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.brakes.stop(); this.sound_brakes = false }, this); this.cursors.left.onDown.add(function() { if (!this.sound_brakes) { this.sound_brakes = true; game.time.events.add(400, function() { if (game.input.activePointer.isDown || this.cursors.right.isDown || this.cursors.left.isDown) { if (Music.enableMisic && game.sound.usingWebAudio) Music.brakes.play(); this.sound_brakes = false } }, this) } }, this); this.cursors.left.onUp.add(function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.brakes.stop(); this.sound_brakes = false }, this); if (GameAPI.Branding.getLogo().image) { var spil_logo = new Bouton(this.game,0,0,"logo_spil",GameAPI.Branding.getLogo().action,this); spil_logo.x = 7 * resolution + spil_logo.width / 2; spil_logo.y = game.height - spil_logo.height / 2 - 5 * resolution; spil_logo.fixedToCamera = true; this.world.add(spil_logo) } this.bg_noire = game.add.image(0, 0, "bgnoire"); this.bg_noire.alpha = .7; this.bg_noire.visible = false; this.bg_noire.alive = true; this.bg_noire.fixedToCamera = true; this.GameStart = false; if (play.numLevel == 1) { this.bg_noire.visible = true; this.tuto_container = this.game.add.sprite(game.width / 2, 270 * resolution, "sprites"); this.tuto_container.frameName = "bgPause" + resolution + ".png"; this.tuto_container.anchor.setTo(.5, .5); this.tuto_container.fixedToCamera = true; this.bnt_tuto = new Bouton(this.game,160 * resolution,360 * resolution,"sprites",function() { if (this.tuto.text == text.txttuto1 || this.tuto.text == text.txttuto1_keyboard) { this.tuto.setText(text.txttuto2); this.tuto.updateText(); this.tuto.fixedToCamera = false; this.tuto.x = this.tuto_container.x - this.tuto.textWidth / 2 } else if (this.tuto.text == text.txttuto2) { this.tuto.setText(text.txttuto3); this.tuto.updateText(); this.tuto.x = this.tuto_container.x - this.tuto.textWidth / 2 } else { this.tuto.destroy(); this.tuto_title.destroy(); this.tuto_container.destroy(); this.bnt_tuto.destroy(); this.bg_noire.visible = false; game.time.events.add(500, function() { this.txt_countdown = game.add.bitmapText(0, 240 * resolution + game.camera.y, "fontOrg", "3", 50 * resolution); this.txt_countdown.updateText(); this.txt_countdown.x = game.camera.x + game.width / 2 - this.txt_countdown.textWidth / 2; this.txt_countdown.visible = false; this.objectif_container = game.add.sprite(game.camera.x, -game.height + game.camera.y, "sprites"); this.objectif_container.frameName = "objectif_container" + resolution + ".png"; this.txt_goals = game.add.bitmapText(0, 0, "fontc", text.txtGoals + ScoreGoal[play.numLevel - 1], 30 * resolution); this.txt_goals.updateText(); this.txt_goals.x = game.camera.x + game.width / 2 - this.txt_goals.textWidth / 2 + 20 * resolution; this.txt_goals.y = this.objectif_container.y + this.objectif_container.height / 2 - this.txt_goals.textHeight / 2 - 6 * resolution; this.CountDownStart() }, this) } } ,this); this.bnt_tuto.frameName = "resumebnt" + resolution + ".png"; this.bnt_tuto.fixedToCamera = true; game.world.add(this.bnt_tuto); this.tuto_title = new Phaser.BitmapText(this.game,118 * resolution,205 * resolution,"fontc",text.txtTutorial,24 * resolution); this.tuto_title.align = "center"; this.tuto_title.fixedToCamera = true; game.world.add(this.tuto_title); if (game.device.desktop) this.tuto = new Phaser.BitmapText(this.game,0,0,"fontc",text.txttuto1_keyboard,24 * resolution); else this.tuto = new Phaser.BitmapText(this.game,0,0,"fontc",text.txttuto1,24 * resolution); this.tuto.align = "center"; this.tuto.updateText(); this.tuto.x = this.tuto_container.x - this.tuto.textWidth / 2; this.tuto.y = 245 * resolution; this.tuto.fixedToCamera = true; game.world.add(this.tuto) } else { game.time.events.add(500, function() { this.txt_countdown = game.add.bitmapText(0, 240 * resolution + game.camera.y, "fontOrg", "3", 50 * resolution); this.txt_countdown.updateText(); this.txt_countdown.x = game.camera.x + game.width / 2 - this.txt_countdown.textWidth / 2; this.txt_countdown.visible = false; this.objectif_container = game.add.sprite(game.camera.x, -game.height + game.camera.y, "sprites"); this.objectif_container.frameName = "objectif_container" + resolution + ".png"; this.txt_goals = game.add.bitmapText(0, 0, "fontc", text.txtGoals + ScoreGoal[play.numLevel - 1], 30 * resolution); this.txt_goals.updateText(); this.txt_goals.x = game.camera.x + game.width / 2 - this.txt_goals.textWidth / 2 + 20 * resolution; this.txt_goals.y = this.objectif_container.y + this.objectif_container.height / 2 - this.txt_goals.textHeight / 2 - 6 * resolution; this.CountDownStart() }, this) } this.createPause(); /*this.debug_key_1=game.input.keyboard.addKey(Phaser.Keyboard.NUMPAD_1);this.debug_key_2=game.input.keyboard.addKey(Phaser.Keyboard.NUMPAD_2);this.debug_key_3=game.input.keyboard.addKey(Phaser.Keyboard.NUMPAD_3);this.debug_key_4=game.input.keyboard.addKey(Phaser.Keyboard.NUMPAD_4);this.debug_key_5=game.input.keyboard.addKey(Phaser.Keyboard.NUMPAD_5);this.debug_key_1.onDown.add(this.unlock_award1,this);this.debug_key_2.onDown.add(this.unlock_award2,this);this.debug_key_3.onDown.add(this.unlock_award3,this);this.debug_key_4.onDown.add(this.unlock_award4,this);this.debug_key_5.onDown.add(this.unlock_award5,this)*/ }, unlock_award1: function() { var award = { award: "award1" }; GameAPI.Award.submit(award) }, unlock_award2: function() { var award = { award: "award2" }; GameAPI.Award.submit(award) }, unlock_award3: function() { var award = { award: "award3" }; GameAPI.Award.submit(award) }, unlock_award4: function() { var award = { award: "award4" }; GameAPI.Award.submit(award) }, unlock_award5: function() { var award = { award: "award5" }; GameAPI.Award.submit(award) }, initAtributs: function() { this.stateMusic = Music.enableMisic; this.timerEndLevel = null; this.timerEndLevelAndLose = null; this.istimerEndLevel = false; this.istimerEndLevelAndLose = false; this.gameOver = false; this.you_win = false; this.pausePlay = false; this.isEndAllLevels = false }, createButtonsPlay: function() { var pause_bnt_bg = game.add.sprite(0, 0, "sprites"); pause_bnt_bg.frameName = "pause_bnt_bg" + resolution + ".png"; pause_bnt_bg.x = game.width - pause_bnt_bg.width; pause_bnt_bg.fixedToCamera = true; this.bnt_pause = new Bouton(this.game,0,0,"sprites",this.funcPause,this); this.bnt_pause.frameName = "pausebnt" + resolution + ".png"; this.bnt_pause.x = 292 * resolution; this.bnt_pause.y = 25 * resolution; this.bnt_pause.fixedToCamera = true; this.game.world.add(this.bnt_pause) }, game_over: function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("whoosh"); this.gameOver = true; this.bnt_pause.visible = false; this.bg_noire.visible = true; this.groupPause.forEachAlive(function(obj) { obj.visible = true }, this); this.bnt_music.visible = false; this.resumebtn.visible = false; this.menubntt.fixedToCamera = false; this.bnt_replay.fixedToCamera = false; this.menubntt.x = 118 * resolution; this.bnt_replay.x = this.menubntt.x + 82 * resolution; this.bnt_replay.y = this.menubntt.y = 285 * resolution; this.menubntt.fixedToCamera = true; this.bnt_replay.fixedToCamera = true; this.textPause.setText(text.txtgameover); this.textPause.fixedToCamera = false; this.textPause.x = 100 * resolution; this.textPause.y = this.textPause.cameraOffset.y; this.textPause.fixedToCamera = true; this.groupPause.y = 400 * resolution; game.world.bringToTop(this.bg_noire); game.world.bringToTop(this.groupPause); this.groupPause.setAll("alpha", 0); game.add.tween(this.groupPause).to({ y: -50 * resolution }, 350, Phaser.Easing.Quadratic.Out, false, 100).to({ y: -35 * resolution }, 200, Phaser.Easing.Quadratic.Out, false, 70).start().onComplete.add(function() { GameAPI.GameBreak.request(this.Spil_pause, this.Spil_resume) }, this); game.world.bringToTop(this.bg_noire); game.world.bringToTop(this.groupPause); this.groupPause.forEach(function(obj) { game.add.tween(obj).to({ alpha: 1 }, 600, Phaser.Easing.Quadratic.Out, true, 150) }, this) }, createPause: function() { this.bgPause = new Phaser.Sprite(this.game,0,0,"sprites"); this.bgPause.frameName = "bgPause" + resolution + ".png"; this.bgPause.x = game.width / 2; this.bgPause.y = 255 * resolution; this.bgPause.anchor.setTo(.5, .5); this.bgPause.alive = true; this.bgPause.fixedToCamera = true; this.bnt_music = new Bouton(this.game,80 * resolution,285 * resolution,"sprites",this.actionMusic,this); this.bnt_music.frameName = "musicbnt" + resolution + ".png"; this.bnt_music.alive = true; this.bnt_music.fixedToCamera = true; this.menubntt = new Bouton(this.game,this.bnt_music.x + 55 * resolution,285 * resolution,"sprites",this.funcBack,this); this.menubntt.frameName = "levelsbnt" + resolution + ".png"; this.menubntt.alive = true; this.menubntt.fixedToCamera = true; this.bnt_replay = new Bouton(this.game,this.menubntt.x + 55 * resolution,285 * resolution,"sprites",this.funReplay,this); this.bnt_replay.frameName = "replaybnt" + resolution + ".png"; this.bnt_replay.alive = true; this.bnt_replay.fixedToCamera = true; this.resumebtn = new Bouton(this.game,this.bnt_replay.x + 55 * resolution,285 * resolution,"sprites",this.funcResume,this); this.resumebtn.frameName = "resumebnt" + resolution + ".png"; this.resumebtn.alive = true; this.resumebtn.fixedToCamera = true; this.groupPause = this.game.add.group(); this.groupPause.add(this.bgPause); this.groupPause.add(this.bnt_music); this.groupPause.add(this.resumebtn); this.groupPause.add(this.menubntt); this.groupPause.add(this.bnt_replay); this.textPause = new Phaser.BitmapText(this.game,120 * resolution,223 * resolution,"fontc",text.txtPause,26 * resolution); this.textPause.alive = true; this.textPause.fixedToCamera = true; this.textPause.align = "center"; this.textPauseLevel = new Phaser.BitmapText(this.game,130 * resolution,188 * resolution,"fontc",text.txtlevel + " " + play.numLevel,24 * resolution); this.textPauseLevel.alive = true; this.textPauseLevel.fixedToCamera = true; this.groupPause.add(this.textPause); this.groupPause.add(this.textPauseLevel); if (GameAPI.Branding.getLogo().image) { var spil_logo = new Bouton(this.game,0,0,"logo_spil",GameAPI.Branding.getLogo().action,this); spil_logo.x = game.width / 2; spil_logo.y = this.bgPause.y + this.bgPause.height / 2 + 5 * resolution; spil_logo.fixedToCamera = true; this.groupPause.add(spil_logo) } this.groupPause.forEachAlive(function(obj) { obj.visible = false }, this); this.groupPause.y = 400 * resolution }, createCongratulations: function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("whoosh"); this.isEndAllLevels = true; this.numLevel = nombre_levels; level = sauvegarde.length - 1; Save_setItem("candycar_level", sauvegarde.length - 1); var bgnoire = this.game.add.sprite(0, 0, "bgnoire"); bgnoire.alpha = .7; bgnoire.fixedToCamera = true; var container = this.game.add.sprite(game.width / 2, 245 * resolution, "sprites"); container.frameName = "bgPause" + resolution + ".png"; container.anchor.setTo(.5, .5); container.fixedToCamera = true; var b = new Bouton(this.game,160 * resolution,330 * resolution,"sprites",function() { play.InitialiseFade("menu") } ,this); b.frameName = "resumebnt" + resolution + ".png"; b.fixedToCamera = true; var tt = new Phaser.BitmapText(this.game,113 * resolution,178 * resolution,"fontc",text.textCongratulations,24 * resolution); tt.align = "center"; tt.fixedToCamera = true; var tt2 = new Phaser.BitmapText(this.game,65 * resolution,220 * resolution,"fontc",text.textAllLevels,24 * resolution); tt2.align = "center"; tt2.fixedToCamera = true; this.world.add(tt); this.world.add(tt2); this.world.add(b) }, createNextLevel: function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("whoosh"); game.time.events.add(100, function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("win") }, this); this.you_win = true; this.bnt_pause.visible = false; this.next_level = new Bouton(this.game,75 * resolution,285 * resolution,"sprites",this.funcnextlevel,this); this.next_level.frameName = "resumebnt" + resolution + ".png"; this.next_level.alive = true; this.bg_noire.visible = true; this.groupNexLevel = this.game.add.group(); this.menubntt.fixedToCamera = false; this.bnt_replay.fixedToCamera = false; this.next_level.x = this.resumebtn.x - game.camera.x - 20 * resolution; this.bnt_replay.x = this.next_level.x - 60 * resolution; this.menubntt.x = this.bnt_replay.x - 60 * resolution; this.menubntt.y = this.bnt_replay.y = this.next_level.y; this.next_level.fixedToCamera = true; this.bnt_replay.fixedToCamera = true; this.menubntt.fixedToCamera = true; this.etoilEnd1 = new Phaser.Sprite(this.game,118 * resolution + game.camera.x,(145 + 150) * resolution + game.camera.y,"sprites"); this.etoilEnd1.frameName = "etoile" + resolution + ".png"; this.etoilEnd1.alive = true; this.etoilEnd1.alpha = 0; this.etoilEnd1.scale.setTo(.85, .85); this.etoilEnd1.anchor.setTo(.5, .5); this.etoilEnd2 = new Phaser.Sprite(this.game,163 * resolution + game.camera.x,(135 + 150) * resolution + game.camera.y,"sprites"); this.etoilEnd2.frameName = "etoile" + resolution + ".png"; this.etoilEnd2.alive = true; this.etoilEnd2.alpha = 0; this.etoilEnd2.anchor.setTo(.5, .5); this.etoilEnd3 = new Phaser.Sprite(this.game,208 * resolution + game.camera.x,(145 + 150) * resolution + game.camera.y,"sprites"); this.etoilEnd3.frameName = "etoile" + resolution + ".png"; this.etoilEnd3.alive = true; this.etoilEnd3.alpha = 0; this.etoilEnd3.scale.setTo(.85, .85); this.etoilEnd3.anchor.setTo(.5, .5); this.record_container = new Phaser.Sprite(game,this.bgPause.x,this.bgPause.y,"sprites"); this.record_container.frameName = "record_container" + resolution + ".png"; this.record_container.anchor.setTo(.5, .5); this.groupNexLevel.add(this.etoilEnd1); this.groupNexLevel.add(this.etoilEnd2); this.groupNexLevel.add(this.etoilEnd3); this.groupNexLevel.add(this.record_container); this.groupNexLevel.add(this.bgPause); this.groupNexLevel.add(this.next_level); this.groupNexLevel.add(this.menubntt); this.groupNexLevel.add(this.bnt_replay); var delay_stars = 400; if (this.number_etoiles >= 1) { game.add.tween(this.etoilEnd1).to({ y: 115 * resolution + game.camera.y, alpha: 1 }, 400, Phaser.Easing.Quadratic.Out, false, delay_stars).start().onComplete.add(function() { game.add.tween(this).to({ y: 145 * resolution + game.camera.y }, 700, Phaser.Easing.Quadratic.Out).start(); game.add.tween(this.scale).to({ x: 0 }, 150, Phaser.Easing.Quadratic.In).to({ x: .85 }, 150, Phaser.Easing.Quadratic.None).to({ x: 0 }, 150, Phaser.Easing.Quadratic.None).to({ x: .85 }, 150, Phaser.Easing.Quadratic.Out).start() }, this.etoilEnd1) } if (this.number_etoiles >= 2) { game.add.tween(this.etoilEnd2).to({ y: 105 * resolution + game.camera.y, alpha: 1 }, 400, Phaser.Easing.Quadratic.Out, false, delay_stars + 200).start().onComplete.add(function() { game.add.tween(this).to({ y: 135 * resolution + game.camera.y }, 700, Phaser.Easing.Quadratic.Out).start(); game.add.tween(this.scale).to({ x: 0 }, 150, Phaser.Easing.Quadratic.In).to({ x: 1 }, 150, Phaser.Easing.Quadratic.None).to({ x: 0 }, 150, Phaser.Easing.Quadratic.None).to({ x: 1 }, 150, Phaser.Easing.Quadratic.Out).start() }, this.etoilEnd2) } if (this.number_etoiles >= 3) { game.add.tween(this.etoilEnd3).to({ y: 115 * resolution + game.camera.y, alpha: 1 }, 400, Phaser.Easing.Quadratic.Out, false, delay_stars + 400).start().onComplete.add(function() { game.add.tween(this).to({ y: 145 * resolution + game.camera.y }, 700, Phaser.Easing.Quadratic.Out).start(); game.add.tween(this.scale).to({ x: 0 }, 150, Phaser.Easing.Quadratic.In).to({ x: .85 }, 150, Phaser.Easing.Quadratic.None).to({ x: 0 }, 150, Phaser.Easing.Quadratic.None).to({ x: .85 }, 150, Phaser.Easing.Quadratic.Out).start() }, this.etoilEnd3) } this.txt_score_win = new Phaser.BitmapText(this.game,0,188 * resolution,"fontc","" + this.current_score,24 * resolution); this.txt_score_win.align = "center"; this.txt_score_win.alive = true; this.txt_score_win.updateText(); this.txt_score_win.x = game.width / 2 - this.txt_score_win.textWidth / 2; this.txt_score_win.fixedToCamera = true; this.groupNexLevel.add(this.txt_score_win); var tt = new Phaser.BitmapText(this.game,110 * resolution,223 * resolution,"fontc",text.youwin,27 * resolution); tt.align = "center"; tt.alive = true; tt.fixedToCamera = true; this.groupNexLevel.add(tt); if (GameAPI.Branding.getLogo().image) { var spil_logo = new Bouton(this.game,0,0,"logo_spil",GameAPI.Branding.getLogo().action,this); spil_logo.x = game.width / 2; spil_logo.y = game.height / 2 + 180 * resolution; spil_logo.fixedToCamera = true; this.groupNexLevel.add(spil_logo) } this.groupNexLevel.y = 400 * resolution; this.groupNexLevel.forEach(function(obj) { if (obj != this.etoilEnd1 && obj != this.etoilEnd2 && obj != this.etoilEnd3) obj.alpha = 0 }, this); game.add.tween(this.groupNexLevel).to({ y: -50 * resolution }, 350, Phaser.Easing.Quadratic.Out, false, 100).to({ y: -35 * resolution }, 200, Phaser.Easing.Quadratic.Out, false, 70).start().onComplete.add(function() { GameAPI.GameBreak.request(this.Spil_pause, this.Spil_resume) }, this); game.time.events.add(750, function() { var txt_best = new Phaser.BitmapText(this.game,0,0,"fontc",text.txtBest + " " + play.current_score,24 * resolution); txt_best.align = "center"; txt_best.alive = true; txt_best.updateText(); txt_best.x = game.camera.x + game.width / 2 - txt_best.textWidth / 2; txt_best.y = this.record_container.y - txt_best.textHeight / 2 - 5 * resolution; txt_best.alpha = 0; this.groupNexLevel.add(txt_best); if (play.current_score > sauvegarde[play.numLevel - 1].bestscore) { sauvegarde[play.numLevel - 1].bestscore = play.current_score; save_ecrit(); this.txt_best_score = new Phaser.BitmapText(this.game,0,0,"fontc","" + text.txtBestScore,24 * resolution); this.txt_best_score.align = "center"; this.txt_best_score.alive = true; this.txt_best_score.updateText(); this.txt_best_score.x = game.camera.x + game.width / 2 - this.txt_best_score.textWidth / 2; this.txt_best_score.y = this.record_container.y - this.txt_best_score.textHeight / 2 - 15 * resolution; this.txt_best_score.alpha = 0; txt_best.y = this.record_container.y - txt_best.textHeight / 2 - 12 * resolution; this.groupNexLevel.add(this.txt_best_score); game.add.tween(this.txt_best_score).to({ y: this.txt_best_score.y + 130 * resolution, alpha: 1 }, 350, Phaser.Easing.Quadratic.None).start().onComplete.add(function() { var emitter = game.add.emitter(this.txt_best_score.x + this.txt_best_score.textWidth / 2, this.txt_best_score.y - this.txt_best_score.textHeight, 80); emitter.makeParticles("etoile"); emitter.setRotation(0, 360); emitter.setAlpha(1, .5, 500, Phaser.Easing.Linear.None); emitter.setScale(.5, .2, 500, Phaser.Easing.Linear.None); emitter.minParticleSpeed.setTo(-250, -250); emitter.maxParticleSpeed.setTo(250, 250); emitter.gravity = 300; emitter.start(true, 1500, 80, 80) }, this) } else { txt_best.setText(text.txtBest + " " + sauvegarde[play.numLevel - 1].bestscore); txt_best.updateText(); txt_best.x = game.camera.x + game.width / 2 - txt_best.textWidth / 2; txt_best.y = this.record_container.y - txt_best.textHeight / 2 - 5 * resolution } game.add.tween(this.record_container).to({ y: this.record_container.y + 110 * resolution }, 350, Phaser.Easing.Quadratic.None).start(); game.add.tween(txt_best).to({ y: txt_best.y + 110 * resolution, alpha: 1 }, 350, Phaser.Easing.Quadratic.None).start() }, this); game.world.bringToTop(this.bg_noire); game.world.bringToTop(this.groupNexLevel); this.groupNexLevel.forEach(function(obj) { if (obj.frameName != "etoile" + resolution + ".png") game.add.tween(obj).to({ alpha: 1 }, 600, Phaser.Easing.Quadratic.Out, true, 150) }, this); this.groupNexLevel.forEachAlive(function(obj) { obj.visible = true }, this) }, Spil_pause: function() { play.pausePlay = true; if (play.stateMusic) { Music.enableMisic = false; Music.music.pause(); Music.sounds.pause() } game.paused = true }, Spil_resume: function() { play.pausePlay = false; if (play.stateMusic) { Music.enableMisic = true; Music.music.resume(); Music.sounds.resume() } game.paused = false }, funcnextlevel: function() { if (this.numLevel <= nombre_levels) this.numLevel++; if (play.numLevel > 10) play.InitialiseFade("play"); else play.InitialiseFade("levels") }, cacherPause: function() { this.bnt_pause.visible = false; this.groupPause.forEachAlive(function(obj) { obj.visible = true }, this); this.bg_noire.visible = true }, funcPause: function() { if (this.istimerEndLevel || this.istimerEndLevelAndLose || this.isEndAllLevels || !this.GameStart) return; if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("whoosh"); this.ispause_music = true; if (this.stateMusic) { Music.enableMisic = false; Music.music.pause() } this.cacherPause(); this.pausePlay = true; this.groupPause.setAll("alpha", 0); game.add.tween(this.groupPause).to({ y: -50 * resolution }, 350, Phaser.Easing.Quadratic.Out, true, 100).to({ y: -35 * resolution }, 200, Phaser.Easing.Quadratic.Out, true, 70); game.world.bringToTop(this.bg_noire); game.world.bringToTop(this.groupPause); this.groupPause.forEach(function(obj) { game.add.tween(obj).to({ alpha: 1 }, 600, Phaser.Easing.Quadratic.Out, true, 150) }, this); if (this.stateMusic) { this.bnt_music.frameName = "musicbnt" + resolution + ".png" } else { this.bnt_music.frameName = "Mutemusicbnt" + resolution + ".png" } game.input.onUp.active = false; this.car.current_speedX = this.car.body.velocity.x; this.car.current_speedY = this.car.body.velocity.y; this.car.body.velocity.x = this.car.body.velocity.y = 0; this.group_enemies.forEachAlive(function(car_enemy) { car_enemy.current_speedX = car_enemy.body.velocity.x; car_enemy.current_speedY = car_enemy.body.velocity.y; car_enemy.body.velocity.x = car_enemy.body.velocity.y = 0 }, this) }, funcResume: function() { if (this.stateMusic) { this.ispause_music = false; Music.enableMisic = true; Music.music.resume() } this.afficherPause(); game.time.events.add(300, function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("whoosh") }, this); game.add.tween(this.groupPause).to({ y: -50 * resolution }, 350, Phaser.Easing.Quadratic.Out, true, 100).to({ y: 400 * resolution }, 300, Phaser.Easing.Quadratic.Out, true).onComplete.add(function() { this.pausePlay = false; this.bg_noire.visible = false; this.car.body.velocity.x = this.car.current_speedX; this.car.body.velocity.y = this.car.current_speedY; this.group_enemies.forEachAlive(function(car_enemy) { car_enemy.body.velocity.x = car_enemy.current_speedX; car_enemy.body.velocity.y = car_enemy.current_speedY }, this) }, this); this.groupPause.forEach(function(obj) { game.add.tween(obj).to({ alpha: 0 }, 600, Phaser.Easing.Quadratic.Out, true, 400) }, this); game.input.onUp.active = true }, afficherPause: function() { this.bnt_pause.visible = true }, funReplay: function() { window['uptap'].ShowScreenVideo("重新开始",()=>{}); if (this.stateMusic && this.pausePlay) { Music.enableMisic = true; Music.music.resume() } play.InitialiseFade("play") }, funcBack: function() { if (this.stateMusic) { Music.enableMisic = true; Music.music.resume() } play.InitialiseFade("levels") }, calculer_etoiles: function() { this.number_etoiles = 0; if (this.current_score >= ScoreGoal[play.numLevel - 1] + 50) { this.number_etoiles = 3 } else if (this.current_score >= ScoreGoal[play.numLevel - 1] + 30) { this.number_etoiles = 2 } else if (this.current_score >= ScoreGoal[play.numLevel - 1] + 10) { this.number_etoiles = 1 } }, Fin_level: function() { play.calculer_etoiles(); play.createNextLevel(); if (this.numLevel > level && this.numLevel < nombre_levels) { level = this.numLevel; Save_setItem("candycar_level", level); move_car_level = true } if (play.number_etoiles > sauvegarde[play.numLevel - 1].numetoile) { sauvegarde[play.numLevel - 1].numetoile = play.number_etoiles } save_ecrit(); var nbr_etoiles = 0; for (var i = 0; i < this.numLevel; i++) { nbr_etoiles += sauvegarde[i].numetoile } if (nbr_etoiles >= 3 && !vect_awards[0]) { vect_awards[0] = true; var award = { award: "award1" }; GameAPI.Award.submit(award) } else if (nbr_etoiles >= 10 && !vect_awards[1]) { vect_awards[1] = true; var award = { award: "award2" }; GameAPI.Award.submit(award) } else if (nbr_etoiles >= 15 && !vect_awards[2]) { vect_awards[2] = true; var award = { award: "award3" }; GameAPI.Award.submit(award) } else if (nbr_etoiles >= 20 && !vect_awards[3]) { vect_awards[3] = true; var award = { award: "award4" }; GameAPI.Award.submit(award) } else if (nbr_etoiles == 30 && !vect_awards[4]) { vect_awards[4] = true; var award = { award: "award5" }; GameAPI.Award.submit(award) } GameAPI.Score.submit(this.current_score) }, update: function() { if (!this.GameStart) return; if (this.you_win && this.groupNexLevel.y > 0) { this.groupNexLevel.y -= 15 } if (this.gameOver || this.you_win || this.pausePlay) return; if (this.isEndAllLevels) return; if (this.istimerEndLevel && this.timerEndLevel != null) { this.timerEndLevel -= this.game.time.elapsed; if (this.timerEndLevel < 0) { this.istimerEndLevel = false; this.Fin_level() } } if (this.istimerEndLevelAndLose && this.timerEndLevelAndLose != null) { if (this.current_score >= ScoreGoal[play.numLevel - 1]) { this.istimerEndLevelAndLose = false; this.timerEndLevelAndLose = null; this.istimerEndLevel = true; this.timerEndLevel = 800 } else { this.timerEndLevelAndLose -= this.game.time.elapsed; if (this.timerEndLevelAndLose < 0) { this.game_over(); this.istimerEndLevelAndLose = false } } } if (this.car.body.velocity.x != 0 && (this.istimerEndLevel || this.istimerEndLevelAndLose || this.gameOver || this.you_win || this.pausePlay)) { this.car.current_speedX = this.car.body.velocity.x; this.car.current_speedY = this.car.body.velocity.y; this.car.body.velocity.x = this.car.body.velocity.y = 0; this.group_enemies.forEachAlive(function(car_enemy) { car_enemy.current_speedX = car_enemy.body.velocity.x; car_enemy.current_speedY = car_enemy.body.velocity.y; car_enemy.body.velocity.x = car_enemy.body.velocity.y = 0 }, this); return } if (this.bonus_timer >= 0) { this.bonus_timer -= this.game.time.elapsed } if (this.bonus_time >= 0 && this.bonus_timer < 0) { if (this.bonus_time != 0) { if (this.bonus_time == 120 || this.bonus_time == 60) { this.minutes--; this.secondss = 59; this.txt_time_game.setText(this.minutes + ":" + this.secondss); this.txt_time_game.updateText(); this.txt_time_game.x = this.txt_time_word.x + this.txt_time_word.textWidth / 2 - this.txt_time_game.textWidth / 2 } else { this.secondss--; if (this.secondss < 10) this.txt_time_game.setText(this.minutes + ":0" + this.secondss); else this.txt_time_game.setText(this.minutes + ":" + this.secondss); this.txt_time_game.updateText(); this.txt_time_game.x = this.txt_time_word.x + this.txt_time_word.textWidth / 2 - this.txt_time_game.textWidth / 2 } this.bonus_time--; this.bonus_timer = 1e3 } else { this.bonus_time--; this.txt_time_game.setText("0:00"); this.txt_time_game.updateText(); this.txt_time_game.x = this.txt_time_word.x + this.txt_time_word.textWidth / 2 - this.txt_time_game.textWidth / 2; if (play.current_score >= ScoreGoal[play.numLevel - 1]) { play.timerEndLevel = 800; play.istimerEndLevel = true } else { this.timerEndLevelAndLose = 800; this.istimerEndLevelAndLose = true } } } if (this.car.body.velocity.x == 0 && this.car.body.velocity.y == 0 && (this.istimerEndLevel || this.istimerEndLevelAndLose || this.gameOver || this.you_win || this.pausePlay)) return; if (!this.car.isTouchedMap && !this.car.isTouchedCar) { if (game.input.activePointer.isDown || this.cursors.right.isDown || this.cursors.left.isDown) { if (game.input.activePointer.isDown) { if (game.input.activePointer.x > game.width / 2) { this.car.angle += this.car.CurveAngle } else { this.car.angle -= this.car.CurveAngle } } else if (this.cursors.right.isDown) { this.car.angle += this.car.CurveAngle } else if (this.cursors.left.isDown) { this.car.angle -= this.car.CurveAngle } if (this.car.speed > this.car.TapMinSpeed) { this.car.speed -= this.car.TapRateSlowerSpeed } if (game.device.desktop) { game.time.events.add(150, function() { var freins = this.group_freins.getFirstDead(); if (freins != null) { freins.reset(this.car.x, this.car.y) } else { freins = game.add.sprite(this.car.x, this.car.y, "breaks", 9) } freins.anchor.setTo(.5, .5); freins.rotation = this.car.rotation; freins.animations.add("break", [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); freins.animations.play("break", 5, false, true); this.group_freins.add(freins) }, this) } } else { if (this.car.speed < this.car.MaxSpeed) { this.car.speed += this.car.RateFasterSpeed } } this.car.body.velocity.x = Math.cos(this.car.rotation) * this.car.speed; this.car.body.velocity.y = Math.sin(this.car.rotation) * this.car.speed } else { if (this.car.isTouchedMap) { if (this.car.speed > this.car.MapMaxSpeed) { this.car.speed -= this.car.MapRateSlowerSpeed } else { this.car.isTouchedMap = false; this.car.isTouchedCar = false; this.car.speed = this.car.MapNewSpeed } if (!(game.input.activePointer.isDown || this.cursors.right.isDown || this.cursors.left.isDown)) { if (this.car.x > game.world.width / 2) { this.car.angle += this.car.MapAngle } else { this.car.angle -= this.car.MapAngle } } else { if (game.input.activePointer.isDown) { if (game.input.activePointer.x > game.width / 2) { this.car.angle += this.car.CurveAngle } else { this.car.angle -= this.car.CurveAngle } } else if (this.cursors.right.isDown) { this.car.angle += this.car.CurveAngle } else if (this.cursors.left.isDown) { this.car.angle -= this.car.CurveAngle } } this.car.body.velocity.x = Math.cos(this.car.rotation) * this.car.speed; this.car.body.velocity.y = Math.sin(this.car.rotation) * this.car.speed } if (this.car.isTouchedCar) { if (this.car.speed > this.car.CarMaxSpeed) { this.car.speed -= this.car.CarRateSlowerSpeed } else { this.car.isTouchedCar = false; this.car.isTouchedMap = false; this.car.speed = this.car.CarNewSpeed } this.car.body.velocity.x = Math.cos(this.car.rotation) * this.car.speedX; this.car.body.velocity.y = Math.sin(this.car.rotation) * this.car.speedY } } this.group_enemies.forEachAlive(function(car_enemy) { if (car_enemy.frameName != "car_enemy_ice" + resolution + ".png") { if (!car_enemy.isTouchedMap && !car_enemy.isTouchedCar && car_enemy.tw_collide == null) { if (car_enemy.speed < car_enemy.MaxSpeed) { car_enemy.speed += car_enemy.RateFasterSpeed } car_enemy.body.velocity.x = Math.cos(car_enemy.rotation) * car_enemy.speed; car_enemy.body.velocity.y = Math.sin(car_enemy.rotation) * car_enemy.speed } else { if (car_enemy.isTouchedMap) { if (car_enemy.speed > car_enemy.MapMaxSpeed) { car_enemy.speed -= car_enemy.MapRateSlowerSpeed } else { car_enemy.isTouchedMap = false; car_enemy.isTouchedCar = false; car_enemy.speed = car_enemy.MapNewSpeed } if (car_enemy.x > game.world.width / 2) car_enemy.angle += car_enemy.MapAngle; else car_enemy.angle -= car_enemy.MapAngle; car_enemy.body.velocity.x = Math.cos(car_enemy.rotation) * car_enemy.speed; car_enemy.body.velocity.y = Math.sin(car_enemy.rotation) * car_enemy.speed } if (car_enemy.isTouchedCar) { if (car_enemy.speed > car_enemy.CarMaxSpeed) { car_enemy.speed -= car_enemy.CarRateSlowerSpeed } else { car_enemy.isTouchedCar = false; car_enemy.isTouchedMap = false; if (car_enemy.tw_collide == null) car_enemy.speed = car_enemy.CarNewSpeed; else car_enemy.speed = 0 } if (car_enemy.x > game.world.width / 2) car_enemy.angle += car_enemy.MapAngle; else car_enemy.angle -= car_enemy.MapAngle; car_enemy.body.velocity.x = Math.cos(car_enemy.rotation) * car_enemy.speedX; car_enemy.body.velocity.y = Math.sin(car_enemy.rotation) * car_enemy.speedY } } if (car_enemy.StartFollow == 0) { var dist_car = Math.sqrt((this.car.x - car_enemy.x) * (this.car.x - car_enemy.x) + (this.car.y - car_enemy.y) * (this.car.y - car_enemy.y)); if (Math.abs(dist_car) < 200 * resolution) { car_enemy.StartFollow = 1 } } else if (car_enemy.StartFollow == 1) { game.time.events.add(500, function() { var rnd_index = Math.floor(Math.random() * 4.9); var new_angle = Phaser.Math.angleBetween(this.x, this.y, play.car.x + play.vect_zones[rnd_index].x, play.car.y + play.vect_zones[rnd_index].y); game.add.tween(this).to({ rotation: new_angle }, 600, Phaser.Easing.Linear.None).start().onComplete.add(function() { this.StartFollow = 1 }, this); this.StartFollow = 2 }, car_enemy) } } game.physics.arcade.collide(car_enemy, this.layer, this.CollisionMap, null, car_enemy); game.physics.arcade.collide(car_enemy, this.group_enemies); if (this.car.tw_collide == null) game.physics.arcade.collide(car_enemy, this.car, this.CollisionCar, null, car_enemy) }, this); game.physics.arcade.collide(this.car, this.layer, this.CollisionMap, null, this.car); this.group_objects.forEachAlive(function(object) { game.physics.arcade.overlap(this.car, object, this.CollisionObject, null, object) }, this); if (this.shield_sprite != null) { this.shield_sprite.x = this.car.x; this.shield_sprite.y = this.car.y } }, InitialiseFade: function(state) { if (play.bgnoire == null) play.bgnoire = game.add.image(0, 0, "bgnoire"); play.bgnoire.fixedToCamera = true; play.bgnoire.alpha = 0; game.add.tween(play.bgnoire).to({ alpha: 1 }, 500, Phaser.Easing.Linear.None, true).onComplete.add(function() { game.time.events.add(100, function() { game.state.start(this, true); play.bgnoire.alpha = 0; play.bgnoire.kill(); play.bgnoire = null }, this) }, state) }, CollisionMap: function() { if (this.isTouchedMap) return; this.isTouchedMap = true; this.isTouchedCar = false; if (this.frameName == "car" + resolution + ".png") { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("collision_map"); var ang = this.angle; if (ang < 0) ang = this.angle + 360; if (Phaser.Rectangle.intersects(play.car.body, play.upLine.getBounds())) { if (ang >= 180 && ang <= 360) { this.speed = -50 * resolution } else { this.isTouchedMap = false; this.speed = 50 * resolution } } else if (Phaser.Rectangle.intersects(play.car.body, play.downLine.getBounds())) { if (this.angle >= 0 && this.angle <= 180) { this.speed = -50 * resolution } else { this.isTouchedMap = false; this.speed = 50 * resolution } } else if (Phaser.Rectangle.intersects(play.car.body, play.rightLine.getBounds())) { if (ang >= 270 && ang <= 360 || ang >= 0 && ang <= 90) { this.speed = -50 * resolution } else { this.isTouchedMap = false; this.speed = 50 * resolution } } else if (Phaser.Rectangle.intersects(play.car.body, play.leftLine.getBounds())) { if (ang >= 90 && ang <= 270) { this.speed = -50 * resolution } else { this.isTouchedMap = false; this.speed = 50 * resolution } } else { if (this.speed >= 0) this.speed = -50 * resolution } } else { this.speed = -50 * resolution } if (this.frameName != "car" + resolution + ".png" && this.StartFollow != 0) { var rnd_index = Math.floor(Math.random() * 4.9); var new_angle = Phaser.Math.angleBetween(this.x, this.y, play.car.x + play.vect_zones[rnd_index].x, play.car.y + play.vect_zones[rnd_index].y); game.add.tween(this).to({ rotation: new_angle }, 600, Phaser.Easing.Linear.None).start() } }, CollisionCar: function() { if (this.isTouchedCar) return; this.isTouchedCar = true; this.speed = -80 * resolution; play.car.isTouchedCar = true; play.car.speed = -80 * resolution; if (this.frameName != "car" + resolution + ".png") { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("car_hit"); play.car.speedX = -150 * resolution; if (this.y > play.car.y) { if (play.car.rotation > 0) { play.car.speedY = -150 * resolution } else { play.car.speedY = 150 * resolution } } else { if (play.car.rotation > 0) { play.car.speedY = 150 * resolution } else { play.car.speedY = -150 * resolution } } if (this.frameName != "car_enemy_ice" + resolution + ".png") { this.speedX = -120 * resolution; if (play.car.y > this.y) { if (this.rotation > 0) { this.speedY = -120 * resolution } else { this.speedY = 120 * resolution } } else { if (this.rotation > 0) { this.speedY = 120 * resolution } else { this.speedY = -120 * resolution } } } if (play.shield_sprite != null || this.frameName == "car_enemy_ice" + resolution + ".png") { game.add.tween(this.scale).to({ x: .8, y: 1.2 }, 250, Phaser.Easing.Quadratic.Out).to({ x: 1.2, y: .8 }, 250, Phaser.Easing.Quadratic.Out).to({ x: 1, y: 1 }, 200, Phaser.Easing.Quadratic.Out).start(); if (this.tw_collide == null) { this.tw_collide = game.add.tween(this).to({ alpha: .5 }, 70, Phaser.Easing.Linear.None).to({ alpha: .9 }, 70, Phaser.Easing.Linear.None); this.tw_collide.loop(); this.tw_collide.start(); game.time.events.add(750, function() { this.tw_collide.pause(); this.tw_collide.pendingDelete = true; this.tw_collide = null; if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("bomb"); this.kill(); play.AnimationKillCar(this.x, this.y); play.CreateObject(this.x, this.y, 1, true); play.creer_text_score(this); game.time.events.add(3e3, function() { play.CreateCarEnemy(this.ind_i, this.ind_j) }, this) }, this) } } } if (play.shield_sprite == null && this.frameName != "car_enemy_ice" + resolution + ".png") { play.CameraShake(); game.add.tween(play.car.scale).to({ x: .8, y: 1.2 }, 250, Phaser.Easing.Quadratic.Out).to({ x: 1.2, y: .8 }, 250, Phaser.Easing.Quadratic.Out).to({ x: 1, y: 1 }, 200, Phaser.Easing.Quadratic.Out).start(); if (play.car.tw_collide == null) { play.car.tw_collide = game.add.tween(play.car).to({ alpha: .5 }, 70, Phaser.Easing.Linear.None).to({ alpha: .9 }, 70, Phaser.Easing.Linear.None); play.car.tw_collide.loop(); play.car.tw_collide.start(); game.time.events.add(1500, function() { play.car.tw_collide.pause(); play.car.tw_collide.pendingDelete = true; play.car.tw_collide = null; play.car.alpha = 1 }, play) } if (play.current_score > 0) { var nbr_money = 0; if (play.current_score >= 30) { nbr_money = Math.floor(Math.random() * 2.9 + 1) } else if (play.current_score >= 20) { nbr_money = Math.floor(Math.random() * 1.9 + 1) } else if (play.current_score >= 10) { nbr_money = 1 } for (var m = 0; m < nbr_money; m++) { play.current_score -= 10; play.txt_score.setText("" + play.current_score); play.txt_score.updateText(); play.txt_score.x = play.txt_score_word.x + play.txt_score_word.textWidth / 2 - play.txt_score.textWidth / 2; play.CreateObject(play.car.x, play.car.y, 1, true) } } } }, CollisionObject: function() { if (this.ind == 1) { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("collect_coin"); play.current_score += 10; play.txt_score.setText("" + play.current_score); play.txt_score.updateText(); play.txt_score.x = play.txt_score_word.x + play.txt_score_word.textWidth / 2 - play.txt_score.textWidth / 2; this.kill(); play.AnimationGetObject(this.x, this.y); play.creer_text_score(this); if (this.frame == 1) play.NewObject(this) } else if (this.ind == 2) { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("collect_powerup"); this.kill(); play.AnimationGetObject(this.x, this.y); if (play.shield_sprite != null) return; play.shield_sprite = new Phaser.Sprite(game,play.car.x,play.car.y,"sprites"); play.group_objects_top.addAt(play.shield_sprite, 0); play.shield_sprite.frameName = "shield_sprite" + resolution + ".png"; play.shield_sprite.anchor.setTo(.5, .5); play.shield_sprite.tw_collide = null; game.time.events.add(8e3, function() { if (play.shield_sprite != null) { if (play.shield_sprite.tw_collide == null) { play.shield_sprite.tw_collide = game.add.tween(play.shield_sprite).to({ alpha: .2 }, 100, Phaser.Easing.Linear.None).to({ alpha: .9 }, 100, Phaser.Easing.Linear.None); play.shield_sprite.tw_collide.loop(); play.shield_sprite.tw_collide.start() } } }, this); game.time.events.add(1e4, function() { play.shield_sprite.tw_collide.pause(); play.shield_sprite.tw_collide.pendingDelete = true; play.shield_sprite.tw_collide = null; play.shield_sprite.alpha = 1; play.shield_sprite.destroy(); play.shield_sprite = null; play.NewObject(this) }, this) } else if (this.ind == 3) { this.kill(); play.AnimationGetObject(this.x, this.y); if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("frozen"); if (game.device.desktop) { var bgwhite = game.add.sprite(0, 0, "bgwhite"); bgwhite.alpha = 0; bgwhite.fixedToCamera = true; game.add.tween(bgwhite).to({ alpha: .8 }, 200, Phaser.Easing.Quadratic.None).to({ alpha: 0 }, 200, Phaser.Easing.Quadratic.Out).start(); game.time.events.add(400, function() { this.destroy() }, bgwhite) } play.group_enemies.forEachAlive(function(car_enemy) { car_enemy.animations.paused = true; car_enemy.loadTexture("sprites"); car_enemy.frameName = "car_enemy_ice" + resolution + ".png"; car_enemy.speed = 0; car_enemy.body.velocity.x = 0; car_enemy.body.velocity.y = 0; game.time.events.add(1e4, function() { if (this.tw_collide != null) return; this.loadTexture("car_enemy"); this.animations.play("lights", 12, true, false); this.speed = 20 * resolution }, car_enemy) }, play); game.time.events.add(1e4, function() { play.NewObject(this) }, this) } else if (this.ind == 4) { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("collect_powerup"); this.kill(); play.AnimationGetObject(this.x, this.y); var txt_score_sp = game.add.bitmapText(this.x - 6 * resolution, this.y - 10 * resolution, "fontc", "+10 sec", 16 * resolution); txt_score_sp.x -= txt_score_sp.textWidth / 2; txt_score_sp.initY = txt_score_sp.y; txt_score_sp.scale.setTo(.1, .1); this.game.add.tween(txt_score_sp.scale).to({ x: 1.6, y: 1.4 }, 200, Phaser.Easing.Quadratic.Out, true, 0).to({ x: 1.2, y: 1.2 }, 1e3, Phaser.Easing.Elastic.Out, true); game.add.tween(txt_score_sp).to({ y: txt_score_sp.initY - 10 * resolution, alpha: 0 }, 600, Phaser.Easing.Linear.None, true, 800).onComplete.add(function() { this.visible = false; this.destroy() }, txt_score_sp); play.bonus_time += 10; play.bonus_timer = 1e3; play.minutes = Math.floor(play.bonus_time / 60); play.secondss = Math.floor((play.bonus_time / 60 - play.minutes) * 60); if (play.secondss < 10) { play.txt_time_game.setText(play.minutes + ":0" + play.secondss) } else { play.txt_time_game.setText(play.minutes + ":" + play.secondss) } play.txt_time_game.updateText(); play.txt_time_game.x = play.txt_time_word.x + play.txt_time_word.textWidth / 2 - play.txt_time_game.textWidth / 2; if (play.bonus_time > 60) { play.minutes = 1; play.secondss = 0; play.bonus_time = play.minutes * 60; if (play.secondss < 10) { play.txt_time_game.setText(play.minutes + ":0" + play.secondss) } else { play.txt_time_game.setText(play.minutes + ":" + play.secondss) } play.txt_time_game.updateText(); play.txt_time_game.x = play.txt_time_word.x + play.txt_time_word.textWidth / 2 - play.txt_time_game.textWidth / 2 } play.istimerEndLevelAndLose = false; play.istimerEndLevel = false; game.time.events.add(1e4, function() { play.NewObject(this) }, this) } else if (this.ind == 5) { this.kill(); play.AnimationGetObject(this.x, this.y); if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("bomb"); play.CameraShake(); game.time.events.add(1e4, function() { play.NewObject(this) }, this); play.group_enemies.forEachAlive(function(car_enemy) { car_enemy.kill(); play.AnimationKillCar(car_enemy.x, car_enemy.y); play.CreateObject(car_enemy.x, car_enemy.y, 1, true); var rnd_timer = Math.random() * 1e4 + 5e3; game.time.events.add(rnd_timer, function() { play.CreateCarEnemy(this.ind_i, this.ind_j) }, car_enemy) }, this) } }, NewObject: function(money) { var new_x = Math.round(Math.random() * game.world.width); var new_y = Math.round(Math.random() * game.world.height); money.x = new_x; money.y = new_y; if ((Math.abs(money.x - play.car.x) > 70 * resolution || Math.abs(money.y - play.car.y) > 70 * resolution) && (this.map.getTile(this.layer.getTileX(money.x), this.layer.getTileX(money.y)) && this.map.getTile(this.layer.getTileX(money.x), this.layer.getTileX(money.y)).index == 2 || this.map.getTile(this.layer.getTileX(money.x - money.width), this.layer.getTileX(money.y)) && this.map.getTile(this.layer.getTileX(money.x - money.width), this.layer.getTileX(money.y)).index == 2 || this.map.getTile(this.layer.getTileX(money.x + money.width), this.layer.getTileX(money.y)) && this.map.getTile(this.layer.getTileX(money.x + money.width), this.layer.getTileX(money.y)).index == 2 || this.map.getTile(this.layer.getTileX(money.x), this.layer.getTileX(money.y - money.height)) && this.map.getTile(this.layer.getTileX(money.x), this.layer.getTileX(money.y - money.height)).index == 2 || this.map.getTile(this.layer.getTileX(money.x), this.layer.getTileX(money.y + money.height)) && this.map.getTile(this.layer.getTileX(money.x), this.layer.getTileX(money.y + money.height)).index == 2)) { this.NewObject(money); return } var anim_revive_object = game.add.sprite(money.x, money.y, "bubble_collect"); anim_revive_object.anchor.setTo(.5, .5); anim_revive_object.animations.add("get", [6, 5, 4, 3, 2, 1, 0]); anim_revive_object.animations.play("get", 15, false, true).onComplete.add(function() { money.reset(new_x, new_y) }, money) }, AnimationGetObject: function(x, y) { var anim_kill_object = game.add.sprite(x, y, "bubble_collect"); anim_kill_object.anchor.setTo(.5, .5); anim_kill_object.animations.add("get"); anim_kill_object.animations.play("get", 15, false, true) }, AnimationKillCar: function(x, y) { var anim_kill_car = game.add.sprite(x, y, "bomb_effect"); anim_kill_car.anchor.setTo(.5, .5); anim_kill_car.animations.add("explosion"); anim_kill_car.animations.play("explosion", 12, false, true) }, CreateCarEnemy: function(i, j) { if (play.istimerEndLevel || play.istimerEndLevelAndLose || play.you_win || play.gameOver) return; var car_enemy = new Phaser.Sprite(this.game,j * this.taille,i * this.taille,"car_enemy",0); car_enemy.animations.add("lights", [0, 1, 2, 3]); car_enemy.animations.play("lights", 12, true, false); car_enemy.alive = true; car_enemy.anchor.setTo(.5, .5); car_enemy.ind_i = i; car_enemy.ind_j = j; car_enemy.speed = 20 * resolution; car_enemy.isTouchedMap = false; car_enemy.isTouchedCar = false; car_enemy.speedX = 0; car_enemy.speedY = 0; car_enemy.current_speedX = 0; car_enemy.current_speedY = 0; car_enemy.StartFollow = 1; car_enemy.tw_collide = null; game.physics.enable(car_enemy); car_enemy.body.setSize(car_enemy.width - car_enemy.width / 6, car_enemy.height - car_enemy.height / 6, 0, 0); if (game.device.desktop) { car_enemy.MaxSpeed = EnemySpeed[play.numLevel - 1]; car_enemy.RateFasterSpeed = 3 * resolution; car_enemy.MapMaxSpeed = -120 * resolution; car_enemy.MapRateSlowerSpeed = 6 * resolution; car_enemy.MapNewSpeed = 20 * resolution; car_enemy.CarMaxSpeed = -250 * resolution; car_enemy.CarRateSlowerSpeed = 10 * resolution; car_enemy.CarNewSpeed = 0; car_enemy.CurveAngle = 3 * resolution; car_enemy.MapAngle = 3 } else { car_enemy.MaxSpeed = EnemySpeed[play.numLevel - 1] - 50 * resolution; car_enemy.RateFasterSpeed = 3 * resolution; car_enemy.MapMaxSpeed = -90 * resolution; car_enemy.MapRateSlowerSpeed = 5 * resolution; car_enemy.MapNewSpeed = 20 * resolution; car_enemy.CarMaxSpeed = -200 * resolution; car_enemy.CarRateSlowerSpeed = 10 * resolution; car_enemy.CarNewSpeed = 0; car_enemy.CurveAngle = 6 * resolution; car_enemy.MapAngle = 3 } game.time.events.add(500, function() { play.group_enemies.add(this) }, car_enemy); var anim_revive_car = game.add.sprite(car_enemy.x, car_enemy.y, "revive_effect"); anim_revive_car.anchor.setTo(.5, .5); anim_revive_car.animations.add("revive_car", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); anim_revive_car.animations.play("revive_car", 15, false, true) }, CreatePlayer: function(x, y) { this.car = game.add.sprite(x, y, "sprites"); this.car.frameName = "car" + resolution + ".png"; this.car.anchor.setTo(.5, .5); this.car.angle = -90; this.car.speed = 0; this.car.speedX = 0; this.car.speedY = 0; this.car.isTouchedMap = false; this.car.isTouchedCar = false; this.car.TouchedTile = null; this.car.tw_collide = null; this.car.current_speedX = 0; this.car.current_speedY = 0; game.physics.enable(this.car); this.car.body.setSize(this.car.width - this.car.width / 6, this.car.height - this.car.height / 6, 0, 0); game.camera.follow(this.car); if (game.device.desktop) { this.car.TapMinSpeed = 120 * resolution; this.car.TapRateSlowerSpeed = 2.5 * resolution; this.car.MaxSpeed = 250 * resolution; this.car.RateFasterSpeed = 3 * resolution; this.car.MapMaxSpeed = -120 * resolution; this.car.MapRateSlowerSpeed = 6 * resolution; this.car.MapNewSpeed = 60 * resolution; this.car.CarMaxSpeed = -300 * resolution; this.car.CarRateSlowerSpeed = 10 * resolution; this.car.CarNewSpeed = 40 * resolution; this.car.CurveAngle = 3; this.car.MapAngle = 3 } else { this.car.TapMinSpeed = 120 * resolution; this.car.TapRateSlowerSpeed = 8 * resolution; this.car.MaxSpeed = 250 * resolution; this.car.RateFasterSpeed = 5 * resolution; this.car.MapMaxSpeed = -80 * resolution; this.car.MapRateSlowerSpeed = 5 * resolution; this.car.MapNewSpeed = 60 * resolution; this.car.CarMaxSpeed = -200 * resolution; this.car.CarRateSlowerSpeed = 15 * resolution; this.car.CarNewSpeed = 60 * resolution; this.car.CurveAngle = 6; this.car.MapAngle = 3 } }, CreateObject: function(x, y, index, to_kill) { if (play.istimerEndLevel || play.istimerEndLevelAndLose || play.you_win || play.gameOver) return; var object = game.add.sprite(x, y, "objects", index); object.alive = true; object.anchor.setTo(.5, .5); object.frame = index; object.ind = index; game.physics.enable(object); object.body.setSize(object.width - object.width / 2.5, object.height - object.height / 2.5, 0, 0); game.add.tween(object.scale).to({ x: .9, y: 1.1 }, 350, Phaser.Easing.Quadratic.Out).to({ x: 1.1, y: .9 }, 350, Phaser.Easing.Quadratic.Out).start().loop(); if (to_kill) { object.frame = 0; var directionX = 1; if (Math.random() > .5) directionX = -1; var directionY = 1; if (Math.random() > .5) directionY = -1; var distanceX = Math.round(Math.random() * 70 * resolution + 20 * resolution); var distanceY = Math.round(Math.random() * 70 * resolution + 20 * resolution); game.add.tween(object).to({ x: object.x + directionX * distanceX, y: object.y + directionY * distanceY }, 600, Phaser.Easing.Quadratic.Out).start().onComplete.add(function() { this.group_objects.add(object) }, this); game.add.tween(object).to({ alpha: .5 }, 200, Phaser.Easing.Linear.None).to({ alpha: .9 }, 200, Phaser.Easing.Linear.None).start().loop(); game.time.events.add(5e3, function() { object.kill() }, object) } else this.group_objects.add(object) }, CameraShake: function() { if (!game.device.desktop) return; game.camera.target = null; var tw_cam = game.add.tween(game.camera).to({ x: game.camera.x + 5 * resolution, y: game.camera.y + 5 * resolution }, 50, Phaser.Easing.Linear.None).to({ x: game.camera.x - 5 * resolution, y: game.camera.y + 5 * resolution }, 50, Phaser.Easing.Linear.None).to({ x: game.camera.x + 5 * resolution, y: game.camera.y - 5 * resolution }, 50, Phaser.Easing.Linear.None).to({ x: game.camera.x - 5 * resolution, y: game.camera.y - 5 * resolution }, 50, Phaser.Easing.Linear.None); tw_cam.loop(); tw_cam.start(); game.time.events.add(250, function() { this.stop(); this.pendingDelete = true; game.camera.target = play.car }, tw_cam) }, CountDownStart: function() { game.add.tween(this.objectif_container).to({ y: this.objectif_container.y + game.height + 100 * resolution }, 500, Phaser.Easing.Back.Out).start(); game.add.tween(this.txt_goals).to({ y: this.txt_goals.y + game.height + 100 * resolution }, 500, Phaser.Easing.Back.Out).start(); game.time.events.add(1200, function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("countdown"); this.txt_countdown.visible = true; game.add.tween(this.txt_countdown.scale).to({ x: 1.3, y: 1.3 }, 300, Phaser.Easing.Quadratic.None).to({ x: 1, y: 1 }, 300, Phaser.Easing.Quadratic.Out).start(); game.time.events.add(600, function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("countdown"); this.txt_countdown.setText("2"); this.txt_countdown.updateText(); this.txt_countdown.x = game.camera.x + game.width / 2 - this.txt_countdown.textWidth / 2; game.add.tween(this.txt_countdown.scale).to({ x: 1.3, y: 1.3 }, 300, Phaser.Easing.Quadratic.None).to({ x: 1, y: 1 }, 300, Phaser.Easing.Quadratic.Out).start(); game.time.events.add(600, function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("countdown"); this.txt_countdown.setText("1"); this.txt_countdown.updateText(); this.txt_countdown.x = game.camera.x + game.width / 2 - this.txt_countdown.textWidth / 2; game.add.tween(this.txt_countdown.scale).to({ x: 1.3, y: 1.3 }, 300, Phaser.Easing.Quadratic.None).to({ x: 1, y: 1 }, 300, Phaser.Easing.Quadratic.Out).start(); game.time.events.add(600, function() { if (Music.enableMisic && game.sound.usingWebAudio) Music.sounds.play("countdown2"); this.txt_countdown.setText(text.txtGo); this.txt_countdown.updateText(); this.txt_countdown.x = game.camera.x + game.width / 2 - this.txt_countdown.textWidth / 2; game.add.tween(this.txt_countdown.scale).to({ x: 1.3, y: 1.3 }, 200, Phaser.Easing.Back.Out).start(); game.add.tween(this.objectif_container).to({ y: this.objectif_container.y + game.world.height }, 500, Phaser.Easing.Back.In).start(); game.add.tween(this.txt_goals).to({ y: this.txt_goals.y + game.world.height }, 500, Phaser.Easing.Back.In).start(); game.time.events.add(400, function() { this.txt_countdown.destroy(); this.GameStart = true }, this) }, this) }, this) }, this) }, this) }, creer_text_score: function(sprite) { sprite.txt_created = true; var txt_score_sp = game.add.bitmapText(sprite.x - 6 * resolution, sprite.y - 10 * resolution, "fontc", "+10", 16 * resolution); txt_score_sp.x -= txt_score_sp.textWidth / 2; txt_score_sp.initY = txt_score_sp.y; txt_score_sp.scale.setTo(.1, .1); this.game.add.tween(txt_score_sp.scale).to({ x: 1.6, y: 1.4 }, 200, Phaser.Easing.Quadratic.Out, true, 0).to({ x: 1.2, y: 1.2 }, 1e3, Phaser.Easing.Elastic.Out, true); game.add.tween(txt_score_sp).to({ y: txt_score_sp.initY - 10 * resolution, alpha: 0 }, 600, Phaser.Easing.Linear.None, true, 800).onComplete.add(function() { this.visible = false; this.destroy() }, txt_score_sp) }, actionMusic: function() { this.stateMusic = !this.stateMusic; if (this.stateMusic) { this.bnt_music.frameName = "musicbnt" + resolution + ".png"; if (!this.ispause_music) Music.music.resume() } else { this.bnt_music.frameName = "Mutemusicbnt" + resolution + ".png"; if (!this.ispause_music) Music.music.pause() } } }; window.onload = function() { setTimeout(function() { window.scrollTo(0, 1) }, 10); game = new Phaser.Game(320 * resolution,480 * resolution,Phaser.CANVAS); play = game.state.add("play", CandyCarEscape.Play, false); game.state.add("credits", CandyCarEscape.Credits, false); lv = game.state.add("levels", CandyCarEscape.Map_Levels, false); game.state.add("menu", CandyCarEscape.Menu, false); game.state.add("preload", CandyCarEscape.Preload, false); game.state.add("boot", CandyCarEscape.Boot, true) } ;