Path: blob/main/public/games/files/gopher-kart/js/stateChoice.js
1036 views
var StateChoice = {1preload: function () {2//Music and Sounds3game.load.audio("select", "assets/music/BeepBox-Song3-compressed.m4a");45//Spritesheets for the 3 colored Gophers6//Later put into 1 spritesheet7game.load.spritesheet("racer", "assets/character-select-loops.png", 76, 72, 7);89game.load.image("background", "assets/bg-color.png");10game.load.image("city", "assets/city-re-colored.png");11game.load.image("sky", "assets/clouds-re-colored.png");12game.load.image("mtn", "assets/mountains-recolored.png");13game.load.image("select", "assets/character-select-bg.png");1415//sample test button16game.load.spritesheet("confirmButton", "assets/buttons-sprite.png", 111, 24, 4);17game.load.spritesheet("neon", "assets/neon-sign.png", 120, 30, 13);1819game.load.spritesheet("buttons", "assets/on-off-buttons.png", 59, 41, 2);20game.load.spritesheet("blueMarquee", "assets/blue-crawl.png", 50, 12, 45);21game.load.spritesheet("pinkMarquee", "assets/pink-crawl.png", 50, 12, 45);22game.load.spritesheet("purpleMarquee", "assets/purple-crawl.png", 50, 12, 45);23// game.load.spritesheet("neonCnfrm", "assets/neon-sign.png", )2425},2627create: function () {28this.camera.reset();2930//MUSIC31this.selectSong = game.add.audio("select");32//Watched youtube video, need to check docs for .play params33this.selectSong.play('', 0, 1, true);3435//BACKGROUND36this.background = game.add.tileSprite(0, 0, 600, 432, "background");3738this.sky = game.add.tileSprite(0, 10, 600, 78, "sky");39this.mtn = game.add.tileSprite(0, 250, 600, 131, "mtn");40this.city = game.add.tileSprite(0, 290, 600, 90, "city");41this.select = game.add.tileSprite(0, 0, 600, 432, "select");4243//MARQUEE44//Blue45this.blueMarquee = game.add.sprite(game.world.bounds.height - 282, game.world.centerY-16, "blueMarquee");46this.blueMarquee.anchor.set(0.5, 0.5);47this.blueMarquee.animations.add("blueCrawl", [],15, true);48this.blueMarquee.animations.play("blueCrawl");49//Pink50this.pinkMarquee = game.add.sprite(game.world.bounds.height - 132, game.world.centerY-16, "pinkMarquee");51this.pinkMarquee.anchor.set(0.5, 0.5);52this.pinkMarquee.animations.add("pinkCrawl", [],13, true);53this.pinkMarquee.animations.play("pinkCrawl");54//Purple55this.purpleMarquee = game.add.sprite(game.world.bounds.height + 18, game.world.centerY-16, "purpleMarquee");56this.purpleMarquee.anchor.set(0.5, 0.5);57this.purpleMarquee.animations.add("purpleCrawl", [],10, true);58this.purpleMarquee.animations.play("purpleCrawl");5960//Choose Racer161this.pickRacer1 = game.add.button(game.world.bounds.height - 282, game.world.centerY+105,62"buttons", this.racerStart.bind(this, "blue"), this);63this.pickRacer1.anchor.set(0.5, 0.5);6465//Choose Racer266this.pickRacer2 = game.add.button(game.world.bounds.height - 132, game.world.centerY+105,67"buttons", this.racerStart.bind(this, "pink"), this);68this.pickRacer2.anchor.set(0.5, 0.5);6970//Choose Racer371this.pickRacer3 = game.add.button(game.world.bounds.height + 18, game.world.centerY+105,72"buttons", this.racerStart.bind(this, "purple"), this);73this.pickRacer3.anchor.set(0.5, 0.5);7475this.buttons = {76"blue": this.pickRacer1,77"pink": this.pickRacer2,78"purple": this.pickRacer379};8081//BLACK AND WHITE GOPHERS82//Blue83this.blue = game.add.sprite(game.world.bounds.height - 282, game.world.centerY+40, "racer");84this.blue.frame = 1;85this.blue.animations.add("blue", [1, 2],9, true);86this.blue.anchor.set(0.5, 0.5);87this.blue.animations.play("blue");8889//Pink90this.PinkGopher = game.add.sprite(game.world.bounds.height - 132, game.world.centerY+40, "racer");91this.PinkGopher.frame = 3;92this.PinkGopher.animations.add("pink", [3, 4],9, true);93this.PinkGopher.anchor.set(0.5, 0.5);94this.PinkGopher.animations.play("pink");9596//Purple97this.PurpleGopher = game.add.sprite(game.world.bounds.height + 18, game.world.centerY+40, "racer");98this.PurpleGopher.frame = 5;99this.PurpleGopher.animations.add("purple", [5, 6],9, true);100this.PurpleGopher.anchor.set(0.5, 0.5);101this.PurpleGopher.animations.play("purple");102103104//CONFIRMATION BUTTON105this.startConfirm = game.add.button(game.world.bounds.height - 132, game.world.height-46,106"neon", this.startGame, this, 12, 12, 12);107this.startConfirm.frame = 12;108this.startConfirm.anchor.set(0.5, 0.5);109this.startConfirm.animations.add("neon", [],5, true);110this.startConfirm.anchor.set(0.5, 0.5);111// this.startConfirm.animations.play("neon");112},113114startGame: function () {115if(character === undefined){116this.sampleText = game.add.text(game.world.centerX, 30, "You must choose a gopher!");117this.sampleText.fill = "ffffff";118this.sampleText.fontSize = 32;119this.sampleText.anchor.set(0.5, 0.5);120// console.log("You must choose a gopher!");121} else {122this.selectSong.stop();123game.state.start("StateMain");124}125},126127racerStart: function (racer){128console.log(racer);129for (var key in this.buttons) {130this.buttons[key].frame = 0;131}132133this.buttons[racer].frame = 1;134character = racer;135136137this.startConfirm.animations.play("neon");138// character.animations.play("blue");139// console.log(character);140},141142143update: function () {144this.sky.tilePosition.x -= 0.1;145146},147148149};150151152