Search the Community

Showing results for tags 'lives'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 2 results

  1. anthkris

    How to Deduct Player Lives

    I'm creating an infinite scroller and (among other things) I'm having trouble with deducting player lives. I've looked at various tutorials, but most of them seem to kill the player whenever they hit an obstacle. Ideally, I'd like to deduct a life from the player until they have no more lives. The problem I'm experiencing is that I'm checking overlap with the player and a pool of enemies (btw, works the same way if I check for collision). In the callback, I only want to deduct a life the first time the player comes in contact with the enemy. What's happening now is that a single contact will destroy all the hearts. I've tried using a counter, but that doesn't seem to work well as any attempt to reset it seems to be happening too quickly. I've also tried to use signals, but they seem to result in the same behavior as using the callback. The code looks like this: // In update this.game.physics.arcade.overlap(this.player, this.enemiesPool, this.hurtPlayer, null, this); // Callback hurtPlayer: function(player, enemy) { console.log(this.hitCounter); //do this during overlap this.isHit = true; this.canShoot = false enemy.play('attacking'); player.play('hit'); //only destroy a heart the first time you contact the enemy //enemy should detract 1 heart at most // if (this.hitCounter <= 0) { // this.destroyHeart(); // } // this.hitCounter++; this.destroyHeart(); //enemy.kill(); }, //Destroy heart destroyHeart: function() { console.log(this.myLives); switch(this.myLives) { case 4: this.life4.destroy(); break; case 3: this.life3.destroy(); break; case 2: this.life2.destroy(); break; case 1: this.life1.destroy(); break; } this.myLives--; }, Any suggestions?
  2. Hello guys, I just recently started to play with Phaser and so far I'm loving it.. However as I'm not used to it, I run into wall.. I'm creating a breakout game where I want different bricks to respond to ball hitting them differently.. Mostly I want to add bricks a health so to speak, so depending on the color of the brick, it will take 1,2,3.. etc ball hits to kill it.. I'm so far doing this in this fashion: // Red bricks bricks_1 = game.add.group(); bricks_1.enableBody = true; bricks_1.physicsBodyType = Phaser.Physics.ARCADE; // Yellow bricks bricks_2 = game.add.group(); bricks_2.enableBody = true; bricks_2.physicsBodyType = Phaser.Physics.ARCADE; // Gray bricks bricks_3 = game.add.group(); bricks_3.enableBody = true; bricks_3.physicsBodyType = Phaser.Physics.ARCADE; // Green bricks bricks_4 = game.add.group(); bricks_4.enableBody = true; bricks_4.physicsBodyType = Phaser.Physics.ARCADE;So, I'm creating a group for each of the type of the possible bricks.. Then as I randomly create a level, I do this: function randomLevel(){ var brick; for (var i = 0; i < 8; i++) { for (var j = 0; j < 6; j++) { var rand = game.rnd.integerInRange(1, 4); switch(rand) { case 1: brick = bricks_1.create(75 + (i*80), 55 + (j*40), 'brick_1'); brick.body.bounce.set(1); brick.body.immovable = true; break; case 2: brick = bricks_2.create(75 + (i*80), 55 + (j*40), 'brick_2'); brick.body.bounce.set(1); brick.body.immovable = true; break; case 3: brick = bricks_3.create(75 + (i*80), 55 + (j*40), 'brick_3'); brick.body.bounce.set(1); brick.body.immovable = true; break; case 4: brick = bricks_4.create(75 + (i*80), 55 + (j*40), 'brick_4'); brick.body.bounce.set(1); brick.body.immovable = true; break; } } }}And then I have 4 onHit functions (which I don't really like, would prefer a single one with some switch statement in there) where depending on what type of brick has been hit, it can play ie different sound for example.. game.physics.arcade.collide(ball, bricks_1, ballHitBrick_1, null, this); game.physics.arcade.collide(ball, bricks_2, ballHitBrick_2, null, this); game.physics.arcade.collide(ball, bricks_3, ballHitBrick_3, null, this); game.physics.arcade.collide(ball, bricks_4, ballHitBrick_4, null, this);This is example of one of the onHit functions (I basically used example of breakout a lot): function ballHitBrick_1(_ball, _brick) { _brick.kill(); hit_fx.play(); score += 10; scoreText.text = 'Score: ' + score; // Are they any bricks left? if (bricks_1.countLiving() == 0 && bricks_2.countLiving() == 0 && bricks_4.countLiving() == 0) { // New level starts scoreText.text = 'Score: ' + score; introText.text = '- Next Level -'; // Let's move the ball back to the paddle ballOnPaddle = true; ball.body.velocity.set(0); ball.x = paddle.x + 16; ball.y = paddle.y - 16; ball.animations.stop(); // And bring the bricks back from the dead randomLevel(); }}And this all works well, ie I can play different sounds based on what brick has been hit.. However what do I need to do to add health to these bricks? So for example, bricks_1 bricks die only after 1 shot, while bricks_3 don't die ever (think of like concrete/metal/blocking bricks).. Thanks a ton!