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

2013/10/15

Help with Adding Object

1
2
Zamoht Zamoht

2013/10/18

#
You wrote the if statements wrong in the Ball class. The Time can't be lower than 10001 and higher than 20000 at the same time. This means that it will go to the last statement and the speed will be 8.
gdwd3 gdwd3

2013/10/19

#
Oh wow. Your right, thanks. :D I can't believe I did that. Thanks for the help! :D
danpost danpost

2013/10/19

#
(1) You need to have the Ball objects remove themselves when they hit the bottom edge of the window. (2) You need a way to end the game -- maybe have a certain number of lives? (3) You may want to decrease the time between speed incrementing (3 minutes between is large) I think I would have coded the timer and speed parts more like this:
// in the world class
// instance field
private int timer;
// in act method (still in world class)
if (!getObjects(Player.class).isEmpty())
{
    timer = (timer+1)%600;
    if (timer == 0) Ball.speed++;
    if (timer%30 == 0)
    {
        addObject(new Ball(),Greenfoot.getRandomNumber(503)+48, 17);
        addObject(new Ball(),Greenfoot.getRandomNumber(503)+48, 17);
    }
}

// in the Ball class
// class field
static int speed = 2;
// remove the 'Speed' method with its call from act
// remove the 'Time' field and the 'Ball' constructor method


// in the Player class
// remove the count field and the 'AddBall' method with its call from act
// remove the Timer field and the 'Time' method with its call from act
You need to login to post a reply.
1
2