Thu, 22 Aug 2013 19:50:12 +0200
Flush progress with initial commit, improve application.
michael@0 | 1 | -- Top of scene |
michael@0 | 2 | --print('This is a new scene!') |
michael@0 | 3 | |
michael@0 | 4 | -- Initiate scene management |
michael@0 | 5 | local sceneloc = director:createScene() |
michael@0 | 6 | sceneloc.name = 'Scene: Scoring' |
michael@0 | 7 | |
michael@0 | 8 | -- Constants calculated |
michael@0 | 9 | local dsw = director.displayWidth |
michael@0 | 10 | local dsh = director.displayHeight |
michael@0 | 11 | local dmw = director.displayCenterX |
michael@0 | 12 | local dmh = director.displayCenterY |
michael@0 | 13 | |
michael@0 | 14 | -- Instantiate common fonts |
michael@0 | 15 | local fontSegoe = director:createFont('fonts/SegoeUI-64pt_bold.fnt') |
michael@0 | 16 | local fontArial = director:createFont('fonts/Arial-96pt_bold.fnt') |
michael@0 | 17 | |
michael@0 | 18 | function sceneloc:setUp(event) |
michael@0 | 19 | dbg.print('sceneloc:setUp') |
michael@0 | 20 | |
michael@0 | 21 | ---- Cancel playing streams |
michael@0 | 22 | --audio:stopStream() |
michael@0 | 23 | |
michael@0 | 24 | -- Print background |
michael@0 | 25 | local rectBack = director:createRectangle({ |
michael@0 | 26 | x=0, y=0, |
michael@0 | 27 | w=dsw, h=dsh, |
michael@0 | 28 | strokeWidth=0, |
michael@0 | 29 | color={10, 74, 134}, alpha=1}) |
michael@0 | 30 | |
michael@0 | 31 | -- Initialize heading labels |
michael@0 | 32 | local labTitle = director:createLabel({ |
michael@0 | 33 | x=0, y=-fontArial.height*1.5/6, |
michael@0 | 34 | hAlignment='centre', vAlignment='top', |
michael@0 | 35 | font=fontArial, |
michael@0 | 36 | text='Astrokaat Scoring', |
michael@0 | 37 | color={0xe0, 0xe0, 0xff} |
michael@0 | 38 | }) |
michael@0 | 39 | |
michael@0 | 40 | -- Initialize heading buttons |
michael@0 | 41 | local butBack = director:createSprite(fontSegoe.height, dsh-fontArial.height*1.5/4, 'images/butback1.png') |
michael@0 | 42 | butBack.yAnchor = 1 |
michael@0 | 43 | butBack.xScale = .8 |
michael@0 | 44 | butBack.yScale = .8 |
michael@0 | 45 | local butInfo = director:createSprite(dmw+labTitle.wText/2+fontSegoe.height/2, dsh-fontArial.height*1.5/4, 'images/butinfo.png') |
michael@0 | 46 | butInfo.yAnchor = 1 |
michael@0 | 47 | butInfo.xScale = .8 |
michael@0 | 48 | butInfo.yScale = .8 |
michael@0 | 49 | |
michael@0 | 50 | -- Initialize body text labels |
michael@0 | 51 | local rectalph = director:createRectangle(fontSegoe.height, fontSegoe.height, dsw - fontSegoe.height * 2, dsh - fontArial.height * 2.25) |
michael@0 | 52 | rectalph.color = color.black |
michael@0 | 53 | rectalph.color.a = 64 |
michael@0 | 54 | --local labFood = director:createLabel({ |
michael@0 | 55 | -- x=fontSegoe.height*1.5, y=-fontSegoe.height * 2.75, |
michael@0 | 56 | -- w=dsw-fontSegoe.height*3, h=0, |
michael@0 | 57 | -- hAlignment='left', vAlignment='top', |
michael@0 | 58 | -- font=fontSegoe, |
michael@0 | 59 | -- text='Food (Positive Points)' |
michael@0 | 60 | --}) |
michael@0 | 61 | local labExplic = director:createLabel({ |
michael@0 | 62 | x=fontSegoe.height*1.5, y=-fontSegoe.height * 2.75, |
michael@0 | 63 | vAlignment='top', font=fontSegoe, |
michael@0 | 64 | text='Food nourishes, but obstacles harm the Astrokaat' |
michael@0 | 65 | }) |
michael@0 | 66 | local spriteCatthumb = director:createSprite(fontSegoe.height*2, dsh-fontSegoe.height*6.75, 'textures/cattin_thumb.png') |
michael@0 | 67 | local labCattin = director:createLabel({ |
michael@0 | 68 | x=fontSegoe.height*2, y=-fontSegoe.height*6.75, |
michael@0 | 69 | vAlignment='top', font=fontSegoe, text='+2 points' |
michael@0 | 70 | }) |
michael@0 | 71 | local spriteCheesethumb = director:createSprite(fontSegoe.height*8.5, dsh-fontSegoe.height*6.75, 'textures/cheese_thumb.png') |
michael@0 | 72 | local labCheese = director:createLabel({ |
michael@0 | 73 | x=fontSegoe.height*8.5, y=-fontSegoe.height*6.75, |
michael@0 | 74 | vAlignment='top', font=fontSegoe, text='+2 points' |
michael@0 | 75 | }) |
michael@0 | 76 | local spriteFischthumb = director:createSprite(dsw-fontSegoe.height*5.5, dsh-fontSegoe.height*6.75, 'textures/fischko_thumb.png') |
michael@0 | 77 | local labFischkopf = director:createLabel({ |
michael@0 | 78 | x=dsw-fontSegoe.height*5.5, y=-fontSegoe.height*6.75, |
michael@0 | 79 | vAlignment='top', font=fontSegoe, text='+2 points' |
michael@0 | 80 | }) |
michael@0 | 81 | -- local labObst = director:createLabel({ |
michael@0 | 82 | -- x=fontSegoe.height*1.5, y=-fontSegoe.height * 7, |
michael@0 | 83 | -- w=dsw-fontSegoe.height*3, h=0, |
michael@0 | 84 | -- hAlignment='left', vAlignment='top', |
michael@0 | 85 | -- font=fontSegoe, |
michael@0 | 86 | -- text='Obstacles (Negative Points)' |
michael@0 | 87 | -- }) |
michael@0 | 88 | local spriteCometblau = director:createSprite(fontSegoe.height*2.5, dsh-fontSegoe.height*10, 'textures/comet1_thumb.png') |
michael@0 | 89 | local labCattin = director:createLabel({ |
michael@0 | 90 | x=fontSegoe.height*2, y=-fontSegoe.height*10, |
michael@0 | 91 | vAlignment='top', font=fontSegoe, text='-1 points' |
michael@0 | 92 | }) |
michael@0 | 93 | local spriteCometrot = director:createSprite(fontSegoe.height*7, dsh-fontSegoe.height*10, 'textures/comet2_thumb.png') |
michael@0 | 94 | local labCheese = director:createLabel({ |
michael@0 | 95 | x=fontSegoe.height*6.5, y=-fontSegoe.height*10, |
michael@0 | 96 | vAlignment='top', font=fontSegoe, text='-1 points' |
michael@0 | 97 | }) |
michael@0 | 98 | local spriteAster1 = director:createSprite(dsw-fontSegoe.height*9, dsh-fontSegoe.height*10, 'textures/asteroid1.png') |
michael@0 | 99 | spriteAster1.xScale = .1875 |
michael@0 | 100 | spriteAster1.yScale = .1875 |
michael@0 | 101 | local labFischkopf = director:createLabel({ |
michael@0 | 102 | x=dsw-fontSegoe.height*10, y=-fontSegoe.height*10, |
michael@0 | 103 | vAlignment='top', font=fontSegoe, text='-2 points' |
michael@0 | 104 | }) |
michael@0 | 105 | local spriteAster2 = director:createSprite(dsw-fontSegoe.height*4.5, dsh-fontSegoe.height*10, 'textures/asteroid2.png') |
michael@0 | 106 | spriteAster2.xScale = .1875 |
michael@0 | 107 | spriteAster2.yScale = .1875 |
michael@0 | 108 | local labFischkopf = director:createLabel({ |
michael@0 | 109 | x=dsw-fontSegoe.height*5.5, y=-fontSegoe.height*10, |
michael@0 | 110 | vAlignment='top', font=fontSegoe, text='-2 points' |
michael@0 | 111 | }) |
michael@0 | 112 | |
michael@0 | 113 | -- Good transitions: slideInL/R, shrinkGrow, crossFade, fadeTR/BL, pageTurn, progressVertical |
michael@0 | 114 | local transoptl = {transitionType = 'slideInL', transitionTime = 0.5} |
michael@0 | 115 | local transoptr = {transitionType = 'slideInR', transitionTime = 0.5} |
michael@0 | 116 | local transoptt = {transitionType = 'slideInT', transitionTime = 0.5} |
michael@0 | 117 | local transoptb = {transitionType = 'slideInB', transitionTime = 0.5} |
michael@0 | 118 | |
michael@0 | 119 | -- Implement event handlers |
michael@0 | 120 | function butInfo:touch(event) |
michael@0 | 121 | if event.phase == 'began' then |
michael@0 | 122 | table.insert(nodeLastscene, director:getCurrentScene()) |
michael@0 | 123 | table.insert(nodeLasttrans, transoptb) |
michael@0 | 124 | director:moveToScene(sceneAbout, transoptt) |
michael@0 | 125 | end |
michael@0 | 126 | return true |
michael@0 | 127 | end |
michael@0 | 128 | butInfo:addEventListener('touch', butInfo) |
michael@0 | 129 | |
michael@0 | 130 | function butBack:touch(event) |
michael@0 | 131 | if event.phase == 'began' then |
michael@0 | 132 | director:moveToScene(table.remove(nodeLastscene), table.remove(nodeLasttrans)) |
michael@0 | 133 | end |
michael@0 | 134 | return true |
michael@0 | 135 | end |
michael@0 | 136 | butBack:addEventListener('touch', butBack) |
michael@0 | 137 | end |
michael@0 | 138 | |
michael@0 | 139 | function sceneloc:tearDown(event) |
michael@0 | 140 | dbg.print('sceneloc:tearDown') |
michael@0 | 141 | --self.releaseResources() |
michael@0 | 142 | --self.<obj-here> = self.<obj-here>:removeFromParent() |
michael@0 | 143 | --self.obj0:removeFromParent() |
michael@0 | 144 | --self.obj1:removeFromParent() |
michael@0 | 145 | --self.obj0 = nil |
michael@0 | 146 | --self.obj1 = nil |
michael@0 | 147 | end |
michael@0 | 148 | |
michael@0 | 149 | function sceneloc:enterPreTransition(event) |
michael@0 | 150 | dbg.print('sceneloc:enterPreTransition') |
michael@0 | 151 | end |
michael@0 | 152 | |
michael@0 | 153 | function sceneloc:enterPostTransition(event) |
michael@0 | 154 | dbg.print('sceneloc:enterPostTransition') |
michael@0 | 155 | end |
michael@0 | 156 | |
michael@0 | 157 | function sceneloc:exitPreTransition(event) |
michael@0 | 158 | dbg.print('sceneloc:exitPreTransition') |
michael@0 | 159 | end |
michael@0 | 160 | |
michael@0 | 161 | function sceneloc:exitPostTransition(event) |
michael@0 | 162 | dbg.print('sceneloc:exitPostTransition') |
michael@0 | 163 | end |
michael@0 | 164 | |
michael@0 | 165 | sceneloc:addEventListener({'setUp', 'tearDown', 'enterPreTransition', |
michael@0 | 166 | 'enterPostTransition', 'exitPreTransition', 'exitPostTransition'}, sceneloc) |
michael@0 | 167 | |
michael@0 | 168 | return sceneloc |
michael@0 | 169 |