This site requires JavaScript, please enable it in your browser!
Greenfoot back
Nooooob
Nooooob wrote ...

2017/3/9

Need help

1
2
3
danpost danpost

2017/3/11

#
Super_Hippo wrote...
Still, if you move and check intersection for each block alone, it can move upon another block of this tetromino.
Good point. They would all need moved first, then the checks for intersecting other blocks would need to be tested afterwards. If any intersections occur, they all would then need to be moved back. I started one to see how I would create a Tetris-like game. My code is quite different from what is given in this thread. However, I did set up the movement properly without thinking about this particular aspect of it. Probably because of how I have my classes set up.
Nooooob Nooooob

2017/3/11

#
Super_Hippo wrote...
private boolean moveTetromino(int dir)
{
    boolean result = true;
    for (Block block : tetromino) block.fall(dir);
    for (Block block : tetromino) result = result && block.fall(0);
    return result;
}
Doesn't really look optimal, but test this for now.
danpost wrote...
Therefore, line 4 of the method should be:
return getObjectsAtOffset(0, 0, Block.class).size() == 1;
My apologies.
Changed both. This happens now:
Super_Hippo Super_Hippo

2017/3/11

#
You need another condition in the fall method which checks if it reached the bottom.
return getObjectsAtOffset(0, 0, Block.class).size() == 1 || getY() == getWorld().getHeight()-1;
Nooooob Nooooob

2017/3/11

#
Super_Hippo wrote...
You need another condition in the fall method which checks if it reached the bottom.
return getObjectsAtOffset(0, 0, Block.class).size() == 1 || getY() == getWorld().getHeight()-1;
Done. What happened in the pic before still happens.
Super_Hippo Super_Hippo

2017/3/11

#
Could it be that the images of the blocks are 50x50 and not 40x40 like the cellsize of the world? The 'thunder' should also be 1 1 0 0 0 1 1 0 ... You messed up the second line.
Nooooob Nooooob

2017/3/11

#
Super_Hippo wrote...
Could it be that the images of the blocks are 50x50 and not 40x40 like the cellsize of the world? The 'thunder' should also be 1 1 0 0 0 1 1 0 ... You messed up the second line.
Yup. Correction:
Super_Hippo Super_Hippo

2017/3/11

#
Oh, it should be != instead of == I think:
getY() != getWorld().getHeight()-1
Actually, this will probably prevent the tetromino from falling to the bottom line at all, but report the result with this change. But if it happens, you can solve this by adding 'false' in the world constructor:
super(15, 20, 40, false);
and then remove the -1 from the code above. Nice images and gifs btw. I wish everyone would be like you and do the opposite of just saying "it is not working".
Nooooob Nooooob

2017/3/11

#
Super_Hippo wrote...
Oh, it should be != instead of == I think:
getY() != getWorld().getHeight()-1
report the result with this change
Super_Hippo wrote...
But if it happens, you can solve this by adding 'false' in the world constructor:
super(15, 20, 40, false);
and then remove the -1 from the code above.
Super_Hippo wrote...
Nice images and gifs btw. I wish everyone would be like you and do the opposite of just saying "it is not working".
Thx :)
Nooooob Nooooob

2017/3/13

#
Side question, is it a good idea to control the Tetrominos like this?: Block class
public void act()
    {
        move();
    }
   
public void move()
    {
        if (Greenfoot.isKeyDown("left"))
        {
            setLocation(getX() - 1, getY());
        }
        if (Greenfoot.isKeyDown("right"))
        {
            setLocation(getX() + 1, getY());
        }
    }
Super_Hippo Super_Hippo

2017/3/13

#
Theoretically, it should be done the same way as the blocks falling. So in the world, check for a key press, move all 4 pieces, if it fails (touches block or reached edge), move it back to where it was. "Theoretically" because it doesn't really work as it should I guess.
danpost danpost

2017/3/13

#
Super_Hippo wrote...
Theoretically, it should be done the same way as the blocks falling. So in the world, check for a key press, move all 4 pieces, if it fails (touches block or reached edge), move it back to where it was. "Theoretically" because it doesn't really work as it should I guess.
Yes, all blocks of each tetromino should be moved together at the same time, then collision checking should be performed for all the blocks and upon any collision encounters, they are all moved back together. With a bounded world, two blocks of the same tetromino will be found colliding upon edge encounters; so only block-to-block collisions need be checked. It is achievable. However, think about what issues you might have when it comes to rotating the Tetromino blocks around each other and keeping them in shape form. Think about where the pivot point might be with each shape and how the rotation might be achieved. Currently, you are just working with moving the blocks uniformly horizontally and vertically and having difficulties. I am afraid that even I might have some difficulties in acquiring the proper behavior with the current design set-up. When I did my mock version, I did things quite differently.
You need to login to post a reply.
1
2
3