create() { util.trace('GameState::create') this.stage.backgroundColor = 0x2c2b2b; let style = { font: "32px Arial", fill: "#ff0044", align: "center"}; let text = game.add.text(game.width/2, game.height/2, "- your game goes here -", style); text.anchor.set(0.5); }
createBullets() { bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.createMultiple(30, 'freezeBullet'); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 1); bullets.setAll('outOfBoundsKill', true); bullets.setAll('checkWorldBounds', true); }
createCrowns() { crownGroup = game.add.group() crownGroup.enableBody = true; crownGroup.physicsBodyType = Phaser.Physics.ARCADE; crowns.forEach(function(tile) { let c = crownGroup.create(tile.worldX, tile.worldY, "crown") c.body.allowGravity = false }); }
create() { //http://kvazars.com/littera/ this.stage.backgroundColor = 0x2c2b2b; this.add.image(0, 0, 'background'); game.add.bitmapText(100, 205, "littera", "This is the Game Title", 36); //.anchor.x = 0.5; let start = game.add.bitmapText(100, 250, "littera", "Click to start.", 36); //var playButton = game.add.button(game.width / 2, game.height - 150, "playbutton", this.startGame); start.inputEnabled = true; start.events.onInputDown.add(this.startGame, this) start.events.onInputOver.add(this.startOver, this); start.events.onInputOut.add(this.startOut, this); //playButton.anchor.set(0.5); //game.state.start("SpriteState"); //game.time.events.add(Phaser.Timer.SECOND * 2, this.startGame, this); }
endGame(player, enemy) { if(!shesDeadJim) { sounds["music"].stop() this.playSound("lose") let cam = game.camera; let style = { font: "32px Arial", fill: "#ff0044", align: "center"}; let text = game.add.text(cam.x + 200, cam.y + 200, "- She's dead, Jim. -\r\nRestarting...", style); text.anchor.set(0.5); game.time.events.add(Phaser.Timer.SECOND * 3, this.nextState, this); shesDeadJim = true; } }
loadSounds() { sounds["coin"] = game.add.audio("coin"); sounds["explode"] = game.add.audio("explode"); sounds["fire"] = game.add.audio("fire"); sounds["jump"] = game.add.audio("jump") sounds["mutate"] = game.add.audio("mutate"); sounds["win"] = game.add.audio("win"); sounds["lose"] = game.add.audio("lose"); sounds["music"] = game.add.audio("music"); game.sound.setDecodedCallback(sounds, function() { soundsLoaded = true sounds["music"].play('', 0, 1, true, true) util.trace("sounds loaded!") }, this); }
createNormalEnemies() { enemyNormalGroup = game.add.group(); enemyNormalGroup.enableBody = true; enemyNormalGroup.physicsBodyType = Phaser.Physics.ARCADE; }
create() { playerScore = 0; bulletTime = 0; spawnTimer = 0; spawnPoints = []; teleporters = []; crowns = []; shesDeadJim = false this.touching = false; game.time.advancedTiming = true; util.trace('StageState::create') this.loadSounds() //game.world.setBounds(0, 0, 1024, 1024); game.world.setBounds(0, 0, 4800, 1856); this.stage.backgroundColor = 0x2c2b2b; game.physics.startSystem(Phaser.Physics.ARCADE); //game.physics.arcade.gravity.y = 400; // CONTROLS this.cursor = game.input.keyboard.createCursorKeys(); this.S = this.game.input.keyboard.addKey(Phaser.Keyboard.S); this.S.onDown.add(function() { this.onShapeShift(1) }, this); this.A = this.game.input.keyboard.addKey(Phaser.Keyboard.A); this.A.onDown.add(function() { this.onShapeShift(0) }, this); this.V = this.game.input.keyboard.addKey(Phaser.Keyboard.V); this.V.onDown.add(this.toggleMusic, this); fireButton = game.input.keyboard.addKey(Phaser.Keyboard.F); //TILES //the first parameter is the tileset name as specified in Tiled, the second is the key to the asset this.map = this.game.add.tilemap('tileMap'); this.map.addTilesetImage('MasterTileset', 'tiles'); this.blockedLayer = this.map.createLayer("TileArea") this.waterLayer = this.map.createLayer("WaterLayer") // Toggle to debug spawns/teleports. //this.hotspots = this.map.createLayer("hotspots") this.waterLayer.alpha = 0.3 // TILE COLLISION this.map.setCollisionBetween(15,20, true, "TileArea"); this.map.setCollisionBetween(25,30, true, "TileArea"); this.map.setCollision([2,5], true, "TileArea") // CREATE SPAWN POINTS for(var x = 0; x < this.map.width; ++x) { for(var y = 0; y < this.map.height; ++y) { let tile = this.map.getTile(x, y, "hotspots"); if(tile && tile.properties["spawner"]) { spawnPoints.push(tile) } if(tile && tile.properties["teleport"]) { teleporters.push(tile) } let crownTile = this.map.getTile(x,y,"crowns"); if(crownTile) { crowns.push(crownTile); } } } this.createCrowns(); // PLAYER this.player = this.game.add.sprite(100, 1440, 'playerSpriteSheet') this.player.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(this.player); this.player.body.collideWorldBounds = true; this.player.body.bounce.y = 0.2; this.player.body.gravity.y = 400; this.player.animations.add('blue', [0,1,2,3,4,5,4,3,2,1], true); this.player.animations.add('green', [6,7,8,9,10,11,10,9,8,7], true); this.player.animations.add('normal', [12,13,14,15,16,17,16,15,14,13], true); this.player.eClass = "enemy_green" this.onShapeShift() this.createBullets() this.createNormalEnemies() //this.createEnemy(836, 1440) game.camera.follow(this.player); //let style = { font: "32px Arial", fill: "#ff0044", align: "center"}; //let text = game.add.text(game.width/2, game.height/2, "- your game goes here -", style); //text.anchor.set(0.5); // EVENTS game.time.events.repeat(Phaser.Timer.SECOND * 4, 5000, this.spawnEnemies, this); // score let style = { font: "24px Arial", fill: "#e75f25", align: "center"}; scoreText = game.add.text(game.camera.x + 20, game.camera.y, "Score: " + playerScore, style); }