Kraken

Members
  • Content Count

    34
  • Joined

  • Last visited

Everything posted by Kraken

  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
  16. I'm pretty new to phaser and JS and I'm wondering if anyone knows where to get good graphics. Possibly custom graphics if possible.
  17. Yes I noticed that as well but you're right it did not fix the issue
  18. if(this.x+this.width < this.bird.x && this.giveScore){
  19. I'm trying to make a flappy bird game and I'm getting an error Uncaught TypeError: Cannot read property 'x' of undefined Game.js:76 I'm not sure if its the constructor or something else giving me this error...I have attached the code for reference var FlappyBoard = FlappyBoard || {}; FlappyBoard.GameState = { init: function() { // bird gravity, will make bird fall if you don't flap this.birdGravity = 800; // horizontal bird speed this.birdSpeed = 125; // flap thrust this.birdFlapPower = 300; // milliseconds between the creation of two pipes this.pipeInterval = 2000; // hole between pipes, in puxels this.pipeHole = 120; this.score=0; this.pipeGroup = this.add.group(); }, create:function(){ this.topScore = localStorage.getItem("topFlappyScore")==null?0:localStorage.getItem("topFlappyScore"); scoreText = this.add.text(10,10,"-",{ font:"bold 16px Arial" }); this.updateScore(); this.stage.backgroundColor = "#87CEEB"; this.stage.disableVisibilityChange = true; //game.physics.startSystem(Phaser.Physics.ARCADE); this.bird = this.add.sprite(80,240,'bird'); this.bird.anchor.set(0.5); this.game.physics.arcade.enable(this.bird); this.bird.body.gravity.y = this.birdGravity; this.game.input.onDown.add(this.flap, this); this.game.time.events.loop(this.pipeInterval, this.addPipe); this.addPipe(); }, update:function(){ this.game.physics.arcade.collide(this.bird, this.pipeGroup, this.die, null, this); }, //this.game.state.start('GameState'); updateScore: function(){ scoreText.text = "Score: "+this.score+"\nBest: "+this.topScore; }, flap: function(){ this.bird.body.velocity.y = -this.birdFlapPower; }, addPipe: function(){ var pipeHolePosition = this.rnd.between(50,430-this.pipeHole); var upperPipe = new FlappyBoard.Pipe(this.game,320,pipeHolePosition-480,-this.birdSpeed, 'pipe'); this.game.add.existing(upperPipe); this.pipeGroup.add(upperPipe); var lowerPipe = new FlappyBoard.Pipe(this.game,320,pipeHolePosition+this.pipeHole,-this.birdSpeed); this.game.add.existing(lowerPipe); this.pipeGroup.add(lowerPipe); }, die: function(){ localStorage.setItem("topFlappyScore",Math.max(this.score,topScore)); } }; FlappyBoard.Pipe = function (game, x, y, speed) { Phaser.Sprite.call(this, game, x, y, 'pipe'); game.physics.enable(this, Phaser.Physics.ARCADE); this.body.velocity.x = speed; this.giveScore = true; }; FlappyBoard.Pipe.prototype = Object.create(Phaser.Sprite.prototype); FlappyBoard.Pipe.prototype.constructor = FlappyBoard.Pipe; FlappyBoard.Pipe.prototype.update = function() { if(this.x+this.width < this.bird.x && this.giveScore){ this.score+=0.5; this.updateScore(); this.giveScore = false; } if(this.x<-this.width){ this.destroy(); } };
  20. Hi Pheaset, thanks for trying it out. I'm not sure why the game.html doesn't work for you but either way it should be on either URL. I used the infinite runner tutorial from the Zenva Academy.
  21. I created my first game, an endless runner game based off the tutorial. Let me know any improvements or recommendations you have. https://kraken18.github.io/game.html
  22. Just to confirm... gravity was the issue now that I have set it to 1000 I no longer get stuck. Anything over that number somehow causes problems when the platform created is lower than the previous one. Thanks scheffgames, I honestly would of never thought it was the gravity.
  23. I'm using arcade physics, I have disabled the cache as you suggested this is basically my player code... this.player = this.add.sprite(200, 200, 'player1'); this.player.anchor.setTo(0.5); this.player.animations.add('running', [1,2,3,4,5,6], 10, true); this.player.animations.add('jumping', [7], true); this.game.physics.arcade.enable(this.player); this.player.body.setSize(58,83, 10, 11); but as for the buggy code I honestly couldn't tell you what it would be as the game will be working fine and then the player gets stuck randomly. I did see the correlation between the gravity setting though I even increased it on the enemy bodies only and it seems to effect the player getting stuck as well. I lowered the gravity equally on everything and I get stuck very rarely now if at all.
  24. Thanks scheffgames! I enabled debug and everything looked alright. I did change the gravity from 1500 to 900 and the frequency it happens is lower significantly which makes me believe that's what the problem is. Its funny though when I run it through the intel emulator everything works fine no matter the gravity but if I try it through intel previewer or chrome that's when it happens.