Section 4

Now we write the code to draw the horizontal laser on our target cell.

renderLaserHorizontalSplatter
    self
        renderLaserHorizontalMask: LaserGameForms splatterBeamMask
        color: LaserGameColors laserBeamSplatterColor

renderLaserHorizontalCenter
    self
        renderLaserHorizontalMask: LaserGameForms centerBeamMask
        color: LaserGameColors laserBeamCenterColor

renderLaserHorizontal
    self renderLaserHorizontalSplatter.
    self renderLaserHorizontalCenter.

renderLaserHorizontalMask: aMaskForm color: aColor
    | cellPosn scaledBeam scale trimmedBeam offset masked |
    cellPosn := self offsetWithinGridForm.
    scale := CellRenderer cellExtent * 6.
    scaledBeam := aMaskForm scaledToSize: scale.
    trimmedBeam := Form extent: (CellRenderer cellExtent x)@(scaledBeam height) depth: scaledBeam depth.
    scaledBeam
        displayOn: trimmedBeam
        at: 0@0
        clippingBox: trimmedBeam boundingBox
        rule: Form paint
        fillColor: nil.
    offset := 0@(4 + (CellRenderer cellExtent y - trimmedBeam height) // 2).
    masked := self maskOffHorizontalOn: trimmedBeam.
    masked
        displayOn: self targetForm
        at: (cellPosn + offset)
        clippingBox: self targetForm boundingBox
        rule: Form oldPaint
        fillColor: aColor

The #renderLaserHorizontalMask:color: method is a little different from the once used on the blank cell. There's a new step. The final mask form is masked twice. Here's the method that does that.

maskOffHorizontalOn: aMask
    | newMask halfExtent halfRect offset |
    halfExtent := (aMask width // 2)@(aMask height).
    newMask := Form extent: aMask extent depth: aMask depth.
    newMask fillColor: Color white.
    (self cell activeSegments at: #west)
        ifTrue: [offset := 0]
        ifFalse: [offset := halfExtent x].
    halfRect := (aMask boundingBox origin + (offset@0)) extent: halfExtent.
    aMask
        displayOn: newMask
        at: offset@0
        clippingBox: halfRect
        rule: Form paint
        fillColor: Color black.
    ^newMask

Index Page Next Page

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