1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
| module(..., package.seeall)
function new()
local localGroup = display.newGroup()
--------------------------------------------------------------------------------------------------------------------------------
require "sprite"
require "toggle"
local ui = require("ui")
local gameUI = require("gameUI")
local physics = require("physics")
physics.start()
physics.setGravity(0, 9.8)
physics.pause()
local dragBody = gameUI.dragBody -- for use in touch event listener below
system.activate("multitouch")
display.setStatusBar(display.HiddenStatusBar)
physics.setDrawMode("hybrid") -- overlays collision outlines on normal Corona objects
----------------------------------------------------------------------
-- Functions --
----------------------------------------------------------------------
local function placeholder( event ) --creates the function for displaying placeholders
if physics.pause() == true then
transparentball.isVisible = false -- hide objects
placeholderball.isVisible = true -- insert variable?
end
end
local function play( event )
if physics.pause == false then
transparentball.x = placeholderball.x
transparentball.y = placeholderball.y
transparentball.isVisible = true
placeholderball.isVisible = false
end
end
function physicspause (event)
physics.pause()
end
function physicsstart (event)
physics.start()
end
function localDrag( event )
gameUI.dragBody( event, {maxForce=20000, frequency=10, dampingRatio=0.2, center=true} )
end
----------------------------------------------------------------------
-- PLACEHOLDERS --
----------------------------------------------------------------------
local placeholderball = display.newImage("graphics/transparentball.png")
placeholderball.x = 160
placeholderball.y = 200
placeholderball:addEventListener( "touch", dragBody )
----------------------------------------------------------------------------------------------------------------
--DRAW IMAGES
----------------------------------------------------------------------------------------------------------------
local background1 = display.newImage( "graphics/background.png" )
background1.x = 160
background1.y = 240
background1.xScale = 2.0
background1.yScale = 2.0
local btn1 = display.newImage("graphics/button.png")
btn1.x = 150
btn1.y = 10
btn1.xScale = 0.300
btn1.yScale = 0.300
btn1:addEventListener("touch", placeholder)
local btn2 = display.newImage("graphics/button.png")
btn2.x = 300
btn2.y = 10
btn2.xScale = 0.300
btn2.yScale = 0.300
btn2:addEventListener("touch", physicsstart)
local instruction = display.newText( "drag any object", 80, 60, native.systemFontBold, 20 )
instruction:setTextColor( 255, 255, 255, 500 )
local ground = display.newImage("graphics/floor.png") -- physical ground object
ground.x = 165
ground.y = display.contentHeight - ground.contentHeight/2
physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } )
local transparentball = display.newImage("graphics/transparentball.png")
transparentball.x = placeholderball.x
transparentball.y = placeholderball.y
transparentball.xScale = 1
transparentball.yScale = 1
physics.addBody(transparentball, {density=0.9, friction=0.3, bounce=0.2})
transparentball:addEventListener( "touch", dragBody )
local yellow = display.newImage("graphics/yellowball.png")
yellow.x = 300
yellow.y = 200
physics.addBody(yellow, {density=0.9, friction=0.3, bounce=0.3})
local orange = display.newImage("graphics/orangeball.png")
orange.x = 400
orange.y = 200
orange.xScale = 0.1
orange.yScale = 0.1
physics.addBody(orange, {density=0.9, friction=0.3, bounce=0.3})
if transparentball.currentFrame == 3 then
-- do something (win condition)
end
transparentball.myName = "transparentball"
red.myName = "red"
localGroup:insert(background1)
localGroup:insert(instruction)
localGroup:insert(ground)
localGroup:insert(transparentball)
localGroup:insert(placeholderball)
localGroup:insert(orange)
localGroup:insert(yellow)
localGroup:insert(btn1)
localGroup:insert(btn2)
------------------------------------------------------------------------------
return localGroup
end |