Small X/Y Location Problem
Author |
Message |
jadedknight
|
Posted: Thu Jan 15, 2009 10:55 am Post subject: Small X/Y Location Problem |
|
|
PROBLEM SOLVED
The highlighted lines are new and correct. You may now just read the solution.
Hello there, I am trying to take a go at programming a tetris clone It's been alright but I am a tad stuck. Basically as you can see below I am just trying to draw a simple square piece, but comprised of 4 smaller blocks.. The problem I am having is getting the right x and y coordinates so that the block becomes one.
code: | public class Tetromino {
int mesh[][] = new int[5][5];
public int[][] squareTetromino () {
mesh[2][2] = 2;
mesh[2][3] = 1;
mesh[3][2] = 1;
mesh[3][3] = 1;
return mesh;
}
} |
(2 is the pivot block)
code: | public class Playfield extends JPanel {
Tetromino tetromino = new Tetromino();
@Override public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
for(int i = 0; i < tetromino.squareTetromino().length; i++) {
for(int j = 0; j < tetromino.squareTetromino()[i].length; j++) {
if(tetromino.squareTetromino()[i][j] == 1) {
[color=red]g.fill3DRect(100 + (i * 10), 100 + (j * 10), 10, 10, true);[/color]
} else if(tetromino.squareTetromino()[i][j] == 2) {
[color=red]g.fill3DRect(100 + (i * 10), 100 + (j * 10), 10, 10, true);[/color]
}
}
}
}
} |
As you can see from above I am drawing each block in the same place, however fooling around with some while statements and more iteration while incrementing a value, then multiplying it by 10 (the block size) has got me nowhere. Does anyone have any suggestions how I can accomplish this?
EDIT:
Basically, if you see the mesh array, everything is null except where the blocks are. Essentially I want to compute the offsets and translate the block accordingly, however I have not been able to come up with a generic way that will work for all tetris pieces. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|