Section 4

Let's add a counter to show the length of the laser beam path. Add the following instance methods to the LaserGame class.

wrapPanel: aPanel label: aLabel
    "wrap a panel in an alignmentMorph and put a label above it"
    | column strM |
    column := AlignmentMorph newColumn
                wrapCentering: #topLeft;
                cellPositioning: #topLeft;
                hResizing: #spaceFill;
                vResizing: #shrinkWrap;
                borderWidth: 2;
                layoutInset: 5;
                color: Color transparent;
                useRoundedCorners;
                borderStyle: (BorderStyle complexAltInset width: 2).
    column addMorph: aPanel.
    strM := StringMorph contents: aLabel.
    strM color: Color veryVeryLightGray.
    column addMorph: strM.
    ^ column

Warning: Some students may be using Pharo instead of the vanilla Squeak development environment with this tutorial. I have not checked out how Laser Game works on Pharo yet, but I will. But I can tell you that in the current Pharo release (as of October 21, 2009) the LedMorph is absent. It was recommended to me that the student should be able to install the missing LedMorph by downloading it from the Pharo repository here: http://www.squeaksource.com/PharoMorphicExtras. I have not tried this myself, and this is only a problem for students using Pharo instead of Squeak 3.9 or Squeak 3.10.

makeLaserPathCounterMorph
    | count |
    count := LedMorph new
                digits: 3;
                extent: 3 * 10 @ 15;
                setBalloonText: ''.
    count color: (Color r: 0.674 g: 0.674 b: 0.96).
    count name: 'laserPath'.
    ^ self wrapPanel: count label: 'Laser Path'

addCountersToPanel: panel
    panel
        addMorph: self makeLaserPathCounterMorph
        fullFrame: (LayoutFrame
            fractions: (0 @ 0 corner: 1 @ 0)
            offsets: (4 @ 4 corner: -8 @ 44))

Now we add the new counters by modifying the #makeControlPanelMorph method.

makeControlPanelMorph
    | panel |
    panel := RectangleMorph new borderWidth: 0;
                 color: Color transparent;
                 layoutPolicy: ProportionalLayout new.
    self addButtonsToPanel: panel.
    self addCountersToPanel: panel.
    ^panel

Open up our LaserGame morph again and see the new panel.

Now we want to make the digits change...

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels    stevewessels@me.com