Writing Word Game

Hi everyone thanks for the great forums that I can read and ask to get very knowledgeable feedback.
My friends ask me to create a game for helping kids to write words, before I start to create it, I’m trying to think the concept and all the logic part.
This is the example of the writing game: http://www.gudli.com/preschool/games/alphabet-writing.html

I will change the black dot with number so the kids also can read it.
The problem that I want to know is when I drag the line how can I detect each number is the right point so when I write the right sequence of number it will form the word.
If the kids start without looking through the sequence numbers it will result as wrong and the line will disappear so it will began from the beginning again.
[import]uid: 74725 topic_id: 13586 reply_id: 313586[/import]

something to get you starting. :slight_smile:
* see the terminal window also
[lua]-- Slash line properties (line that shows up when you move finger across the screen)
local maxPoints = 5
local lineThickness = 25
local lineFadeTime = 250
local endPoints = {}

local prevtag = 0
local function drawpath(event)
if event.target.tag == prevtag or event.target.tag == prevtag + 1 then
–correct path
else
print(“wrong Path”)
end
prevtag = event.target.tag
end

local txt = {}
txt[1] = display.newText(“1”,200,400,nil,30)
txt[1]:addEventListener(“touch”,drawpath)
txt[1].tag = 1

txt[2] = display.newText(“2”,240,300,nil,30)
txt[2]:addEventListener(“touch”,drawpath)
txt[2].tag = 2

txt[3] = display.newText(“3”,290,200,nil,30)
txt[3]:addEventListener(“touch”,drawpath)
txt[3].tag = 3

txt[4] = display.newText(“4”,360,300,nil,30)
txt[4]:addEventListener(“touch”,drawpath)
txt[4].tag = 4

txt[5] = display.newText(“5”,400,400,nil,30)
txt[5]:addEventListener(“touch”,drawpath)
txt[5].tag = 5

path = 0

function main()
Runtime:addEventListener(“touch”, drawSlashLine)
end

function drawSlashLine(event)
– Insert a new point into the front of the array
table.insert(endPoints, 1, {x = event.x, y = event.y, line= nil})

