Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

roll around marble game using corona?
Started by stubones99 May 11 2015 08:06 AM

4 replies to this topic
tilt orientation game
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

stubones99

[GLOBAL: userInfoPane.html]
stubones99
  • Enthusiast

  • 71 posts
  • Corona SDK

Will corona expose the orientation of an iphone / android phone enough to make a roll around marble game (where you dodge the holes and move the marble by tilting the device one way or another. 

 

I see iphone games out there that do similar things but don't see the level / tilt data in the API. I assume it does not use the acceleratormeters, but I could be mistaken.

 

Thanks!



[TOPIC: post.html]
#2

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 950 posts
  • Corona SDK

No problem. Corona can do this. Mind you, because there is no 3D in Corona it is not evident to get a realistic rolling ball effect - but this is definitely NOT necessary to make a cool rolling marble game (look at Dark Nebula).



[TOPIC: post.html]
#3

stubones99

[GLOBAL: userInfoPane.html]
stubones99
  • Enthusiast

  • 71 posts
  • Corona SDK

How do you get the level or tilt of a device from Corona?

 

I remember there was 6 directions (laid left / right, right side up, upside down, and that sort of thing for orientation) but it would not let you  get degrees of rotation or tilt of device.

 

Thanks!
stu



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,561 posts
  • Enterprise

This is the code from my first game Omniblaster where you used tilt to move the ship side to side.  Same basic idea you're wanting to do:

local function onTilt(event)
    app.myRocket.x = (app.myRocket.x + event.xGravity * ((app.sensitivity * 15 )+ level))
    if app.myRocket.x < 0 then
        app.myRocket.x = 0
    elseif app.myRocket.x > (display.contentWidth - 64) then
        app.myRocket.x = display.contentWidth - 64
    end


    return true
end
Runtime:addEventListener("accelerometer", onTilt )

No need to mess with orientation events, just use the accelerometer to get your X, Y and Z movement.

 

Rob



[TOPIC: post.html]
#5

WideAwakeGames

[GLOBAL: userInfoPane.html]
WideAwakeGames
  • Contributor

  • 143 posts
  • Corona SDK

Try something like this to get you started. 


                
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local _W = display.contentWidth
local _H = display.contentHeight

local physics = require("physics")
physics.setDrawMode("hybrid")
physics.start()

physics.setScale( 60 )
physics.setGravity( 0, 0 ) 

system.setAccelerometerInterval( 100 ) -- set accelerometer to maximum responsiveness
display.setStatusBar( display.HiddenStatusBar )

function onTilt( event )
        
        physics.setGravity( ( -7 * event.yGravity ), ( -7 * event.xGravity ) )
        
end

Runtime:addEventListener( "accelerometer", onTilt )

local borderBodyElement = { friction= 0.3, bounce = .5 }


local borderTop = display.newRect( 0, 0, _W,30 )
borderTop.anchorX = 0
borderTop:setFillColor( 0, 0, 0, 0)		
physics.addBody( borderTop, "static", borderBodyElement )

local borderBottom = display.newRect( 0, _H , _W, 30)
borderBottom.anchorX = 0
borderBottom:setFillColor( 0, 0, 0, 0)		
physics.addBody( borderBottom, "static", borderBodyElement )

local borderLeft = display.newRect( 0, 0, 30, _H )
borderLeft.anchorY = 0
borderLeft:setFillColor( 0, 0, 0, 0)		
physics.addBody( borderLeft, "static", borderBodyElement )

local borderRight = display.newRect( _W , 0, 30, _H )
borderRight.anchorY = 0
borderRight:setFillColor( 0, 0, 0, 0)		
physics.addBody( borderRight, "static", borderBodyElement )

local ball = display.newImage("Icon-60.png", 60, 60 )

physics.addBody( ball, { radius = 30 } )
ball.isSleepingAllowed = false
ball.x = _W / 2
ball.y = _H / 2





[topic_controls]
[/topic_controls]