1

I need to make a game board - using an array - for a Bomberman game remake in Processing.

This means the game board / array (which is rather large [9x9] and has 3 values [a,b,c] throughout), has to be able to:

  • Define the color/sprite of the according fields
  • Set the limit for where the character can walk
  • Have unique properties for each value/field (one value represents the open space where the player can move around, another is a solid block, and another one breaks when a bomb is blown up next to it and transforms into an open field type)

I'm pretty much a programming noob and I barely a clue how to make all of this work.. I've already set up the array though which look like this:

int [][] board =  { 
{b, b, b, b, b, b, b, b, b},  
{b, a, b, a, b, a, b, c, b}, 
{b, c, c, a, a, a, a, a, b},
{b, c, a, a, c, a, a, a, b}, 
{b, c, c, b, a, b, c, a, b}, 
{b, a, c, a, a, a, a, a, b}, 
{b, b, a, b, c, b, b, c, b}, 
{b, a, a, a, c, a, a, c, b}, 
{b, b, b, b, b, b, b, b, b}  };

And I have managed to draw it as a monochrome chessboard. Now I just have to figure out how to give each value the properties of the according block type.

Thanks for any help in advance :)

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
Unarmed
  • 11
  • 3

2 Answers2

0

Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:

You need to break your problem down into smaller pieces and then approach each of those pieces one at a time.

For example, I'd start with a simple program that just draws a grid of squares. Then work your way up from there: can you make it so the number of squares is a variable (or two variables) that you define at the top of your sketch? Now make it so each square is a different color. Now make it so each square is reading from the array.

Work your way up in small pieces, and if you get stuck, post a MCVE in a new question and we'll go from there. Good luck.

Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • That's what I did and I have a b&w grid with variables for rows and columns displaying, but I can't figure out how to color it right now. – Unarmed May 21 '17 at 14:45
  • @Unarmed What have you tried? Have you tried using an `if` statement to decide which color each square should be? – Kevin Workman May 21 '17 at 15:49
  • Yes but I didn't manage.. I asked in [this](http://stackoverflow.com/questions/44101117/processing-how-can-i-color-the-squares-drawn-by-my-2d-array-in-different-colors) question for that exact problem. – Unarmed May 21 '17 at 19:48
-1

Going off of what Kevin Workman said, here is code you could possibly use for a grid of squares:

void setup(){
  size(800, 800);
  background(255, 204, 5);
  fill(158, 10, 10);
  for(int i = width/8; i <= width; i += width/4){
     for(int v = height/8; v <= height; v += height/4){
        rect(i, v - height/8, width/8, height/8);
        rect(i - width/8, v, width/8, height/8);
     }
  }
}

It's not necessarily an array, but a for loop does the job.