resources/scenerules.lua

changeset 0
bba7a2a225f6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/resources/scenerules.lua	Thu Aug 22 19:50:12 2013 +0200
     1.3 @@ -0,0 +1,169 @@
     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: Scoring'
    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 +    ---- Cancel playing streams
    1.25 +    --audio:stopStream()
    1.26 +
    1.27 +    -- Print background
    1.28 +    local rectBack = director:createRectangle({
    1.29 +        x=0, y=0,
    1.30 +        w=dsw, h=dsh,
    1.31 +        strokeWidth=0,
    1.32 +        color={10, 74, 134}, alpha=1})
    1.33 +
    1.34 +    -- Initialize heading labels
    1.35 +    local labTitle = director:createLabel({
    1.36 +        x=0, y=-fontArial.height*1.5/6,
    1.37 +        hAlignment='centre', vAlignment='top',
    1.38 +        font=fontArial,
    1.39 +        text='Astrokaat Scoring',
    1.40 +        color={0xe0, 0xe0, 0xff}
    1.41 +    })
    1.42 +
    1.43 +    -- Initialize heading buttons
    1.44 +    local butBack = director:createSprite(fontSegoe.height, dsh-fontArial.height*1.5/4, 'images/butback1.png')
    1.45 +    butBack.yAnchor = 1
    1.46 +    butBack.xScale = .8
    1.47 +    butBack.yScale = .8
    1.48 +    local butInfo = director:createSprite(dmw+labTitle.wText/2+fontSegoe.height/2, dsh-fontArial.height*1.5/4, 'images/butinfo.png')
    1.49 +    butInfo.yAnchor = 1
    1.50 +    butInfo.xScale = .8
    1.51 +    butInfo.yScale = .8
    1.52 +
    1.53 +    -- Initialize body text labels
    1.54 +    local rectalph = director:createRectangle(fontSegoe.height, fontSegoe.height, dsw - fontSegoe.height * 2, dsh - fontArial.height * 2.25)
    1.55 +    rectalph.color = color.black
    1.56 +    rectalph.color.a = 64
    1.57 +    --local labFood = director:createLabel({
    1.58 +    --    x=fontSegoe.height*1.5, y=-fontSegoe.height * 2.75,
    1.59 +    --    w=dsw-fontSegoe.height*3, h=0,
    1.60 +    --    hAlignment='left', vAlignment='top',
    1.61 +    --    font=fontSegoe,
    1.62 +    --    text='Food (Positive Points)'
    1.63 +    --})
    1.64 +    local labExplic = director:createLabel({
    1.65 +        x=fontSegoe.height*1.5, y=-fontSegoe.height * 2.75,
    1.66 +        vAlignment='top', font=fontSegoe,
    1.67 +        text='Food nourishes, but obstacles harm the Astrokaat'
    1.68 +    })
    1.69 +    local spriteCatthumb = director:createSprite(fontSegoe.height*2, dsh-fontSegoe.height*6.75, 'textures/cattin_thumb.png')
    1.70 +    local labCattin = director:createLabel({
    1.71 +        x=fontSegoe.height*2, y=-fontSegoe.height*6.75,
    1.72 +        vAlignment='top', font=fontSegoe, text='+2 points'
    1.73 +    })
    1.74 +    local spriteCheesethumb = director:createSprite(fontSegoe.height*8.5, dsh-fontSegoe.height*6.75, 'textures/cheese_thumb.png')
    1.75 +    local labCheese = director:createLabel({
    1.76 +        x=fontSegoe.height*8.5, y=-fontSegoe.height*6.75,
    1.77 +        vAlignment='top', font=fontSegoe, text='+2 points'
    1.78 +    })
    1.79 +    local spriteFischthumb = director:createSprite(dsw-fontSegoe.height*5.5, dsh-fontSegoe.height*6.75, 'textures/fischko_thumb.png')
    1.80 +    local labFischkopf = director:createLabel({
    1.81 +        x=dsw-fontSegoe.height*5.5, y=-fontSegoe.height*6.75,
    1.82 +        vAlignment='top', font=fontSegoe, text='+2 points'
    1.83 +    })
    1.84 +--    local labObst = director:createLabel({
    1.85 +--        x=fontSegoe.height*1.5, y=-fontSegoe.height * 7,
    1.86 +--        w=dsw-fontSegoe.height*3, h=0,
    1.87 +--        hAlignment='left', vAlignment='top',
    1.88 +--        font=fontSegoe,
    1.89 +--        text='Obstacles (Negative Points)'
    1.90 +--    })
    1.91 +    local spriteCometblau = director:createSprite(fontSegoe.height*2.5, dsh-fontSegoe.height*10, 'textures/comet1_thumb.png')
    1.92 +    local labCattin = director:createLabel({
    1.93 +        x=fontSegoe.height*2, y=-fontSegoe.height*10,
    1.94 +        vAlignment='top', font=fontSegoe, text='-1 points'
    1.95 +    })
    1.96 +    local spriteCometrot = director:createSprite(fontSegoe.height*7, dsh-fontSegoe.height*10, 'textures/comet2_thumb.png')
    1.97 +    local labCheese = director:createLabel({
    1.98 +        x=fontSegoe.height*6.5, y=-fontSegoe.height*10,
    1.99 +        vAlignment='top', font=fontSegoe, text='-1 points'
   1.100 +    })
   1.101 +    local spriteAster1 = director:createSprite(dsw-fontSegoe.height*9, dsh-fontSegoe.height*10, 'textures/asteroid1.png')
   1.102 +    spriteAster1.xScale = .1875
   1.103 +    spriteAster1.yScale = .1875
   1.104 +    local labFischkopf = director:createLabel({
   1.105 +        x=dsw-fontSegoe.height*10, y=-fontSegoe.height*10,
   1.106 +        vAlignment='top', font=fontSegoe, text='-2 points'
   1.107 +    })
   1.108 +    local spriteAster2 = director:createSprite(dsw-fontSegoe.height*4.5, dsh-fontSegoe.height*10, 'textures/asteroid2.png')
   1.109 +    spriteAster2.xScale = .1875
   1.110 +    spriteAster2.yScale = .1875
   1.111 +    local labFischkopf = director:createLabel({
   1.112 +        x=dsw-fontSegoe.height*5.5, y=-fontSegoe.height*10,
   1.113 +        vAlignment='top', font=fontSegoe, text='-2 points'
   1.114 +    })
   1.115 +
   1.116 +    -- Good transitions: slideInL/R, shrinkGrow, crossFade, fadeTR/BL, pageTurn, progressVertical
   1.117 +    local transoptl = {transitionType = 'slideInL', transitionTime = 0.5}
   1.118 +    local transoptr = {transitionType = 'slideInR', transitionTime = 0.5}
   1.119 +    local transoptt = {transitionType = 'slideInT', transitionTime = 0.5}
   1.120 +    local transoptb = {transitionType = 'slideInB', transitionTime = 0.5}
   1.121 +
   1.122 +    -- Implement event handlers
   1.123 +    function butInfo:touch(event)
   1.124 +        if event.phase == 'began' then
   1.125 +            table.insert(nodeLastscene, director:getCurrentScene())
   1.126 +            table.insert(nodeLasttrans, transoptb)
   1.127 +            director:moveToScene(sceneAbout, transoptt)
   1.128 +        end
   1.129 +        return true
   1.130 +    end
   1.131 +    butInfo:addEventListener('touch', butInfo)
   1.132 +
   1.133 +    function butBack:touch(event)
   1.134 +        if event.phase == 'began' then
   1.135 +            director:moveToScene(table.remove(nodeLastscene), table.remove(nodeLasttrans))
   1.136 +        end
   1.137 +        return true
   1.138 +    end
   1.139 +    butBack:addEventListener('touch', butBack)
   1.140 +end
   1.141 +
   1.142 +function sceneloc:tearDown(event)
   1.143 +    dbg.print('sceneloc:tearDown')
   1.144 +    --self.releaseResources()
   1.145 +    --self.<obj-here> = self.<obj-here>:removeFromParent()
   1.146 +    --self.obj0:removeFromParent()
   1.147 +    --self.obj1:removeFromParent()
   1.148 +    --self.obj0 = nil
   1.149 +    --self.obj1 = nil
   1.150 +end
   1.151 +
   1.152 +function sceneloc:enterPreTransition(event)
   1.153 +    dbg.print('sceneloc:enterPreTransition')
   1.154 +end
   1.155 +
   1.156 +function sceneloc:enterPostTransition(event)
   1.157 +    dbg.print('sceneloc:enterPostTransition')
   1.158 +end
   1.159 +
   1.160 +function sceneloc:exitPreTransition(event)
   1.161 +    dbg.print('sceneloc:exitPreTransition')
   1.162 +end
   1.163 +
   1.164 +function sceneloc:exitPostTransition(event)
   1.165 +    dbg.print('sceneloc:exitPostTransition')
   1.166 +end
   1.167 +
   1.168 +sceneloc:addEventListener({'setUp', 'tearDown', 'enterPreTransition',
   1.169 +    'enterPostTransition', 'exitPreTransition', 'exitPostTransition'}, sceneloc)
   1.170 +
   1.171 +return sceneloc
   1.172 +

mercurial