I searched through the site and could not see where to do this. For this one scene it is just a small game like angry birds where it uses the physics and lets you throw an object at others stacked to knock down. It’s only one level so hopefully I can make this work with rotated graphics. Below is the basic code that I got from a demo on here and added a couple changes so far. Can you advise me what I may need to change in here? I know I will need to change the direction the game variable moves when the ball is thrown. But how do I change the direction of the gravity for the ball and the blocks that will fall down?
Thanks!
Warren
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local m1 = 0
local physics = require("physics")
physics.start()
physics.setScale(50)
local game = display.newGroup()
local circle = display.newImage( "gfx/anthony.png")
circle.x =20
circle.y = 220
physics.addBody(circle, "dynamic", {density = .7, friction = 0.3, bounce = 0.2, radius = 40})
game:insert(circle)
local floor = display.newRect( 0, 300, 12048, 4 )
physics.addBody(floor, "static", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
game:insert(floor)
-- Add Blocks
local x = 1200
local y = 235
local block1 = display.newImage("gfx/block1.png")
block1.x = x
block1.y = y
physics.addBody(block1, "dynamic", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
block1.myName = "b1"
game:insert(block1)
x = x + 50
local block2 = display.newImage("gfx/block1.png")
block2.x = x
block2.y = 235
physics.addBody(block2, "dynamic", {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
block2.myName = "b2"
game:insert(block2)
function circleTouched(event)
if event.phase == "began" then
display.getCurrentStage():setFocus(circle)
elseif event.phase == "ended" then
local p1 = event.xStart - event.x
local p2 = event.yStart - event.y
if p1 \> 20 then
p1 = 20
end
if p1 \< -17 then
p1 = -17
end
if p2 \> 10 then
p2 = 10
end
if p2 \< -30 then
p2 = -30
end
print(p2)
circle:applyLinearImpulse(p1, p2, circle.x, circle.y)
display.getCurrentStage():setFocus(nil)
end
end
circle:addEventListener("touch", circleTouched)
local function onCollision( event )
if ( event.phase == "began" ) then
--print( event.object2.myName )
end
end
Runtime:addEventListener( "collision", onCollision )
function loop(e)
local targetx = 300 - circle.x
--game.x = game.x + ((targetx - game.x) \*0.05)
if circle.x \> 200 then
local d = (game.x - (circle.x - 200) )
d = d - game.x
game.x = d
end
end
Runtime:addEventListener("enterFrame", loop)
[import]uid: 184193 topic_id: 35854 reply_id: 142578[/import]