Section 4

Now all the vertical drawing methods.

renderLaserVerticalMask: aMaskForm color: aColor
    | cellPosn scaledBeam scale trimmedBeam offset rotatedBeam |
    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.
    rotatedBeam := trimmedBeam rotateBy: 90.
    offset := (0 + (CellRenderer cellExtent x - rotatedBeam width) // 2)@(3 + (CellRenderer cellExtent y // 2) negated).
    rotatedBeam
        displayOn: self targetForm
        at: (cellPosn + offset)
        clippingBox: self targetForm boundingBox
        rule: Form oldPaint
        fillColor: aColor

renderLaserVerticalSplatter
    self
        renderLaserVerticalMask: LaserGameForms splatterBeamMask
        color: LaserGameColors laserBeamSplatterColor

renderLaserVerticalCenter
    self
        renderLaserVerticalMask: LaserGameForms centerBeamMask
        color: LaserGameColors laserBeamCenterColor

renderLaserVertical
    self renderLaserVerticalSplatter.
    self renderLaserVerticalCenter.

The last piece is to add the instance method that decides which laser path to use.

renderLaser
    | rotate |
    self cell isOff ifTrue: [^self].
    rotate := self cell activeSegments at: #south.
    rotate
        ifTrue: [self renderLaserVertical]
        ifFalse: [self renderLaserHorizontal].

Index Page Next Page

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