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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
| local function main()
----------------------------------------------------------------------------------------
-- Constants-
----------------------------------------------------------------------------------------
local FALSE = 0
local TRUE = 1
local moved = FALSE;
local cLi -- CURRENT LETTER IMAGE
local accuThresh = 15
local matches
local distanceBetween1
local function distanceBetween( obj1, obj2 )
local xfactor = obj2.x - obj1.x
local yfactor = obj2.y - obj1.y
distanceBetween1 = math.sqrt((xfactor*xfactor) + (yfactor*yfactor))
--print("Distance =" .. distanceBetween1)
return distanceBetween1
end
----------------------------------------------------------------------------------------
-- Display Group
----------------------------------------------------------------------------------------
local background = display.newGroup()
local drawDotsGroup = display.newGroup() ; drawDotsGroup.alpha = .2 --DISPLAY ALPHA
local startEndPoints = display.newGroup() ; startEndPoints.alpha = .2
----------------------------------------------------------------------------------------
-- Display Objects
----------------------------------------------------------------------------------------
local backdrop = display.newImageRect("assets/green_chalk_bkg.png", 1024,768);
backdrop.x = _W/2 ; backdrop.y = _H/2
background:insert(backdrop)
local upperCimage = display.newImageRect("test_c.png", 256,256)
upperCimage.x = _W/2 ; upperCimage.y = _H/2 ; upperCimage.alpha = .2
cLi = upperCimage
----------------------------------------------------------------------------------------
-- LETTER TABLES
----------------------------------------------------------------------------------------
local cTable = {
{ x = cLi.x+70, y = cLi.y-90, match = 0 },
{ x = cLi.x+44, y = cLi.y-105, match = 0 },
{ x = cLi.x, y = cLi.y-110, match = 0 },
{ x = cLi.x-55, y = cLi.y-90, match = 0 },
{ x = cLi.x-82, y = cLi.y-25, match = 0 },
{ x = cLi.x-78, y = cLi.y+40, match = 0 },
{ x = cLi.x-55, y = cLi.y+85, match = 0 },
{ x = cLi.x-15, y = cLi.y+108, match = 0 },
{ x = cLi.x+35, y = cLi.y+94, match = 0 },
{ x = cLi.x+60, y = cLi.y+70, match = 0 },
}
for i,v in ipairs(cTable) do print(i,v.y) end
local function drawCinvisibles()
for i=1, #cTable do
cZoneStart = display.newCircle(cTable[i].x, cTable[i].y ,10) ;
end
end
--drawCinvisibles() --< Uncomment to draw match points
----------------------------------------------------------------------------------------
-- Fade In Effect for current letter
------------------------------------------------------------------------------------------
local function isCorrect(obj)
transition.to(obj, {time = 1000, alpha = 1})
end
----------------------------------------------------------------------------------------
-- Try Again
------------------------------------------------------------------------------------------
local function tryAgain()
letterFail = display.newText("Try Again", _W/2, _H/2, "Helvetica", 76)
end
----------------------------------------------------------------------------------------
-- Draw Points by User
------------------------------------------------------------------------------------------
local linePoints = {} -- TABLE TO HOLD DRAWN LINE DOTS
local function createPoints(event)
local phase = event.phase
if "began" == phase then
matches = 0
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
elseif "moved" == phase then
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
moved = TRUE;
for i = 1, #linePoints, 1 do --Iterate through drawn points
vpt = display.newRect(linePoints[i].x,linePoints[i].y,6,6)
for h = 1, #cTable, 1 do
if(linePoints[i] and cTable[h] ~= nil) then --Find Distance
distanceBetween(linePoints[i], cTable[h])
end
if (distanceBetween1 < accuThresh) then
cTable[h].match = 1 --Matched per Hard-coded Point
matches = matches + 1 --Total matches
end
--[[if(distanceBetween1 < 30) then
print(distanceBetween1)
end]]--
end
end
elseif "ended" == phase or "cancelled" == phase then
moved = FALSE;
--print("total matches " .. matches)
for i,v in ipairs(cTable) do print(i,v.match ) end --Show which points hardcoded were matched
--[[local hardCodeMatches = 0
for i = 1, #cTable, 1 do
if cTable[i].match == 1 then
hardCodeMatches = hardCodeMatches + 1
end
end
print("cTable matches " .. hardCodeMatches)
if hardCodeMatches == 10 then
isCorrect(cLi)
elseif hardCodeMatches < 10 then
tryAgain()
end]]--
end
return true
end
Runtime:addEventListener("touch",createPoints);
end
----------------------------------------------------------------------------------------
main(); |