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

2023/10/25

I need help with my breakout game!

yesineedhelp yesineedhelp

2023/10/25

#
I’m currently using a Breakout game format. However, I’m stuck on one problem. Alright, so my Actor Block 3 is considered a power up block and when the Block 3 is hit by the ball, it spawns a new Power Up actor allows the ball to speed up, slow down, or add additional time. When the ball touches the Block 3, it adds a new actor, which is one of the power up. What makes this difficult is that I made it so that the Block 3 have a random spawn. And I personally want to the Power up actor to be added into the world under the Block 3 when the ball hits it. Here is my random spawning for Block 4 code, written in my world class:
public void act()
{
int a = Greenfoot.getRandomNumber(9);
Block3 b3 = new Block3();
addObject(b3, a*103 +61, 40);
}
And here is my current code for A power up spawning, currently, it spawns at a specific x and y, written in my Ball’s code:
public void act()
{
deltaY = -deltaY;
int r = Greenfoot.getRandomNumber(3); 
if(r == 0)
{
PowerUp1 pu1 = new PowerUp1();
 getWorld().addObject(pu1,165, 279);
}
}
In short, I want to make the X and Y of the power up to have the same X and Y as the Block 3. How do I do that!?
danpost danpost

2023/10/26

#
yesineedhelp wrote...
here is my current code for A power up spawning, currently, it spawns at a specific x and y, written in my Ball’s code: << Code Omitted >> In short, I want to make the X and Y of the power up to have the same X and Y as the Block 3. How do I do that!?
It is not the ball's responsibility to change a block to a power up. It is the block that changes into a power up.
yesineedhelp yesineedhelp

2023/10/26

#
Thanks! I managed to fix it by using the method "getOneIntersectingObject."
You need to login to post a reply.