resources/sceneintro.lua

changeset 0
bba7a2a225f6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/resources/sceneintro.lua	Thu Aug 22 19:50:12 2013 +0200
     1.3 @@ -0,0 +1,135 @@
     1.4 +-- Top of scene
     1.5 +--print('This is a new scene!')
     1.6 +
     1.7 +-- Initiate scene management
     1.8 +local sceneloc = director:createScene()
     1.9 +sceneloc.name = 'Scene: Intro'
    1.10 +
    1.11 +-- Constants calculated
    1.12 +local dsw = director.displayWidth
    1.13 +local dsh = director.displayHeight
    1.14 +local dmw = director.displayCenterX
    1.15 +local dmh = director.displayCenterY
    1.16 +
    1.17 +-- Instantiate common fonts
    1.18 +local fontSegoe = director:createFont('fonts/SegoeUI-64pt_bold.fnt')
    1.19 +local fontArial = director:createFont('fonts/Arial-96pt_bold.fnt')
    1.20 +
    1.21 +function sceneloc:setUp(event)
    1.22 +    dbg.print('sceneloc:setUp')
    1.23 +
    1.24 +    -- Prepare playing streams
    1.25 +    --audio:stopStream()
    1.26 +    if not audio:isStreamPlaying() then
    1.27 +        audio:loadStream('sounds/vapour.mp3')
    1.28 +        audio:playStream('sounds/vapour.mp3', true)
    1.29 +    end
    1.30 +
    1.31 +    -- Print background
    1.32 +    local rectBack = director:createRectangle({
    1.33 +        x=0, y=0,
    1.34 +        w=dsw, h=dsh,
    1.35 +        strokeWidth=0,
    1.36 +        color={10, 74, 134}, alpha=1})
    1.37 +
    1.38 +    -- Initialize heading labels
    1.39 +    local labTitle = director:createLabel({
    1.40 +        x=0, y=-fontArial.height*1.5/6,
    1.41 +        hAlignment='centre', vAlignment='top',
    1.42 +        font=fontArial,
    1.43 +        text='Astrokaat Instructions',
    1.44 +        color={0xe0, 0xe0, 0xff}
    1.45 +    })
    1.46 +
    1.47 +    -- Initialize heading buttons
    1.48 +    local butInfo = director:createSprite(dsw-fontSegoe.height, dsh-fontArial.height*1.5/6, 'images/butinfo.png')
    1.49 +    butInfo.xAnchor = 1
    1.50 +    butInfo.yAnchor = 1
    1.51 +
    1.52 +    -- Initialize body text labels
    1.53 +    local rectalph = director:createRectangle(fontSegoe.height, fontSegoe.height, dsw - fontSegoe.height * 2, dsh - fontArial.height * 2.25)
    1.54 +    rectalph.color = color.black
    1.55 +    rectalph.color.a = 64
    1.56 +    local labCont = director:createLabel({
    1.57 +        x=fontSegoe.height*2, y=-fontSegoe.height*3.25,
    1.58 +        w=dsw-fontSegoe.height*3, h=0,
    1.59 +        hAlignment='left', vAlignment='top',
    1.60 +        font=fontSegoe,
    1.61 +        text='Keep Astrokaat alive by maintaining her health. Eat flying food while avoiding space obstacles. Direct Astrokaat about by pushing on the screen.'
    1.62 +    })
    1.63 +
    1.64 +    -- Initialize body buttons
    1.65 +    local butRules = director:createSprite(fontSegoe.height*2, fontSegoe.height*2, 'images/butrules.png')
    1.66 +    local butStart = director:createSprite(dsw-fontSegoe.height*2, fontSegoe.height*2, 'images/butstart.png')
    1.67 +    butStart.xAnchor = 1
    1.68 +    butStart.yAnchor = 0
    1.69 +
    1.70 +    -- Good transitions: slideInL/R, shrinkGrow, crossFade, fadeTR/BL, pageTurn, progressVertical
    1.71 +    local transoptl = {transitionType = 'slideInL', transitionTime = 0.5}
    1.72 +    local transoptr = {transitionType = 'slideInR', transitionTime = 0.5}
    1.73 +    local transoptt = {transitionType = 'slideInT', transitionTime = 0.5}
    1.74 +    local transoptb = {transitionType = 'slideInB', transitionTime = 0.5}
    1.75 +
    1.76 +    -- Implement event handlers
    1.77 +    function butInfo:touch(event)
    1.78 +        if event.phase == 'began' then
    1.79 +            table.insert(nodeLastscene, director:getCurrentScene())
    1.80 +            table.insert(nodeLasttrans, transoptb)
    1.81 +            director:moveToScene(sceneAbout, transoptt)
    1.82 +        end
    1.83 +        return true
    1.84 +    end
    1.85 +    butInfo:addEventListener('touch', butInfo)
    1.86 +
    1.87 +    function butRules:touch(event)
    1.88 +        if event.phase == 'began' then
    1.89 +            table.insert(nodeLastscene, director:getCurrentScene())
    1.90 +            table.insert(nodeLasttrans, transoptr)
    1.91 +            director:moveToScene(sceneRules, transoptl)
    1.92 +        end
    1.93 +        return true
    1.94 +    end
    1.95 +    butRules:addEventListener('touch', butRules)
    1.96 +
    1.97 +    function butStart:touch(event)
    1.98 +        if event.phase == 'began' then
    1.99 +            table.insert(nodeLastscene, director:getCurrentScene())
   1.100 +            table.insert(nodeLasttrans, transoptl)
   1.101 +            director:moveToScene(sceneBegin, transoptr)
   1.102 +        end
   1.103 +        return true
   1.104 +    end
   1.105 +    butStart:addEventListener('touch', butStart)
   1.106 +end
   1.107 +
   1.108 +function sceneloc:tearDown(event)
   1.109 +    dbg.print('sceneloc:tearDown')
   1.110 +    --self.releaseResources()
   1.111 +    --self.<obj-here> = self.<obj-here>:removeFromParent()
   1.112 +    --self.obj0:removeFromParent()
   1.113 +    --self.obj1:removeFromParent()
   1.114 +    --self.obj0 = nil
   1.115 +    --self.obj1 = nil
   1.116 +end
   1.117 +
   1.118 +function sceneloc:enterPreTransition(event)
   1.119 +    dbg.print('sceneloc:enterPreTransition')
   1.120 +end
   1.121 +
   1.122 +function sceneloc:enterPostTransition(event)
   1.123 +    dbg.print('sceneloc:enterPostTransition')
   1.124 +end
   1.125 +
   1.126 +function sceneloc:exitPreTransition(event)
   1.127 +    dbg.print('sceneloc:exitPreTransition')
   1.128 +end
   1.129 +
   1.130 +function sceneloc:exitPostTransition(event)
   1.131 +    dbg.print('sceneloc:exitPostTransition')
   1.132 +end
   1.133 +
   1.134 +sceneloc:addEventListener({'setUp', 'tearDown', 'enterPreTransition',
   1.135 +    'enterPostTransition', 'exitPreTransition', 'exitPostTransition'}, sceneloc)
   1.136 +
   1.137 +return sceneloc
   1.138 +

mercurial