WhiteSoul Posted July 25, 2014 Share Posted July 25, 2014 Hello. I'm almost finishing my first game, but I'm stuck with the enemies issue...I want that the enemies comes from the upper part of the screen at random intervals but I can't do it. I was looking for tutorials but I don't know how to do it.I think that I need to create a group for the enemies and I did that already. Thank you so much in advance. Regards, Daniel. Link to comment Share on other sites More sharing options...
lewster32 Posted July 25, 2014 Share Posted July 25, 2014 This example has a random enemy spawner which you could analyse and adapt to your game: http://gamemechanicexplorer.com/#homingmissiles-5 WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 25, 2014 Author Share Posted July 25, 2014 Thank you so much. That website seems so interesting to learn about games but it seems a bit difficult to me, hehe. Anyways I will try to implement it. Link to comment Share on other sites More sharing options...
lewster32 Posted July 25, 2014 Share Posted July 25, 2014 Stick with it - the examples on that site are brilliantly written and well commented. If you get stuck let us know and we'll see what we can do WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 25, 2014 Author Share Posted July 25, 2014 Oh, that's so nice, thank you. I will also take a look at Phaser's GitHub documentation page, so maybe in that way I can understand the game states. Link to comment Share on other sites More sharing options...
bryanbibat Posted July 26, 2014 Share Posted July 26, 2014 Here's another tutorial with a section for spawning random enemies from the top: https://leanpub.com/html5shootemupinanafternoon/read#leanpub-auto-enemy-sprite-group WhiteSoul and lewster32 2 Link to comment Share on other sites More sharing options...
Heppell08 Posted July 26, 2014 Share Posted July 26, 2014 If you have a group of enemies and want them to spawn from the top of the screen randomly then in your group creation and spawn you can set the Y to above world height and set the X to game.world.randomX; WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 26, 2014 Author Share Posted July 26, 2014 Thank you so much for the help! That book seems awesome and very useful.And about that tip, I didn't knew that you could do that. Let's see if finally I can finish my game hahaha. Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 26, 2014 Author Share Posted July 26, 2014 Yes, it worked! Finally! I'm so happy my first game is almost done. ^^ But now I want to make the enemy group disappear when they hit the player, I was using "enemies.kill()" but that only kills the enemy that touched the player, the other ones keep appearing.I want to use that so it only appears on the screen "Game Over". Thank you guys again for all the interest. Link to comment Share on other sites More sharing options...
Heppell08 Posted July 26, 2014 Share Posted July 26, 2014 You'd need to set up a few arguments like.if(player.exists === false){ ... Game over etc here }But it totally depends on how you have the logic laid out really. Just check for the death of player or use a physics collode/overlap to do the callbacks if the player dies on contact with the enemy. WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 26, 2014 Author Share Posted July 26, 2014 Yes, I'm using a colliding system, so the thing that I want to achieve is that when one enemy of the group touches the player the whole group disappear. I already have the text "Game Over" placed but the problem is that the enemies keep appearing. Link to comment Share on other sites More sharing options...
Dumtard Posted July 26, 2014 Share Posted July 26, 2014 As Heppell said it depends on how you set up the logic for your enemy spawning. Basically you have to have some logic so that you can stop the spawn, if you are using a timer, stop the timer, if you are calling a function that spawns enemies every frame in your update method, stop calling that when its time for game over, etc.An easier more general answer would be to set up a GameOver State and switch states to that to display your game over, and a button for restarting, etc. WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 26, 2014 Author Share Posted July 26, 2014 Oh, ok, I didn't think it in that way... I will try it, thank you. Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 27, 2014 Author Share Posted July 27, 2014 I've been thinking how to do that, but I have no clue... ^^; This is the code that spawns the enemies that I have inside the update function:if (game.nextEnemyAt < game.time.now && enemies.countDead() > 0) { game.nextEnemyAt = game.time.now + game.enemyDelay; var enemy = enemies.getFirstExists(false); enemy.reset(game.rnd.integerInRange(20, 280), 0); enemy.body.velocity.y = game.rnd.integerInRange(190, 280); enemy.play("movement"); }The problem is that I don't know how to stop that "if". Link to comment Share on other sites More sharing options...
Dumtard Posted July 27, 2014 Share Posted July 27, 2014 Add another check to the if statement that ensures it is not in the game over state so that if its game over it will not enter that statement. var gameover = false;if (collision) { gameover = true;}if (game.nextEnemyAt < game.time.now && enemies.countDead() > 0 && !gameover) { game.nextEnemyAt = game.time.now + game.enemyDelay; var enemy = enemies.getFirstExists(false); enemy.reset(game.rnd.integerInRange(20, 280), 0); enemy.body.velocity.y = game.rnd.integerInRange(190, 280); enemy.play("movement"); } WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 27, 2014 Author Share Posted July 27, 2014 Oh, nice! Thank you so much, let's see how can implement that because I was testing with it and the spawn didn't worked at all, I mean even without collision.But I'm so close. Link to comment Share on other sites More sharing options...
Dumtard Posted July 27, 2014 Share Posted July 27, 2014 I don't know how exact you were following my code, but make sure var gameover = false is not in the update loop, initialize it only once. You can also do as Heppell said earlier and check if the player still exists after being removed from collision.if (game.nextEnemyAt < game.time.now && enemies.countDead() > 0 && player.exists) { game.nextEnemyAt = game.time.now + game.enemyDelay; var enemy = enemies.getFirstExists(false); enemy.reset(game.rnd.integerInRange(20, 280), 0); enemy.body.velocity.y = game.rnd.integerInRange(190, 280); enemy.play("movement"); } WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 27, 2014 Author Share Posted July 27, 2014 Thank you for all the efforts. Anyways I had the variable "gameover" out of the update loop with the other variables. I will try that, I don't know why I didn't tried it before... ^^; Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 27, 2014 Author Share Posted July 27, 2014 Yes, it works!!Thank you guys for helping me a lot, without the help this game would be only a few ideas in my mind. I only need one more step, let's see if I can do it alone. ^^ Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 28, 2014 Author Share Posted July 28, 2014 Oh, one last thing on this topic, do you guys mind if I post the game here with a CC license?I'm mentioning this just in case there's a policy about that in these forums and because you guys helped me a lot so I feel like I'm on a group. It's my first one, so I don't know exactly what to do... Link to comment Share on other sites More sharing options...
Dumtard Posted July 28, 2014 Share Posted July 28, 2014 There are several places you can post it,http://www.html5gamedevs.com/forum/8-game-showcase/http://www.html5gamedevs.com/topic/1975-game-list-of-phaser-games/http://pgl.ilinov.eu/ lewster32 and WhiteSoul 2 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 28, 2014 Author Share Posted July 28, 2014 Thank you so much for the links Dumtard, they will be very useful. Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 By all means! Post it on the Game Showcase forum WhiteSoul 1 Link to comment Share on other sites More sharing options...
WhiteSoul Posted July 28, 2014 Author Share Posted July 28, 2014 Nice, thank you. I was thinking doing that because I have an open topic, so I can place it there. Link to comment Share on other sites More sharing options...
Recommended Posts