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

2012/1/6

@Akuhano about Brick breaker

danpost danpost

2012/1/6

#
Until the compiling of your scenario is resolved, it is best not to have your scenario uploaded on the Greenfoot site. The first thing I noticed upon inspection of your code, is that in the world class constructor, you have some code that should probably be in the act() method of the world, not in the constructor. The code I am refering to is:
        if(ball.getY() > paddle.getY())
        {
            count++;
        }
        
        if(count == 1)
        {
            removeObject(life3);
        }
        
        if(count == 2)
        {
            removeObject(life2);
        }
        
        if(count == 3)
        {
            removeObject(life);
        }
EDIT: I do not know why this posted 3 times!?!?
davmac davmac

2012/1/6

#
I've deleted the duplicates.
Akuhano Akuhano

2012/1/6

#
I fixed the compiling issues, now I'm just trying to fix the life counter, as well as make the bricks disappear upon being hit. I'll re-upload the code after I get home, because I'm currently at school. Thanks for your help (:
danpost danpost

2012/1/12

#
Alright, I had a look at your code for your project. The main issue with the paddle not being detected is due to the fact that you may one time move the ball on the paddle, BUT not at or below the center of the paddle where you check looks at, then the next move puts it past the paddle, so again it will not reverse direction. I changed the check in checkPaddle to 'if (paddle != null && getY() - deltaY < paddle.getY())' and that seemed to work). The ball does appear to penetrate the paddle before reversing direction, but at least it is not going through and ignoring it. I also tried 'if (paddle != null)' without the position check and it seems to work similarly.
Akuhano Akuhano

2012/1/12

#
That seemed to work, the ball stops going through the paddle, but it seems to rest inside of the paddle for a moment. But that's better than having the player lose their life completely. Thanks so much for the help x]
danpost danpost

2012/1/13

#
I modified the code to the following and its appearance is much better
        if (paddle != null)
        {
            deltaY = -deltaY;
            int offsetY = getY() - paddle.getY();
            int offsetX = getX() - paddle.getX();
            setLocation(getX(), paddle.getY() + offsetY + deltaY);
            deltaX = deltaX + (offsetX/10);
            // etc.
Akuhano Akuhano

2012/1/13

#
That worked great, thanks. I'm pretty much done with the game now, I just need to add in more levels, and I'll be finished. The only problem now is that when I want to test a new level, I can't beat the previous ones ._.
danpost danpost

2012/1/13

#
Just use the speed slider and slow down the game. You should be able to get by the levels then (use the mouse to move the paddle, as the arrow keys are too slow). You could also temporarily change the order of the levels, so the first one is the one you are working on.
Akuhano Akuhano

2012/1/13

#
Haha yeah, that's what I've been doing with it x]
You need to login to post a reply.