JoC #17: Bouncy coloured balls

      Debugging is twice as hard as writing the code in the first place.
      Therefore, if you write the code as cleverly as possible, you are,
      by definition, not smart enough to debug it.
            — Brian W. Kernighan.

We’re leaving the ‘Trick, the turtle’ scenario this week to make something new completely from scratch.

The main purpose here is to piece together everything we have seen to far about the structure of a class, and create a complete new class (with fields, constructors and methods).

Yes, I know, this doesn’t sound too exciting. I can see from the video view numbers that videos dealing with review of concepts aren’t quite as popular as the ones showing new stuff.

So: Don’t worry. I’ve thrown a few interesting new things in as well: dynamically changing images, string concatenation and multiple constructors are some of them. Oh yes, and a first run-in with a runtime exception!

Download video

Concepts discussedclass structure, field, constructor, method, default constructor, changing images


13 thoughts on “JoC #17: Bouncy coloured balls

  1. It is good to see the video. Nice one!

    I am teaching my kids for Greenfoot game too.
    for the key board event, it works fine, but we still can not program for mouse event control yet. Can you be so kindly to show us some examples about mouse control?
    Thanks in advance.

  2. We are up to chapter 5 in the book and have just done the Piano. It would be great if you could do another video – one on loops and arrays. There is so much new terminology and concepts to understand.
    Your videos are terrific. I am lucky to have a great teacher; Ed Parrish who made a really cool Java Jeopardy game that is in the Greenfoot scenario gallery.

  3. I will!

    But it will not be one of the next – I want to do things pretty much in sequence, and I’ll need a few more videos until I get to it. But I will.

    Michael

  4. Pingback: JOC #17 – Bouncing Coloured Balls - compu2Learn.co.uk

  5. Pingback: El júbilo de programar – Videotutoriales | CyberHades

  6. do you have links to where all the code is written up so i dont have to keep back tracking the video and can just look at it on my screen?

  7. Michael,

    At the 13:00 minute mark, how did you get the context-sensitive help to pop up showing the class methods? That is very helpful and I can’t find the key combination.

    Thanks and love the videos.

  8. Is there any way to make the balls properly bounce? By properly bounce I mean at a right angle, so if it approached the bottom of the world (assuming the horizontal line to the right was 0/360) at 225 degrees, it then go off at 315 degrees. I’ve tried but failed. Any help?

  9. Why bounce at 90 degrees? The angle at which it bounces off is different every time. This is the code that I used:
    public boolean atWorldEdge()
    {
    if(getX() getWorld().getWidth() – 10)
    {
    turn(180-(2*getRotation()));
    return true;
    } else if(getY() getWorld().getHeight() – 10)
    {
    turn(360-(2*getRotation()));
    return true;
    };
    return false;
    }
    Then in the act() method:
    move(6);
    if (atWorldEdge())
    {

    changeImage();
    Greenfoot.playSound(“Boing.wav”);
    }
    And it bounces perfectly!

  10. Great tutorials
    Question in my senario when the ball hits the bottom of the world it sticks and slides either left or right how would this be fixed ? I feel it has to do with The atWorldEdge method ?

    Also would an object interaction method be the same as the atWorldEdge for the balls that come incontact with each other ?
    I.e Balls hit each other they bounce of in diff directions

  11. –Mik said: ” I can see from the video view numbers that videos dealing with review of concepts aren’t quite as popular as the ones showing new stuff.”

    Are you sure it is counting unique views? Could be the same viewers are watching the new stuff more often because they are grasping new concepts, whereas review is covering something they already have learned and hopefully don’t have to re-watch. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *