I'm going to give a real quick description right now (I have to run to multi-var) and will check when I get back.
I have the game working such that I can move the figures around the screen. the basics is I have a 2D-array of these "Brick" objects (which is extending "GRect" - from the acm.graphics package)
now I gave this new brick object a "hasStopped" boolean variable, and once the brick hits the bottom of the screen I call it to true.
the reason I need to know if the bricks have stopped is for moving other bricks around, once I call the next brick to the screen I can move over top of the other bricks (which obviously you do not want) now even though I have a basic method which i will write quickly below:
if (keyPress == a /*move left*/ && !playArea[currentFigure.getX() - 1][currentFigure.getY()].hasStopped())
{
then you may do the move left
}
I do call this for all 4 bricks which are currently falling (lets say in a "T" shape) but it is still moving over the bricks, I have not yet had the time to print this variable out as it is being called. but currently I see no reason why this is not working.
Tetris game - block problem.
Started by Grogerian, Sep 30 2009 03:25 AM
1 reply to this topic
#1
Posted 30 September 2009 - 03:25 AM
|
|
|
#2
Posted 30 September 2009 - 04:35 AM
ok so I'm back to multi var :)
here is the brick class-
this is the move left function
I have tried both ! and by itself, neither seem to work.
here is the figure positioning class:
EDIT::: I have determined what is wrong, the ".stop()" function is either not being called correctly, or it is not setting the variable correctly.
EDIT#2::: *facepalm* forget I asked this question :) turns out I was calling my method "drop(nextPiece)" then trying to stop the pieces that had already fallen (which obviously won't get called until my method was done :P) I'll keep this alive for other questions :: I'm sure I will have them ::
EDIT3::: Seeing as I already doubleposted -_- and I don't want to triple post, I will mention that I have ran into a new problem :) breaking a completed row. I am looking forward to ideas *currently stumped*
here is the brick class-
import acm.graphics.GRect;
public class Brick extends GRect {
private final int WIDTH = 40;
private boolean isNotStopped = true;
public Brick(double arg0, double arg1, double arg2, double arg3) {
super(arg0, arg1, arg2, arg3);
}
public boolean isStopped()
{
return isNotStopped;
}
public void stop()
{
isNotStopped = false;
}
}
this is the move left function
if (keyCheck == 'a')
{
if (currentShape.getX(0) > 0 && currentShape.getX(1) > 0 && currentShape.getX(2) > 0 && currentShape.getX(3) > 0&& playArea[currentShape.getX(0) - 1][currentShape.getY(0)].isStopped() && playArea[currentShape.getX(1) - 1][currentShape.getY(1)].isStopped() && playArea[currentShape.getX(2) - 1][currentShape.getY(2)].isStopped() && playArea[currentShape.getX(3) - 1][currentShape.getY(3)].isStopped())
{
playArea[currentShape.getX(0)][currentShape.getY(0)].setVisible(false);
playArea[currentShape.getX(1)][currentShape.getY(1)].setVisible(false);
playArea[currentShape.getX(2)][currentShape.getY(2)].setVisible(false);
playArea[currentShape.getX(3)][currentShape.getY(3)].setVisible(false);
currentShape.setX(0,currentShape.getX(0) - 1);
currentShape.setX(1,currentShape.getX(1) - 1);
currentShape.setX(2,currentShape.getX(2) - 1);
currentShape.setX(3,currentShape.getX(3) - 1);
playArea[currentShape.getX(0)][currentShape.getY(0)].setColor(figureColor);
playArea[currentShape.getX(1)][currentShape.getY(1)].setColor(figureColor);
playArea[currentShape.getX(2)][currentShape.getY(2)].setColor(figureColor);
playArea[currentShape.getX(3)][currentShape.getY(3)].setColor(figureColor);
playArea[currentShape.getX(0)][currentShape.getY(0)].setVisible(true);
playArea[currentShape.getX(1)][currentShape.getY(1)].setVisible(true);
playArea[currentShape.getX(2)][currentShape.getY(2)].setVisible(true);
playArea[currentShape.getX(3)][currentShape.getY(3)].setVisible(true);
}
}
I have tried both ! and by itself, neither seem to work.
here is the figure positioning class:
import java.awt.Color;
public class Figure {
public int shapeT = 0;
public int shapeS = 1;
public int shapeL = 2;
public int shapeRL = 3;
public int shapeI = 4;
public int shapeBox = 5;
public int shapeIL = 6;
public int shapeIRL = 7;
private int[][] coordinates = new int[4][2];
//Color color = null;
public Figure(int figure, Color color) {
if (figure == shapeT)
{
coordinates[0][0] = 4;
coordinates[0][1] = 0;
coordinates[1][0] = 5;
coordinates[1][1] = 0;
coordinates[2][0] = 6;
coordinates[2][1] = 0;
coordinates[3][0] = 5;
coordinates[3][1] = 1;
//coordinates[4][0] = 4;
//coordinates[4][1] = 4;
}
}
public int getX(int part)
{
return coordinates[part][0];
}
public int getY(int part)
{
return coordinates[part][1];
}
/*public Color getColor()
{
return color;
}*/
public void setX(int part, int value)
{
coordinates[part][0] = value;
}
public void setY(int part, int value)
{
coordinates[part][1] = value;
}
}
EDIT::: I have determined what is wrong, the ".stop()" function is either not being called correctly, or it is not setting the variable correctly.
EDIT#2::: *facepalm* forget I asked this question :) turns out I was calling my method "drop(nextPiece)" then trying to stop the pieces that had already fallen (which obviously won't get called until my method was done :P) I'll keep this alive for other questions :: I'm sure I will have them ::
EDIT3::: Seeing as I already doubleposted -_- and I don't want to triple post, I will mention that I have ran into a new problem :) breaking a completed row. I am looking forward to ideas *currently stumped*
Edited by Grogerian, 30 September 2009 - 05:18 AM.


Sign In
Create Account

Back to top









