SHOW:
|
|
- or go back to the newest paste.
1 | --------------------------------------------------------------------------------- | |
2 | -- | |
3 | -- testscreen1.lua | |
4 | -- | |
5 | --------------------------------------------------------------------------------- | |
6 | ||
7 | local storyboard = require( "storyboard" ) | |
8 | local scene = storyboard.newScene() | |
9 | ||
10 | --------------------------------------------------------------------------------- | |
11 | -- BEGINNING OF YOUR IMPLEMENTATION | |
12 | --------------------------------------------------------------------------------- | |
13 | ||
14 | require("physics") | |
15 | physics.start() | |
16 | physics.pause() | |
17 | --physics.setDrawMode("hybrid") | |
18 | ||
19 | gameOn = false | |
20 | ||
21 | ||
22 | local module = require "module" | |
23 | ||
24 | ||
25 | --local lines = module.lines | |
26 | --local line_number = module.line_number | |
27 | --local line_width = module.line_width | |
28 | --local prev_x, prev_y = module.prev_x, module.prev_y | |
29 | --local maxLines = 5 | |
30 | --local maxDist = 400 | |
31 | --local dist = module.dist | |
32 | --local mathSqrt = module.mathSqrt | |
33 | ||
34 | local dist = 0 | |
35 | local maxDist = 400 | |
36 | ||
37 | ||
38 | ||
39 | ||
40 | local drawLine = module.drawLine | |
41 | ||
42 | local gameWin = module.gameWin | |
43 | ||
44 | local gameState = module.gameState | |
45 | ||
46 | ||
47 | ||
48 | ||
49 | -- Called when the scene's view does not exist: | |
50 | function scene:createScene( event ) | |
51 | local screenGroup = self.view | |
52 | ||
53 | ||
54 | ||
55 | local ball = module.spawnBall(30, 50) | |
56 | ||
57 | local goal = module.createGoal(100, 300) | |
58 | ||
59 | ||
60 | ||
61 | local wall = module.createWall( 0, 150, 450, 14, 1) | |
62 | ||
63 | local wall2 = module.createWall( 200, 300, 400, 10) | |
64 | ||
65 | local arrow = module.createArrow() | |
66 | ||
67 | screenGroup:insert( arrow ) | |
68 | screenGroup:insert( ball ) | |
69 | screenGroup:insert( goal ) | |
70 | screenGroup:insert( wall ) | |
71 | screenGroup:insert( wall2 ) | |
72 | ||
73 | local changeGravity = module.changeGravity | |
74 | ||
75 | ||
76 | screenGroup[3]:addEventListener("tap", gameState) | |
77 | arrow:addEventListener("tap", changeGravity) | |
78 | ||
79 | ||
80 | ||
81 | ||
82 | end | |
83 | ||
84 | ||
85 | -- Called immediately after scene has moved onscreen: | |
86 | function scene:enterScene( event ) | |
87 | ||
88 | local drawLineWrapper = function(e) | |
89 | --if gameOn == false then | |
90 | if e.phase == "began" then | |
91 | prev_x = e.x | |
92 | prev_y = e.y | |
93 | elseif e.phase == "moved" then | |
94 | if dist < maxDist then | |
95 | ||
96 | dist_x = e.x - prev_x | |
97 | dist_y = e.y - prev_y | |
98 | ||
99 | dist = dist + mathSqrt(dist_x*dist_x + dist_y*dist_y) | |
100 | print(dist) | |
101 | ||
102 | drawLine(prev_x, prev_y, dist_x, dist_y) | |
103 | ||
104 | prev_x = e.x | |
105 | prev_y = e.y | |
106 | ||
107 | ||
108 | end | |
109 | elseif e.phase == "ended" then | |
110 | end | |
111 | --end | |
112 | ||
113 | end | |
114 | - | |
114 | + | |
115 | scene.view.lineDrawer = drawLineWrapper | |
116 | Runtime:addEventListener("touch", drawLineWrapper) | |
117 | ||
118 | Runtime:addEventListener("collision", gameWin) | |
119 | ||
120 | ||
121 | -- remove previous scene's view | |
122 | --storyboard.purgeScene( "storyboard.lastScene" ) | |
123 | --storyboard.lastScene = | |
124 | ||
125 | ||
126 | ||
127 | end | |
128 | ||
129 | ||
130 | -- Called when scene is about to move offscreen: | |
131 | function scene:exitScene( event ) | |
132 | ||
133 | lines = {} | |
134 | ||
135 | ||
136 | ||
137 | -- remove touch listener for image | |
138 | -- image:removeEventListener( "touch", image ) | |
139 | ||
140 | ||
141 | end | |
142 | ||
143 | ||
144 | -- Called prior to the removal of scene's "view" (display group) | |
145 | function scene:destroyScene( event ) | |
146 | ||
147 | print( "((destroying scene 1's view))" ) | |
148 | end | |
149 | ||
150 | --------------------------------------------------------------------------------- | |
151 | -- END OF YOUR IMPLEMENTATION | |
152 | --------------------------------------------------------------------------------- | |
153 | ||
154 | -- "createScene" event is dispatched if scene's view does not exist | |
155 | scene:addEventListener( "createScene", scene ) | |
156 | ||
157 | -- "enterScene" event is dispatched whenever scene transition has finished | |
158 | scene:addEventListener( "enterScene", scene ) | |
159 | ||
160 | -- "exitScene" event is dispatched before next scene's transition begins | |
161 | scene:addEventListener( "exitScene", scene ) | |
162 | ||
163 | -- "destroyScene" event is dispatched before view is unloaded, which can be | |
164 | -- automatically unloaded in low memory situations, or explicitly via a call to | |
165 | -- storyboard.purgeScene() or storyboard.removeScene(). | |
166 | scene:addEventListener( "destroyScene", scene ) | |
167 | ||
168 | --------------------------------------------------------------------------------- | |
169 | ||
170 | return scene |