– Remove any excessed points
if(#endPoints > maxPoints) then
table.remove(endPoints)
end

for i,v in ipairs(endPoints) do
local line = display.newLine(v.x, v.y, event.x, event.y)
line.width = lineThickness
end

if(event.phase == “ended”) then
while(#endPoints > 0) do
table.remove(endPoints)
end
end
end
main()[/lua] [import]uid: 71210 topic_id: 13586 reply_id: 49862[/import]

Thanks renvis it’s really help me, I will try to make my writing game from ur code.
Are you working in the same company(technowand) with renjith?? [import]uid: 74725 topic_id: 13586 reply_id: 49866[/import]

hey Denni, was that you… I din’t notice your name…This is me itself I just changed my display name. :slight_smile: [import]uid: 71210 topic_id: 13586 reply_id: 49867[/import]

hahah yeah that’s me thanks man it’s really helpful [import]uid: 74725 topic_id: 13586 reply_id: 49868[/import]

hi fufuwawa see this,

[lua] local points={}

points[1] = display.newCircle(0,0,10)
points[1].x = 512 - 120
points[1].y = 300

points[2] = display.newCircle(0,0,10)
points[2].x = 512 - 60
points[2].y = 400

points[3] = display.newCircle(0,0,10)
points[3].x = 512
points[3].y = 500

points[4] = display.newCircle(0,0,10)
points[4].x = 512 + 60
points[4].y = 400

points[5] = display.newCircle(0,0,10)
points[5].x = 512 + 120
points[5].y = 300

local myLines = {}
local perfectLines = {}

local function chkRightOrWrong(e)
if e.target.myName == 1 and e.target.isChked == false then
e.target.isChked = true
print(“ok”)
elseif e.target.isChked == false and e.target.myName ~= 1 then
local i = e.target.myName
if points[i - 1].isChked == true then
print(“ok”)
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
perfectLines[#perfectLines + 1] = display.newLine(points[i - 1].x,points[i - 1].y,points[i].x,points[i].y)

e.target.isChked = true
else
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
print(“wrong”)
end

end
end

for i=1,#points do
points[i].isChked = false
points[i].myName = i
points[i]:addEventListener(“touch”,chkRightOrWrong)
end

local prevX,prevY
local function drawLine(e)
if prevX then
myLines[#myLines + 1] = display.newLine(prevX,prevY,e.x,e.y)
myLines[#myLines].width = 3
end
prevX = e.x
prevY = e.y
if “ended” == e.phase then
prevX = nil
prevY = nil
end
end
Runtime:addEventListener(“touch”,drawLine)[/lua] [import]uid: 12482 topic_id: 13586 reply_id: 51059[/import]

@hgvyas123 perfect… this was what we were looking for… :slight_smile: [import]uid: 71210 topic_id: 13586 reply_id: 51061[/import]

glad i helped

:slight_smile: [import]uid: 12482 topic_id: 13586 reply_id: 51063[/import]

Thanks a lot hgvyas123 for your code, now i can continuing my game again [import]uid: 74725 topic_id: 13586 reply_id: 51069[/import]

hi here’s the what i am talking about math.abs

[lua]local points={}

points[1] = display.newCircle(0,0,10)
points[1].x = 512 - 120
points[1].y = 300

points[2] = display.newCircle(0,0,10)
points[2].x = 512 - 60
points[2].y = 400

points[3] = display.newCircle(0,0,10)
points[3].x = 512
points[3].y = 500

points[4] = display.newCircle(0,0,10)
points[4].x = 512 + 60
points[4].y = 400

points[5] = display.newCircle(0,0,10)
points[5].x = 512 + 120
points[5].y = 300

local myLines = {}
local perfectLines = {}

local lastPoint

local function chkRightOrWrong(e)

if e.target.myName == 1 and e.target.isChked == false then
e.target.isChked = true
print(“ok”)
Runtime:addEventListener(“touch”,drawLine)
lastPoint = e.target.myName
elseif e.target.isChked == false and e.target.myName ~= 1 then
local i = e.target.myName
if points[i - 1].isChked == true then
print(“ok”)
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
perfectLines[#perfectLines + 1] = display.newLine(points[i - 1].x,points[i - 1].y,points[i].x,points[i].y)
lastPoint = e.target.myName
e.target.isChked = true
else
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
print(“wrong”)
end

end
end

for i=1,#points do
points[i].isChked = false
points[i].myName = i
points[i]:addEventListener(“touch”,chkRightOrWrong)
end

function drawLine(e)
if lastPoint ~= nil then
print(“asd”)
print(math.abs(e.x - points[lastPoint + 1].x))
if math.abs(e.x - points[lastPoint + 1].x) > 150 or math.abs(e.y - points[lastPoint + 1].y) > 150 then
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
end
end
if prevX then
myLines[#myLines + 1] = display.newLine(prevX,prevY,e.x,e.y)
myLines[#myLines].width = 3
end
prevX = e.x
prevY = e.y
if “ended” == e.phase then
prevX = nil
prevY = nil
end
end
[/lua]

for other i am looking

:slight_smile: [import]uid: 12482 topic_id: 13586 reply_id: 51700[/import]

[lua] local points={}

points[1] = display.newCircle(0,0,10)
points[1].x = 312 - 120
points[1].y = 300

points[2] = display.newCircle(0,0,10)
points[2].x = 312 - 60
points[2].y = 400

points[3] = display.newCircle(0,0,10)
points[3].x = 312
points[3].y = 500

points[4] = display.newCircle(0,0,10)
points[4].x = 312 + 60
points[4].y = 400

points[5] = display.newCircle(0,0,10)
points[5].x = 312 + 120
points[5].y = 300

points[6] = display.newCircle(0,0,10)
points[6].x = 330 + 50
points[6].y = 340

points[7] = display.newCircle(0,0,10)
points[7].x = 312
points[7].y = 340

points[8] = display.newCircle(0,0,10)
points[8].x = 330 - 90
points[8].y = 340

local myLines = {}
local perfectLines = {}

local lastPoint
local currentPoint,nextPoint
local temp
local function chkRightOrWrong(e)
if e.target.myName ~= 1 then
currentPoint = e.target.myName
nextPoint = e.target.myName + 1
end
if e.target.isChked == true then
Runtime:addEventListener(“touch”, drawLine)
end

if e.target.myName == 1 and e.target.isChked == false then
e.target.isChked = true
Runtime:addEventListener(“touch”, drawLine)
lastPoint = e.target.myName
currentPoint = e.target.myName
nextPoint = e.target.myName + 1
elseif e.target.myName > 7 and e.target.isChked == true then
e.target.isChked = false
Runtime:removeEventListener(“touch”, drawLine)

–[[elseif e.target.myName == 6 and e.target.isChked == true then
e.target.isChked = true
Runtime:addEventListener(“touch”, drawLine)
lastPoint = e.target.myName
currentPoint = e.target.myName
nextPoint = e.target.myName + 1
]]–

elseif e.target.isChked == false and e.target.myName ~= 1 then
local i = e.target.myName
print(i …“hahsd”)
if i == 6 then
points[6].isChked = true
end
if i ~= 6 then
if points[i - 1].isChked == true then
temp = #myLines
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
if temp > 5 then
print(temp …“basdhjg23”)
perfectLines[#perfectLines + 1] = display.newLine(points[i - 1].x,points[i - 1].y,points[i].x,points[i].y)
perfectLines[#perfectLines].width = 10
perfectLines[#perfectLines]:setColor(255, 100, 50)
lastPoint = e.target.myName
e.target.isChked = true
temp = 0
print(“asdasd”)
end
else
temp = 0
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
print(#myLines …“asd”)
end
end
end
end
end

for i=1,#points do
points[i].isChked = false
points[i].myName = i
points[i]:addEventListener(“touch”,chkRightOrWrong)
end

function drawLine(e)
if lastPoint ~= nil then
if lastPoint + 1 <= #points then
if math.abs(e.x - points[lastPoint + 1].x) > 150 or math.abs(e.y - points[lastPoint + 1].y) > 150 then
temp = 0
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
end
end
end
if prevX then
myLines[#myLines + 1] = display.newLine(prevX,prevY,e.x,e.y)
myLines[#myLines].width = 10
myLines[#myLines]:setColor(255, 100, 50)
end
prevX = e.x
prevY = e.y
if “ended” == e.phase then
prevX = nil
prevY = nil
currentPoint = nil
nextPoint = nil
temp = 0
for i=1,#myLines do
myLines[i]:removeSelf()
myLines[i] = nil
end
Runtime:removeEventListener(“touch”,drawLine)
end
end[/lua] [import]uid: 12482 topic_id: 13586 reply_id: 51710[/import]