JoC #29: Viewer questions: timers

      Time is an illusion. Lunchtime doubly so.
            — Douglas Adams

We are starting a new, probably more or less regular, thing today: answering viewer questions.

In the first of the Q&A episodes, I am talking about timers: How to arrange something to happen after a specific time delay. This principle is generally useful for many games and simulations. We also get  bit more practice with int variables.

Download video

Concepts discussedtime delay, variables, counting


JoC #28: Return of the object interaction

      If life gives you lemons – keep them. Because, hey. Free lemons.
            — Anonymous

In this episode, we’re continuing from the last episode’s theme and investigate and compare an alternative structure for making our Ball and Counter objects cooperate. We also have a first brief look at casting.

Recognising alternatives is a good skill, and it slowly eases us into discussions about code quality, which we will get to in more detail later.

Download video

The download today (below) is the scenario as it is at the end of this episode. However, try to add a counter into one of your own scenarios to make sure you are fully taking in what’s going on here.

Concepts discussedobject interaction, casting, score counting

Download: breakout-v3.zip  (the scenario at the end of this episode)

JoC #27: Object interaction – a second look

      Daring ideas are like chessmen moved forward; they may be beaten,
      but they may start a winning game.
            — Goethe

In this and the next episode, we’re looking a bit more into how to set up object structures, and how to get them to interact. This is one of the most fundamental concepts of object-oriented programming, so you need to get your head around this.

We discuss this here with the example of integrating our counter object into a scenario.

Download video

Concepts discussedobject interaction, object references, score counting, constructors, fields

Download: breakout-v2.zip  (the scenario at the end of this episode)

JoC #26: How to display text

      Teamwork is essential; it allows you to blame someone else.
            — Finagles’ 8th Rule 

One of the frequently asked questions is how to display text in Greenfoot scenarios. Today I’ll answer that question.

I discuss two things: How to display some static text (text that does not change, such as instructions), and how to display text that should change during the program run. We’ll do that by making our own score counter.

Download video

Concepts discussedDynamic images, text display, GreenfootImage, score counting

JoC #25: Dealing with errors

      We learn wisdom from failure much more than from success. We often discover
      what will do, by finding out what will not do; and probably he who never made a
      mistake never made a discovery.
            — Samuel Smiles

We’re talking about errors today. I’m sure you all have – like me – got your fair share of errors when you were programming. I’ll talk a bit about how to go about investigating what went wrong when you get an error.

In doing this, we’re discussing the important distinction of synax errors and semantic errors, and we’re learning to deal with both. This includes reading stack traces.

Download video

Concepts discussed: syntax errors, runtime errors, stack trace, exception

JoC #24: Smoke and mirrors

      The ideals which have lighted me on my way and time after time given me new 
      courage to face life cheerfully, have been Truth, Goodness, and Beauty. . . . The 
      ordinary objects of human endeavour — property, outward success, luxury — have
      always seemed to me contemptible.
            — Albert Einstein

One more quick one about image effects: a smoke effect to be precise. I’ll show you how to create this really cool effect just with what you know already. Hopefully, this will give you some ideas of more cool effects that you can do on your own.

Download video

Concepts discussedimage manipulation, visual effects, animation

Download: The project can be downloaded from the Greenfoot book website.

 

JoC #23: Animating the image

      A positive attitude may not solve all your problems,
      but it will annoy enough people to make it worth the effort.
            — attributed to Herman Oliver Albright

A last little bit before we leave our coloured circles behind: an animation. In this case, it’s a very simple one: fading out the circles. But it shows an important technique: The appearance of an actor can change all the time, if we want to. This is the basis for many visual effects.

And, we finally see an if-statement with an else clause! I can’t believe that it took this long for this to pop up.

Download video

Concepts discussedtransparency, dynamically changing images, if-statement


JoC, Teacher Commentary 22: Tracing control flow

      Mathematicians are like Frenchmen: whatever you say to them they translate
      into their own language and forthwith it is something entirely different.
            — Goethe, Maximen und Reflexionen

Tracing control flow (either through control structures, such as if-statements or loops) or through method calls, is hard for beginners.

This episode shows you how to use the debugger to make this clearer.

Download video

Concepts discussedcontrol flow, tracing, breakpoints, debugger

JoC #22: Refactoring for good style

      We are accustomed to see men deride what they do not understand, and snarl
      at the good and beautiful because it lies beyond their sympathies.
            — Goethe

Okay, time to get a little more professional again: Let’s clean up our code a little.

Writing in good style is really important, so today I’ll show you a bit about refactoring. Especially, we want to create short, clear methods. (The technical term for it is cohesion – we want highly cohesive methods.)

Download video

Concepts discussed: methods, refactoring, style, cohesion

JoC #21: Image manipulation – take two

      For every action, there is an equal and opposite criticism.
             — Steven Wright

We’re getting a bit further into image manipulation. I’ll show you how an actor can change appearance by dynamically changing its image while the program is running.

Download video

Concepts discussedimage manipulation, random numbers

Downloads: bounce.zip  bounce-v1.zip