Working on my variation of breakout. I have power up balls that randomly spawn underneath the blocks. That's working well. however, I need to check when a block is removed so a ball can drop.
This is for the random spawning blocks. I am also storing the object locations of both the blocks and powerUp balls in two separate ArrayLists.
Basically this is supposed to check if the X of both the corresponding block and powerup pairs are the same, and if not, give permission for the power up to move. HOWEVER, I am using getWorld.removeObject() to remove the blocks so my method throws an IllegalStateException(accessing removed objects location). So my problem is what happens to the coordinates of the removed object? I believe I previously caught the error for another part of my program since the error was useless, and it seems the coordinates of the removed object remain the same but it's just not visible? Not sure. anyway to get around this? Much appreciated =D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public void spawnPowerUp() { if (counter < 3 ) { counter++; int rand = Greenfoot.getRandomNumber(((Board) getWorld()).getBlockList().size()); int x = ((Board) getWorld()).getBlockList().get(rand).getX(); int y = ((Board) getWorld()).getBlockList().get(rand).getY(); blockList.add(((Board) getWorld()).getBlockList().get(rand)); powerUpList.add( new PowerUp()); getWorld().addObject(((PowerUp)powerUpList.get(powerUpList.size()- 1 )), x, y); ((Board) getWorld()).getBlockList().remove(rand); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | public void isTouching() { for ( int i = 0 ; i < Block.blockList.size(); i++) { int powerUpX = Block.powerUpList.get(i).getX(); int blockX = Block.blockList.get(i).getX(); if (blockX != powerUpX) Block.powerUpList.get(i).moving = true ; } } |