Can i develop a 2d game like doodle jump in corona ?
yes.
you can make whatever you want with corona.
Yes. Corona would be a great tool to make that kind of game! In fact, you might want to do a quick Google:
https://www.google.com/search?q=corona+doodle+jump&oq=corona+doodle+jump
There are a couple of tutorials specifically for building a doodle jump like game.
Rob
Here’s some code to get you started. Set your frames per second to 60 in the config.lua and simulate on iPhone-template:
display.setStatusBar( display.HiddenStatusBar ) -- hide the status bar local mainGroup = display.newGroup() local platformList = {} local coinList = {} local coinCounter = 1 local trampolineList = {} local trampolineCounter = 1 local gravity = .3 local playerVerticalSpeed = 0 local lastPlatformPosition = 960 local coinScore = 0 mainGroup.y = 0 for i = 1, 8 do -- platform creation local newPlatformPosition = lastPlatformPosition - math.random(3)\*100 platformList[i] = display.newRect(mainGroup, math.random(440)+100, newPlatformPosition, 200, 50) lastPlatformPosition = newPlatformPosition end -- for loop platform creation for i = 1,8 do -- coin creation coinList[i] = display.newCircle(mainGroup, -320,0, 20) coinList[i]:setFillColor(1,.75,0) end -- for loop coin creation for i = 1,8 do -- trampoline creation trampolineList[i] = display.newRect(mainGroup, -200,0,100,40) trampolineList[i]:setFillColor(0,.5,1) end local playerSprite = display.newRect(mainGroup,320,480,100,100) -- create scoreText local scoreText = display.newText("0",320,50, native.systemFont, 32) local playerXdirection = 0 local frameLoop = function(event) -- calculate the horizontal motion if playerXdirection == 1 then playerSprite.x = playerSprite.x - 5 elseif playerXdirection == 2 then playerSprite.x = playerSprite.x + 5 end -- add gravity to hero playerVerticalSpeed = playerVerticalSpeed + gravity playerSprite.nextYposition = playerSprite.y + playerVerticalSpeed -- do collision detection of next Y position with all platforms if playerVerticalSpeed \> 4 then for i = 1,8 do -- go over all 6 platforms if (math.abs((playerSprite.nextYposition+50) - (platformList[i].y))\<25) and (math.abs(playerSprite.x - platformList[i].x)\<150) then playerVerticalSpeed = -15 end end -- for loop over all 6 platforms end -- if moving down! -- set the player y position to the hypotethical y position playerSprite.y = playerSprite.nextYposition -- do collision detection with coins for i = 1, #coinList do local xDistanceToPlayer = coinList[i].x - playerSprite.x local yDistanceToPlayer = coinList[i].y - playerSprite.y if math.sqrt(xDistanceToPlayer\*xDistanceToPlayer + yDistanceToPlayer\*yDistanceToPlayer) \< 40 then coinList[i].x = -320 coinScore = coinScore + 100 end -- if coin distance check end -- update "camera position" local cameraYdelta = mainGroup.y + playerSprite.y - 480 if cameraYdelta \< 0 then mainGroup.y = mainGroup.y - cameraYdelta -- update score text scoreText.text = math.floor(mainGroup.y/10) + coinScore end -- recycle platforms to the top of the screen for i = 1, #platformList do local positionOnScreen = mainGroup.y + platformList[i].y if positionOnScreen \> 1000 then local newPlatformPosition = lastPlatformPosition - math.random(3)\*100 platformList[i].y = newPlatformPosition -- add coin or platform if random result is right local randomResult = math.random(4) if randomResult == 1 then coinList[coinCounter].x = platformList[i].x coinList[coinCounter].y = platformList[i].y - 50 coinCounter = coinCounter + 1 if coinCounter \> 8 then coinCounter = 1 end -- if coinCounter needs to be reset elseif randomResult == 2 then trampolineList[trampolineCounter].x = platformList[i].x trampolineList[trampolineCounter].y = platformList[i].y - 45 trampolineCounter = trampolineCounter + 1 if trampolineCounter \> 8 then trampolineCounter = 1 end -- if trampolineCounter needs to be reset end -- if math.random coin placement -- update lastPlatformPosition lastPlatformPosition = newPlatformPosition end end end -- frameLoop() local screenTouchedListener = function(event) if event.phase == "began" then playerXdirection = math.ceil((event.x)/320) elseif event.phase == "ended" then playerXdirection = 0 end end -- screenTouchedListener() Runtime:addEventListener("touch", screenTouchedListener) Runtime:addEventListener("enterFrame", frameLoop)
Note: if I would hardcode the variables and optimize a bit, that would be under a hundred lines of code. That’s the power and beauty of Corona. Prototyping is insanely fast.
Do you have a background in programming or is it all new to you? If yes, what languages and what’s your level?
yes.
you can make whatever you want with corona.
Yes. Corona would be a great tool to make that kind of game! In fact, you might want to do a quick Google:
https://www.google.com/search?q=corona+doodle+jump&oq=corona+doodle+jump
There are a couple of tutorials specifically for building a doodle jump like game.
Rob
Here’s some code to get you started. Set your frames per second to 60 in the config.lua and simulate on iPhone-template:
display.setStatusBar( display.HiddenStatusBar ) -- hide the status bar local mainGroup = display.newGroup() local platformList = {} local coinList = {} local coinCounter = 1 local trampolineList = {} local trampolineCounter = 1 local gravity = .3 local playerVerticalSpeed = 0 local lastPlatformPosition = 960 local coinScore = 0 mainGroup.y = 0 for i = 1, 8 do -- platform creation local newPlatformPosition = lastPlatformPosition - math.random(3)\*100 platformList[i] = display.newRect(mainGroup, math.random(440)+100, newPlatformPosition, 200, 50) lastPlatformPosition = newPlatformPosition end -- for loop platform creation for i = 1,8 do -- coin creation coinList[i] = display.newCircle(mainGroup, -320,0, 20) coinList[i]:setFillColor(1,.75,0) end -- for loop coin creation for i = 1,8 do -- trampoline creation trampolineList[i] = display.newRect(mainGroup, -200,0,100,40) trampolineList[i]:setFillColor(0,.5,1) end local playerSprite = display.newRect(mainGroup,320,480,100,100) -- create scoreText local scoreText = display.newText("0",320,50, native.systemFont, 32) local playerXdirection = 0 local frameLoop = function(event) -- calculate the horizontal motion if playerXdirection == 1 then playerSprite.x = playerSprite.x - 5 elseif playerXdirection == 2 then playerSprite.x = playerSprite.x + 5 end -- add gravity to hero playerVerticalSpeed = playerVerticalSpeed + gravity playerSprite.nextYposition = playerSprite.y + playerVerticalSpeed -- do collision detection of next Y position with all platforms if playerVerticalSpeed \> 4 then for i = 1,8 do -- go over all 6 platforms if (math.abs((playerSprite.nextYposition+50) - (platformList[i].y))\<25) and (math.abs(playerSprite.x - platformList[i].x)\<150) then playerVerticalSpeed = -15 end end -- for loop over all 6 platforms end -- if moving down! -- set the player y position to the hypotethical y position playerSprite.y = playerSprite.nextYposition -- do collision detection with coins for i = 1, #coinList do local xDistanceToPlayer = coinList[i].x - playerSprite.x local yDistanceToPlayer = coinList[i].y - playerSprite.y if math.sqrt(xDistanceToPlayer\*xDistanceToPlayer + yDistanceToPlayer\*yDistanceToPlayer) \< 40 then coinList[i].x = -320 coinScore = coinScore + 100 end -- if coin distance check end -- update "camera position" local cameraYdelta = mainGroup.y + playerSprite.y - 480 if cameraYdelta \< 0 then mainGroup.y = mainGroup.y - cameraYdelta -- update score text scoreText.text = math.floor(mainGroup.y/10) + coinScore end -- recycle platforms to the top of the screen for i = 1, #platformList do local positionOnScreen = mainGroup.y + platformList[i].y if positionOnScreen \> 1000 then local newPlatformPosition = lastPlatformPosition - math.random(3)\*100 platformList[i].y = newPlatformPosition -- add coin or platform if random result is right local randomResult = math.random(4) if randomResult == 1 then coinList[coinCounter].x = platformList[i].x coinList[coinCounter].y = platformList[i].y - 50 coinCounter = coinCounter + 1 if coinCounter \> 8 then coinCounter = 1 end -- if coinCounter needs to be reset elseif randomResult == 2 then trampolineList[trampolineCounter].x = platformList[i].x trampolineList[trampolineCounter].y = platformList[i].y - 45 trampolineCounter = trampolineCounter + 1 if trampolineCounter \> 8 then trampolineCounter = 1 end -- if trampolineCounter needs to be reset end -- if math.random coin placement -- update lastPlatformPosition lastPlatformPosition = newPlatformPosition end end end -- frameLoop() local screenTouchedListener = function(event) if event.phase == "began" then playerXdirection = math.ceil((event.x)/320) elseif event.phase == "ended" then playerXdirection = 0 end end -- screenTouchedListener() Runtime:addEventListener("touch", screenTouchedListener) Runtime:addEventListener("enterFrame", frameLoop)
Note: if I would hardcode the variables and optimize a bit, that would be under a hundred lines of code. That’s the power and beauty of Corona. Prototyping is insanely fast.
Do you have a background in programming or is it all new to you? If yes, what languages and what’s your level?