Gustavo Azevedo Posted March 15, 2018 Share Posted March 15, 2018 I would like to create a scoring system in which the coins randomly descended into different places. Sorry if the english is bad (still lurning the language). This is my code. (function () { var game = new Phaser.Game(540, 303, Phaser.AUTO, 'container-game', { preload: preload, create: create, update: update, }); var estrada, player, keys, moedas; function preload() { this.velocidade = 80; // CARREGAMENTO DE IMAGENS game.load.image('background', 'img/background.png'); game.load.spritesheet('boneco', 'img/player.png', 37, 78); game.load.spritesheet('moeda', 'img/moeda.png', 31, 31); } function create() { this.moedas = game.add.group(); game.time.events.loop(5000, this.adicionarMoeda, this); // FISICAS DO JOGO game.physics.startSystem(Phaser.Physics.ARCADE); keys = game.input.keyboard.createCursorKeys(); // BACKGROUND estrada = game.add.tileSprite(0, 0, 540, 303, 'background'); // APLICAÇÕES SOB O PERSONAGEM player = game.add.sprite(252, 200, 'boneco'); game.physics.arcade.enable(player); player.animations.add('pedalar', [0, 1, 2, 3], 10, true); player.animations.play('pedalar'); } function update() { // BACKGROUND INFINITO this.velocidade += 1 * 0.03; estrada.tilePosition.y += this.velocidade / 60; console.log(this.velocidade); // CONTROLES DO PERSONAGEM if (keys.left.isDown) { if (player.x > 172) { player.x -= 5; } } if (keys.right.isDown) { if (player.x < 329) { player.x += 5; } } } function adicionarMoeda() { var moedaX = game.rnd.integerInRange(170, 320); var moeda = game.add.sprite(moedaX, -30, 'moeda'); this.moedas.add(moeda); game.physics.arcade.enable(moeda); moeda.body.velocity.y = this.velocidade; moeda.animations.add('girar', [0, 1, 2, 3, 4, 5, 6, 7], 16, true); moeda.animations.play('girar'); moeda.checkWorldBounds = true; moeda.outOfBoundsKill = true; } }()); Link to comment Share on other sites More sharing options...
Recommended Posts