The bodies just pass right through each other. Please help.
--# Main
function setup()
parameter.watch(PlayerY)
displayMode(FULLSCREEN_NO_BUTTONS)
supportedOrientations(LANDSCAPE_ANY)
floor1 = physics.body(POLYGON,vec2(-501,HEIGHT/2 - 200),vec2(1000,HEIGHT/2 - 200),vec2(-501,HEIGHT/2 - 200),vec2(1000,HEIGHT/2 - 200))
floor2 = physics.body(POLYGON,vec2(490,HEIGHT/2 + 186),vec2(1000,HEIGHT/2 + 186),vec2(450,HEIGHT/2 + 215),vec2(1000,HEIGHT/2 + 215))
Player = physics.body(POLYGON,vec2(WIDTH/2 + 10,HEIGHT/2 - 10),vec2(WIDTH/2 - 10,HEIGHT/2 - 10),vec2(WIDTH/2 + 10,HEIGHT/2 - 10),vec2(WIDTH/2 - 10,HEIGHT/2 + 10))
-- moved the following line from draw
physics.gravity(0,-300) -- changed
parameter.watch("PlayerX")
parameter.watch("PlayerY")
parameter.watch("Floor1Y")
Scene = 1
scrollTitleScreen = 0
xVel = 0
yVel = 0
Player.y = 500
Player.x = 500
floor1.gravityScale=0
floor2.gravityScale=0
floor1.x = 200
floor1.y = 200
floor1.density=5000
end
function draw()
--Draws the appropritate stagese
--Scenes:
--1 = Title Screen
--2 = Gamemode Select
--3 = Stage select
--4 = Ingame
scene = Scene
PlayerX = Player.x
PlayerY = floor1.y
textMode(CENTER)
-- moved this line to setup
--Player.x = WIDTH/2 Player.y = HEIGHT/2 floor1.x = 500
if Scene == 1 then
physics.pause()
strokeWidth(5)
background(0, 255, 251, 255)
font("Copperplate-Bold")
fill(0, 0, 0, 255)
fontSize(87)
text("THE PROTO PROGRAM",WIDTH/2,HEIGHT -78)
rectMode(CENTER)
fill(0, 255, 251, 255)
stroke(0, 0, 0, 255)
rect(WIDTH/2,HEIGHT/2,250,126)
fill(0, 0, 0, 255)
fontSize(60) text("PLAY",WIDTH/2,HEIGHT/2)
elseif Scene == 2 then
physics.pause()
strokeWidth(5)
fontSize(84)
stroke(0, 0, 0, 255)
fill(51,51,51,255)
background(0,255,251,255)
rectMode(CENTER)
fill(0, 0, 0, 255)
text("CHOOSE A GAMEMODE",WIDTH/2,HEIGHT -78)
fill(0, 255, 251, 255)
rect(WIDTH/2,HEIGHT/2,250,126)
fontSize(27)
fill(0,0,0,250)
text("DEATHMATCH",WIDTH/2,HEIGHT/2)
rectMode(CORNER)
fill(0, 255, 251, 255)
rect(-3,-3,100,50)
rectMode(CENTER)
textMode(CORNER)
fontSize(25)
fill(0, 0, 0, 255)
text("BACK",9,10)
elseif Scene == 3 then
physics.pause()
background(0,255,251,255)
strokeWidth(5)
fontSize(84)
stroke(0, 0, 0, 255)
background(0,255,251,255)
rectMode(CENTER)
fill(0, 0, 0, 255)
text("CHOOSE A STAGE",WIDTH/2,HEIGHT -78)
fill(0, 255, 251, 255)
rect(WIDTH/2,HEIGHT/2,250,126)
fontSize(49)
fill(0,0,0,250)
text("METRO",WIDTH/2,HEIGHT/2)
rectMode(CORNER)
fill(0, 255, 251, 255)
rect(-3,-3,100,50)
rectMode(CENTER)
textMode(CORNER)
fontSize(25)
fill(0, 0, 0, 255)
text("BACK",9,10)
elseif Scene == 4 then
physics.resume()
rectMode(CENTER)
stroke(0, 0, 0, 255)
fill(127, 127, 127, 255)
strokeWidth(5)
fontSize(84)
stroke(0, 0, 0, 255)
background(35, 47, 47, 255)
rectMode(CENTER)
fill(0, 0, 0, 255)
rect(floor1.x,floor1.y,1200,90)
rect(floor2.x + 1080,floor2.y,1207,20)
fontSize(49)
fill(0,0,0,250)
rectMode(CORNER)
fill(0, 255, 251, 255)
rect(-3,-3,200,100)
rectMode(CENTER)
textMode(CORNER)
fontSize(55)
fill(0, 0, 0, 255)
text("LEFT",9,10)
rectMode(CORNER)
fill(0, 255, 251, 255)
stroke(0, 0, 0, 255)
rect(197,-3,200,100)
rectMode(CENTER)
textMode(CORNER)
fontSize(55)
fill(0, 0, 0, 255)
text("RIGHT",209,10)
rectMode(CENTER)
rectMode(CORNER)
fill(0, 255, 251, 255)
stroke(0, 0, 0, 255)
rect(95,97,200,100)
rectMode(CENTER)
textMode(CORNER)
fontSize(55)
fill(0, 0, 0, 255)
text("RIGHT",209,10)
rectMode(CENTER)
sprite("Documents:Cyborg",Player.x,Player.y,73,90)
if Scene == 5 then
physics.pause()
tint(0, 0, 0, 255)
rectMode(CENTER)
stroke(0, 0, 0, 255)
fill(127, 127, 127, 255)
strokeWidth(5)
fontSize(84)
stroke(0, 0, 0, 255)
background(35, 47, 47, 255)
rectMode(CENTER)
fill(0, 0, 0, 255)
rect(floor1.x,floor1.y,1200,90)
fontSize(49)
fill(0,0,0,250)
rectMode(CORNER)
fill(0, 255, 251, 255)
rect(-3,-3,200,100)
rectMode(CENTER)
textMode(CORNER)
fontSize(55)
fill(0, 0, 0, 255)
text("LEFT",9,10)
rectMode(CORNER)
fill(0, 255, 251, 255)
stroke(0, 0, 0, 255)
rect(197,-3,200,100)
rectMode(CENTER)
textMode(CORNER)
fontSize(55)
fill(0, 0, 0, 255)
text("RIGHT",209,10)
rectMode(CENTER)
rectMode(CORNER)
fill(0, 255, 251, 255)
stroke(0, 0, 0, 255)
rect(95,97,200,100)
rectMode(CENTER)
textMode(CORNER)
fontSize(55)
fill(0, 0, 0, 255)
text("RIGHT",209,10)
rectMode(CENTER)
sprite("Documents:Cyborg",Player.x,Player.y,20,1000)
rect(WIDTH/2,HEIGHT/2,500,400)
end
end
end
--Buttons
--DeathMatch button
function touched(touch)
if touch.state == ENDED and touch.x > WIDTH/2 - 125 and
touch.x < WIDTH /2 + 125 and touch.y < HEIGHT/2+63 and
touch.y > HEIGHT/2- 63 and Scene == 2 then
Scene = 3
sound(SOUND_BLIT, 16900)
floor1.x = 500
Player.y = 500
end
--Play button
if touch.state == ENDED and touch.x > WIDTH/2 - 125 and
touch.x < WIDTH /2 + 125 and touch.y < HEIGHT/2+63 and
touch.y > HEIGHT/2- 63 and Scene == 1 then
Scene = 2
sound(SOUND_BLIT, 16900)
end
--Metro stage button
if touch.state == ENDED and touch.x > WIDTH/2 - 125 and
touch.x < WIDTH /2 + 125 and touch.y < HEIGHT/2+63 and
touch.y > HEIGHT/2- 63 and Scene == 3 then
Scene = 4
sound(SOUND_BLIT, 16900)
end
--Back button (title screen)
if touch.state == ENDED and touch.x > 0 and touch.x < 100 and
touch.y < 100 and touch.y > 0 and Scene ~= 1 and Scene ~= 4 then
Scene = Scene -1
sound(SOUND_BLIT, 16900)
end
--Ingame buttons
--Left button
if Scene == 4 then
if touch.x > 0 and touch.x < 200 and
touch.y < 100 and touch.y > 0 then
if touch.state == BEGAN or touch.state == MOVING then
xVel = 100
yVel = 0
updatePlayerVel()
end
elseif touch.state == ENDED then
xVel = 0
updatePlayerVel()
end
--Right button
if touch.x > 200 and touch.x < 400 and
touch.y < 100 and touch.y > 0 then
if touch.state == BEGAN or touch.state == MOVING then
xVel = -100
yVel = 0
updatePlayerVel()
end
elseif touch.state == ENDED then
xVel = 0
updatePlayerVel()
end
--Jump button
if Player:testOverlap(floor1) then
if touch.x > 95 and touch.x < 295 and
touch.y < 200 and touch.y > 100 then
if touch.state == BEGAN then
yVel = 300
updatePlayerVel()
end
end
end
end
end
function updatePlayerVel()
floor1.linearVelocity = vec2(xVel,yVel)
floor2.linearVelocity = vec2(xVel,yVel)
Player.linearVelocity = vec2(0,yVel)
end