Toony Flash game prototype ported to iPhone using Corona SDK
Yesterday I blogged about Toony Flash game and I said it would be interesting to port the game to mobile devices.
Some hours later, Jason Ian Green from PodWork sent me the Corona SDK version of the prototype I made with AS3.
This is what you’ll get:
and this is main.lua file, with the complete script:
|
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 |
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local toonyVector = {} local toRemove = {} local interface = display.newGroup() local toonyTypes = {"square.png", "circle.png", "hexagon.png", "flower.png"} local currentObj local originX local originY local score = 0 local function onTouch(event) if event.phase == "began" then --print("began") currentObj = event.target originX = currentObj.x originY = currentObj.y end if event.phase == "moved" then --print("moved") currentObj.x = event.x currentObj.y = event.y end if event.phase == "ended" or event.phase == "cancelled" then --print("ednded") for n = 1, #toonyVector, 1 do local diffx = currentObj.x - toonyVector[n].x local diffy = currentObj.y - toonyVector[n].y if currentObj.id == toonyVector[n].id then if math.abs(diffx) < 20 and math.abs(diffy) < 20 then toonyVector[n].alpha = 1.0 end end end currentObj.x = originX currentObj.y = originY end end local function go(event) for i = 1, #toonyVector, 1 do toonyVector[i].y = toonyVector[i].y + 1 if toonyVector[i].y > 260 then if toonyVector[i].alpha == 1.0 then score = score + 1 print(score) end toonyVector[i]:removeSelf() table.insert(toRemove,i) end end for j = #toRemove, 1, -1 do table.remove(toonyVector,j) end toRemove={} end local function newToony(event) local rand = math.random(4) local newToon = display.newImage( toonyTypes[rand] ) newToon.x = math.random(400) + 25 newToon.y = 25 newToon.id = rand newToon.alpha = 0.5 table.insert(toonyVector,newToon) end local function main() local tSquare = display.newImage( toonyTypes[1] ) tSquare.x=100 tSquare.y=295 tSquare.id = 1 tSquare:addEventListener( "touch", onTouch ) interface:insert(tSquare) local tCircle = display.newImage( toonyTypes[2] ) tCircle.x=200; tCircle.y=295; tCircle.id = 2 tCircle:addEventListener( "touch", onTouch ) interface:insert(tCircle) local tHexagon = display.newImage( toonyTypes[3] ) tHexagon.x=300; tHexagon.y=295; tHexagon.id = 3 tHexagon:addEventListener( "touch", onTouch ) interface:insert(tHexagon) local tFlower = display.newImage( toonyTypes[4] ) tFlower.x=400; tFlower.y=295; tFlower.id = 4 tFlower:addEventListener( "touch", onTouch ) interface:insert(tFlower) Runtime:addEventListener( "enterFrame", go ) timer.performWithDelay( 2000, newToony, 0 ) end main() |
You can also download the entire project to compile it on your own on Corona SDK.
If anyone wants to continue with the porting, I will be happy to host it on the blog.






(6 votes, average: 3.83 out of 5)







This post has 3 comments
Jason Green
Glad to help out, you have given so many great tutorials, I thought it was time to give something back. To anyone who wants to use this code, beware that I didn’t have time to perfect the drag and drop functionality and I think objects can get left behind if you move to fast. There are probably a whole bunch of great drag and drop corona tutorials and classes out there so shouldn’t be a problem.
Joao
Hey, this is nice!
You’ll write tutorials about Corona?
Thanks.
Toony Flash game prototype ported to iPhone using Corona SDK – Emanuele Feronato « eaflash
[...] on http://www.emanueleferonato.com Share this:TwitterFacebookLike this:LikeBe the first to like this [...]