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