Section 4

Laser On Mirror Cell

The blank cells and target cell now draw in the laser beam. The mirror cells are next. The simple approach would be to draw both the horizontal and vertical laser beams fully across a mirror cell. Then use the masking technique we applied for the target cell to clip off the portion of the mirror cell where the laser does not belong. The final step would be then to redraw the mirror itself, exactly as we did on the target cell.

We can re-use much of the code already written for the other cells. Begin by writing new stub instance methods on the MirrorCellRenderer to ignore the mask requests until we work that part out.

maskOffHorizontalOn: aMask

maskOffVerticalOn: aMask

We need to do a little refactoring of the rendering inside the MirrorCellRenderer. Add this new instance method.

    self cell isLeft
        ifTrue: [self renderContentsLeanLeft]
        ifFalse: [self renderContentsLeanRight]

Modify the #renderContents method to use this new code.

     self fillBackground.
     self renderMirror

Now we can add a method to draw the laser beam. This will be our first pass at how this can work.

     self cell isOff ifTrue: [^self].
     self renderLaserVertical.
     self renderLaserHorizontal.
     self renderMirror.

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels