Kodeco Forums

How To Make A Game Like Bomberman

Ever wanted to blow up your friends? Learn how to make a game like Bomberman in this step by step tutorial that will have you setting bombs off with ease.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1136-how-to-make-a-game-like-bomberman

Iā€™m disappointed that the tutorial starts when game is already playable. Could have been a great tutorial but I donā€™t think Iā€™m learning much from more than half of game already set up :frowning:

Hi @r0gerblack, Iā€™m sorry to hear that.
We strive to make tutorials that highlight the interesting parts that build on a simple base and I understand this might not be ideal for everyone. Some people want to start with a blank slate.

In this case, Iā€™ve provided the level geometry and player movement with rigidbody based collision.
These concepts are explained in our more starting tutorials (https://www.raywenderlich.com/category/unity).
The boilerplate code thatā€™s unique to this tutorial can be found in the Assets/Scripts folder of the Starter Project and is fully commented so you can understand what every part does and why itā€™s there.

I hope Iā€™ve helped explain why the tutorial is already kind of playable from the start and I encourage you to give it a chance, Iā€™m willing to bet youā€™ll learn a lot from it even though we donā€™t start out from nothing. :smile:

Have a good day!

@blackdragonbe Awesome tutorial!!

@jecht83 Thank you! :smile:

Hi @blackdragonbe , Thank you for your tutorial, it is so helpful for a beginner like me, i have done ur game. But now i trying to add a block which can be destroyed, i used OnTriggerEnter to destroy it, but if i use RaycastHit to make Explosion not go through it, it cant be destroy by OnTriggerEnter, i am just beginner and not smart, please help me the code, my English is not very good, so sorry about that.

Hi @blackdragonbe, i have a stupid mistake when let size of collider of Explosion too small so it cant reach the blocks, i have read some tutorials about this game, but your tutorial is the best, it so easy to understand the code, thank you so much, i want to add some features to make it more interesting, if i cant go somewhere, hope u help me. This game went with my childhood, i love it so much.

Hi @luongtien!

Iā€™m glad to hear you enjoyed the tutorial :smile:
Donā€™t be too hard on yourself, we all have to begin somewhere and Iā€™m honored you chose my tutorial as one of your first.
Bomberman was also one of my favorite games as a kid, I loved to play it with my younger brother. Itā€™s one of the reasons I chose that particular game to draw inspiration from.

Be sure to share some screenshots, Iā€™d love to see what youā€™re doing with the project to expand on it!
If you get into trouble, feel free to ask me, Iā€™ll try to answer any questions to the best of my ability.

Cheers!

Hi @blackdragonbe !

Im so happy when hear u said that, you are so kind. :blush:o
Today i got this problem, i want to blow up block 4, but when explosion goes through block 1,2,3, it blows up them too, becuz the size of collider of explosion is same as block.
I use OnTriggerEnter2D , i put it in class Destroysefl. Did i go right way, please help me.

Thank you so much !!!

Hi! Very nice tutorial, thank you for sharing it with us. I think there is a step missing, I need to create a tag ā€œExplosionā€ and assign it to the Explosion prefab to make the chain explosion works. Maybe it happened to me because I cant open the project directly in Unity 5.3.5f1 and created a new project to import the assets.

Hi again @luongtien!

You can probably solve your problem by making the explosion collider a tiny bit smaller (scale it down to 0.95 instead of 1 for example) so it wonā€™t touch anything outside its bounds.

As for the placement of your code, the DestroySelf class is a small helper class thatā€™s used to make an object destroy itself after x amount of seconds. If you put the collision handling code there you wonā€™t be able to reuse that class for anything else.
I would probably put that sort of logic inside a Explosion class or a DestroyBlocksOnTouch class, depending on if you want to reuse the collision logic for other game objects or not.

Good luck with the project!


Hi there @gbonesso!

Thanks!
Sounds like the tags werenā€™t imported along with the rest of the assets as those are stored in ProjectSettings/TagManager.asset.

You can either add the tag yourself as you have done or overwrite the default TagManager.asset file with the one in the Starter Project.

Cheers!

Hi @blackdragonbe !!!
Thank you when u have time for my problem, i have tried that way, and then i met this problem, explosion cant blow up anything, becuz of the Raycast prevents explosion from going through the block, so block and collider of explosion cant meet each other if we let the size of collider of explosion <1.
I stuck here for 3 days, brick has 2 problem, one is destroyable, two is : explosion cant go through. i cant make 2 things that run at the same time.

I know the last post was a relatively long time ago, so I hope this isnā€™t too late!

Iā€™m trying to use some of your code in my 2d bomberman clone, and Iā€™m having all sorts of problems with the raycasting bit :confounded:

Here is my code, and, before anyone jumps on me: yes, I did convert from physics/raycast to physics2d/raycast2d

The error Iā€™m getting is in the line: Physics2D.Raycast (transform.position + new Vector3 (0.0f, 0.5f, 0.0f), direction, out hit, i);

I keep getting an error that says: cannot convert ā€˜out UnityEngine.RaycastHit2Dā€™ to ā€˜floatā€™

I think itā€™s telling me that it canā€™t convert the Raycast2DHit hit to a float, which makes sense, but when I try to rearrange that line, I get an error that says Use of unassigned local variable ā€˜hitā€™.

So, it seems like Iā€™m getting yelled at for trying to retrieve the info about whether or not my ray hit something, but then getting yelled at again if I donā€™t look for that info.

Please Help!!

Hi @froboy449,
Im doing the same thing like u, convert this project from 3D to 2D, ur problem i have solved, i can give U my project, i have made something new such as, load map from file txt, upgrade item (number of bomb, speed of player), now i am trying make item of power. I think we can contact to talk about this game, do u have any social network, i just use facebook
here is mine: Redirecting...
and this is my gmail: luongtien5293@gmail.com
I hope we can do this project together.
:slight_smile:

Hi @luongtien,

Have you managed to solve your problem yet? You can probably adapt the explosion-player collision code to make sure the breakable blocks get destroyed.

@froboy449:
The signature of Physics2D.Raycast differs from the 3D one, try this:

    RaycastHit2D hit = Physics2D.Raycast(transform.position + new Vector3(0.0f, 0.5f, 0.0f), i);

Hi @blackdragonbe,
I have solved that problem, now trying a to make item of bomb power. i have done with item number of bomb, speed of player. i created class " powerUp" then put it in item PowerUp, and class Bomb, i made a function .
void IncreasePower (){
powerBomb++;
}

Thee item i did the same way, but i dont know class power up not work, i debug i realize that, the value of bomb power in loop for never change although i call function IncreasePower. Do u have any clue for meā€¦Thank U !!!
Here is class PowerUp

using UnityEngine;
using System.Collections;

public class PowerUp : MonoBehaviour
{
void OnCollisionEnter2D (Collision2D other)
{

	if (other.gameObject.tag == "Player") {	
		Bomb.instance.IncreasePower ();
		Destroy (this.gameObject);
	} 
}

}

@blackdragonbe Wow, I never would have figured that out. I looked through the docs for raycast2d and it seemed like it was exactly the same, except with 2D added, guess I need to work on my reading compe :stuck_out_tongue:

@luongtien Ya man that sounds great. Iā€™m an artist majoring in csc, but coding is definitely my weak point. Wanted to make this game to show off my art and work on my code, so working with someone else, even if itā€™s just throwing ideas and solutions off of them, would be great! Also, is that your daughter in those facebook photos? Sheā€™s adorable!!

Hi @luongtien

Itā€™s hard to say whatā€™s wrong without seeing the new Bomb class, but it seems to me that this line is the culprit:

Bomb.instance.IncreasePower ();

The way I would do it is having the following in the Player class:

float bombPower = 1;

public void IncreaseBombPower()
{
  bombPower++;
  // Other stuff that should happen
}

Then you can change the PowerUp OnCollisionEnter2D to this:

 void OnCollisionEnter2D (Collision2D other)
 {

  if (other.gameObject.tag == "Player") {	
	other.GetComponent<Player>.IncreaseBombPower();
	Destroy (this.gameObject);
  } 
}  

Then, if you let the player drop a bomb, set the bombā€™s power the playerā€™s bomb power.
Hope it works out!

@froboy449
Yeah I was a bit confused at first glance as well, I usually let the Intellisense guide me when dealing with complicated method calls :smiley:

Good luck on your cooperation guys!

Cheers!

Hi @blackdragonbe,
Thank you for your clue, it worked well, my mistake is to try change the value of bomb power before the bomb appear.
Now im trying to create some monsters, but i dont know how to make them move random on the map, i saw the bomberman i played when i was small, the monsters automaticaly go out if there was a path when i destroyed bricks. I try to find some sample code, but what i got is " A*", i dont need it now, it is too smart for level 1, do u have any clue for word to search google, i am beginner, so sometimes i dont know use what word to search for my problem.:sweat:

Hi @froboy449,
How about your project ? Is progress still good? and may i ask a question, Intellisence == Intelligence, is it right ?, i search google but no answer.

Intellisence seems to be a typo.

Intelligence is simply the ability to learn new things and apply what has been learned

IntelliSense is the auto complete feature in Visual studio. Check out this video for more information: Visual Studio tutorial: Using IntelliSense effectively | lynda.com

English is fun, isnā€™t it?