Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Hello, i'm richard
Started by info0602 Dec 29 2018 12:58 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

info0602

[GLOBAL: userInfoPane.html]
info0602
  • Observer

  • 1 posts
  • Corona SDK

Can i develop a 2d game like doodle jump in corona ?



[TOPIC: post.html]
#2

alberto.diego.chisilevich

[GLOBAL: userInfoPane.html]
alberto.diego.chisilevich
  • Observer

  • 28 posts
  • Corona SDK

yes.
you can make whatever you want with corona.

[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,541 posts
  • Enterprise

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



[TOPIC: post.html]
#4

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 950 posts
  • Corona SDK

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)


[TOPIC: post.html]
#5

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 950 posts
  • Corona SDK

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?




[topic_controls]
[/topic_controls]