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

2018/4/4

I need to remove an object

erchainis erchainis

2018/4/4

#
I'm creating a bubble shooter game with four different colors, where I have bubbles at the top of the world and one on the bottom of the world. Whenever I press space-bar the bubble on the bottom starts moving and whenever this one hits or touches another bubble this one immediately stops. After that the program should check if this ball is touching or is adjacent to at least two or more bubbles of the same color in order to be eliminated from the world.
danpost danpost

2018/4/4

#
erchainis wrote...
I'm creating a bubble shooter game with four different colors, where I have bubbles at the top of the world and one on the bottom of the world. Whenever I press space-bar the bubble on the bottom starts moving and whenever this one hits or touches another bubble this one immediately stops. After that the program should check if this ball is touching or is adjacent to at least two or more bubbles of the same color in order to be eliminated from the world.
Which part are you having difficulties with? What have you tried? Show some code/effort.
erchainis erchainis

2018/4/4

#
    public void act() 
    {

        
        xCurr+=speedX;
        yCurr+=speedY;
        
        setLocation((int) xCurr, (int) yCurr);

        World w = getWorld();
        if (xCurr<0) 
{
            exactX -= xSpeed;
            xSpeed = -xSpeed;;
 }
       else if (xCurr>w.getWidth()-1)
{
 
            exactX -= xSpeed;
            xSpeed = -xSpeed;
}        
        iif(exactY <= 0)
        {
            getWorld().removeObject(this);
        }   
        
        List<Bubble> bumpingInto = this.getIntersectingObjects(Bubble.class);
        
        int bubbleCount =0;
        
        for(Bubble bumper: bumpingInto)
        {
            
            bumpCount++;
        }
        
        if (bumpCount>=2)
        {
            speedX = 0;
            speedY = 0;
        }
I kind of frustrate because IT DOES NOT SET the location properly this code stops the ball to stick to one another but somethime to far or over the other one.
erchainis erchainis

2018/4/4

#
Obviously my code way longer I just tried to post where Im having trouble with. I tried by comparing their color but I couldn't because maybe I'm not initializing the color properly. i tried something like Color nameColor = Color.BLUE; Color nameColor2 = Color.BLUE; Color nameColor3 = Color.BLUE; Color nameColor4 = Color.BLUE; And tried to give this characteristic to the bubble once I created
danpost danpost

2018/4/4

#
How does your code even compile? Line 22 should fail as iif is not a keyword. Also, where is bumpCount does not appear to be declared as a variable. You wrote that you tried to compare colors and maybe initializing was a problem. Where is the codes for all that? as well as for giving characteristic to the bubble.
You need to login to post a reply.