Kraken

Members
  • Content count

    34
  • Joined

  • Last visited

About Kraken

  • Rank
    Advanced Member

Recent Profile Visitors

222 profile views
  1. Turns out this was the way to do it, thanks for the help!
  2. Thanks for the reply I'm not really sure how the function could change the level can you show me an example?
  3. var TowerDefense = TowerDefense || {}; TowerDefense.GameState = { init: function(currentLevel) { this.monstersKilled = 0; this.numLevels = 2; this.currentLevel = currentLevel ? currentLevel : 'level1'; }, hitMonster: function(monster, weapon) { monster.body.velocity.x = 200; monster.body.velocity.y = -300; monster.damage(1); weapon.destroy(); if(!monster.alive){ this.killedEnemies++; if(this.killedEnemies == this.numEnemies) { this.game.state.start('GameState', true, false, this.levelData.nextLevel); } } }, TowerDefense.UnitAI.prototype.damage = function(amount) { Phaser.Sprite.prototype.damage.call(this, amount); if(this.health <=0){ TowerDefense.GameState.monstersKilled++; TowerDefense.GameState.monstersCountLabel.text = TowerDefense.GameState.monstersKilled; } So i have to JSON files that are levels and once a set amount of enemies are dead the level changes but it seems that when I start the state for the next level the entire game basically restarts.
  4. I'm loading my level data from JSON files and it keeps resetting the counter after you beat each level. Is there a way to keep the counter from resetting?
  5. Thanks, that did the trick!
  6. I'm trying to calculate the number of enemies killed but for some reason it is not updating. I have a monstersKilled = 0 variable in the create section of the GameState. this.monstersKilled = 0; I made an enemy prefab where in the damage prototype I want this.monsterKilled to update as enemy's die but it is not updating. var TowerDefense = TowerDefense || {}; TowerDefense.UnitAI = function (game, x, y, id, health) { Phaser.Sprite.call(this, game, x, y, id); this.customProps = { speed: 100 }; //this.game = game; this.game.physics.arcade.enable(this); this.scale.x = -1; this.body.velocity.x = -100; this.checkWorldBounds = true; this.body.collideWorldBounds = false; this.body.gravity.y = 1400; this.customProps.speed = 100; this.health = health; }; TowerDefense.UnitAI.prototype = Object.create(Phaser.Sprite.prototype); TowerDefense.UnitAI.prototype.constructor = TowerDefense.UnitAI; TowerDefense.UnitAI.prototype.update = function() { if (this.customProps.speed) { this.body.velocity.x = Math.max(-this.customProps.speed, this.body.velocity.x - 6); } Phaser.Sprite.prototype.update.call(this); }; TowerDefense.UnitAI.prototype.reset = function(x, y, id, health){ Phaser.Sprite.prototype.reset.call(this, x, y, health); this.loadTexture(id); }; TowerDefense.UnitAI.prototype.damage = function(amount) { Phaser.Sprite.prototype.damage.call(this, amount); if(this.health <=0){ this.monstersKilled++; } }; here is my create enemy function to reset the enemies as needed createEnemy: function(x, y, id, health){ var monster = this.enemyUnits.getFirstExists(false); if(!monster){ monster = new TowerDefense.UnitAI(this.game, x, y, id, health); this.enemyUnits.add(monster); monster.animations.play('run', 16, true); monster.body.setSize(58,83, 10, 11); } monster.reset(x, y, id, health); monster.animations.add('run'); monster.animations.play('run', 16, true); monster.body.setSize(28,48, 0, 0); }
  7. Ah yes I should of put in a world bounds so you cant just skip all the pipes. That is a smart move on your part though.
  8. I did learn quite a bit from this one. I originally had a bird that was flapping its wings but I didn't have a sprite sheet for the fish but I am planning on putting in a sound and a sprite sheet for the player.
  9. Thanks for trying it out! I guess it may a bit hard but I used to play the original Flappy Bird for hours so I thought it was easy when i made this one.
  10. OK so should I put the code of the game inside the IIFE? I'm fairly new to JS and I'm not sure how this would protect the code on the client.
  11. Hey Arcanorum, I guess once the files are on the web they are not really safe anymore. Do you recommend JSCompress?
  12. Thanks JohnCitron, do you recommend I use something like JScrambler to encrypt the game?
  13. I didn't even know about circle physics bodies. Thanks Arcanorum! I contemplated using a timer but I wanted to keep the bubble effect and make the player hit an urchin to shrink back.
  14. Here is my second try at a phaser game. I based it on the flappy bird tutorial. Let me know what you think I could do to improve it. https://kraken18.github.io/flappyboard/
  15. Awesome, I'm gonna have a look around those sites