Sub Box2D_BeginContact(Contact As lgBox2DContact)
Dim thisContact As typContact
thisContact.Body1 = Contact.FixtureA.Body
thisContact.Body2 = Contact.FixtureB.Body
If Contact.FixtureA.Body.UserData = Null Or _
Contact.FixtureB.Body.UserData = Null Then Return
If Contact.FixtureA.Body.UserData Is objcor And Contact.Fixtureb.Body.UserData Is objcor Then
Dim objcor1 As objcor = thisContact.Body1.UserData
Dim objcor2 As objcor = thisContact.Body2.UserData
If objcor1.name.Contains("lift") And thisContact.Body2 = player Or objcor2.name.Contains("lift") And thisContact.Body1 = player Then
Dim liftb As lgBox2DBody
If player = thisContact.Body1 Then liftb = thisContact.Body2 Else liftb = thisContact.Body1
onlift = True
liftonBody = liftb
Dim objc As objcor = liftb.UserData
Dim objc2 As objcor = player.UserData
objc2.speed = objc.speed
objc2.horizontal = objc.horizontal
else if objcor1.name = "train" And thisContact.Body2 = player Or objcor2.name = "train" And thisContact.Body1 = player Then
If trainstop = False Then
Dim trainb As lgBox2DBody
If player = thisContact.Body1 Then trainb = thisContact.Body2 Else trainb = thisContact.Body1
ontrain = True
trainbody = trainb
Dim LeftWheelJoint As lgBox2DRevoluteJoint = Joint_arr.Get(0)
Dim RightWheelJoint As lgBox2DRevoluteJoint = Joint_arr.Get(1)
If LeftWheelJoint.isMotorEnabled = False Then LeftWheelJoint.enableMotor(True)
If RightWheelJoint.isMotorEnabled = False Then RightWheelJoint.enableMotor(True)
End If
else If objcor1.name = ("coin") And thisContact.Body2 = player Or objcor2.name = ("coin") And thisContact.Body1 = player Then
If thisContact.Body2 = player Then
Dim objco1 As objcor = thisContact.Body1.UserData
If objco1.hit = False Then
If soundon = 1 Then coinsound.Play2(0.3)
objco1.hit = True
End If
Else
Dim objco1 As objcor = thisContact.Body2.UserData
If objco1.hit = False Then
If soundon = 1 Then coinsound.Play2(0.3)
objco1.hit = True
End If
End If
cointint = cointint + 1
else If objcor1.name = ("coin2") And thisContact.Body2 = player Or objcor2.name = ("coin2") And thisContact.Body1 = player Then
If thisContact.Body2 = player Then
Dim objco1 As objcor = thisContact.Body1.UserData
If objco1.hit = False Then
If soundon = 1 Then coinsound.Play2(0.3)
objco1.hit = True
End If
Else
Dim objco1 As objcor = thisContact.Body2.UserData
If objco1.hit = False Then
If soundon = 1 Then coinsound.Play2(0.3)
objco1.hit = True
End If
End If
cointint = cointint + 25
else if objcor1.name = "info" And thisContact.Body2 = player Or objcor2.name = "info" And thisContact.Body1 = player Then
If objcor1.name = "info" Then
infoint = objcor1.key
Else
infoint = objcor2.key
End If
drawshield = True
drawshieldFadeOUT = False
drawshieldFadeCD = 0
else if thisContact.Body1 = player And thisContact.Body2 = checkpoint Or thisContact.Body2 = player And thisContact.Body1 = checkpoint Then
If checkpointhit = False Then
checkpointhit = True
If soundon = 1 Then checkpointsound.Play2(0.5)
End If
else If thisContact.Body1 = player And thisContact.Body2 = gate Or thisContact.Body2 = player And thisContact.Body1 = gate Then
Dim gateobj As objcor = gate.UserData
If gateobj.hit = True And gateobj.exitnow = False Then
gateobj.exitnow = True
goleft = False
goright = False
firedown = False
injump = False
player.setLinearVelocity2(player.getLinearVelocityFromWorldPoint(player.WorldCenter).x/2,player.getLinearVelocityFromWorldPoint(player.WorldCenter).y)
End If
else if objcor1.name = "spikes" And thisContact.Body2 = player Or objcor2.name = "spikes" And thisContact.Body1 = player Then
If medead = False Then
killplayer
changeplayertosensor
End If
else if objcor1.name = "key" And thisContact.Body2 = player Or objcor2.name = "key" And thisContact.Body1 = player Then
Dim keycor As objcor
If thisContact.Body1 = player Then
keycor = thisContact.Body2.UserData
If keycor.key = "1" Then
keycor.key = "2"
camerafollow = gate
' cameragofast = True
turnon_elevators
waitforgate = True
End If
Else
keycor = thisContact.Body1.UserData
If keycor.key = "1" Then
keycor.key = "2"
camerafollow = gate
' cameragofast = True
turnon_elevators
waitforgate = True
End If
End If
else if objcor1.name = "sticky" And thisContact.Body2 = player Or objcor2.name = "sticky" And thisContact.Body1 = player Then
onsticky = True
else if objcor1.name = "enemy" And thisContact.Body2 = player Or objcor2.name = "enemy" And thisContact.Body1 = player Then
If medead = False Then
killplayer
changeplayertosensor
End If
else if objcor1.name = "fallstone" And thisContact.Body2 = player Or objcor2.name = "fallstone" And thisContact.Body1 = player Then
Dim fallstone As lgBox2DBody
If thisContact.Body2 = player Then fallstone = thisContact.Body1 Else fallstone = thisContact.Body2
Dim fallstoneobj As objcor = fallstone.UserData
If fallstone.getLinearVelocityFromWorldPoint(fallstone.WorldCenter).y < -2 Then
If medead = False Then
fallstoneobj.hit = True
killplayer
changeplayertosensor
If soundon = 1 Then fallstonesound.Play2(0.6)
Worldshakenow = True
shakeCD = 20
End If
End If
else if objcor1.name = "fallstone" And objcor2.name = "ground" Or objcor2.name = "fallstone" And objcor1.name = "ground" Then
Dim fallstoneobj As objcor
If objcor2.name = "ground" Then fallstoneobj = objcor1 Else fallstoneobj = objcor2
If fallstoneobj.hit = False Then
fallstoneobj.hit = True
If soundon = 1 Then fallstonesound.Play2(0.6)
Worldshakenow = True
shakeCD = 20
End If
Else if objcor1.name = "enemybullet" And thisContact.Body2 = player Or objcor2.name = "enemybullet" And thisContact.Body1 = player Then
If thisContact.Body2 = player Then
Dim bullet As objcor = thisContact.Body1.UserData
bullet.hit = True
Else
Dim bullet As objcor = thisContact.Body2.UserData
bullet.hit = True
End If
If medead = False Then
killplayer
changeplayertosensor
End If
else if objcor1.name = "enemybullet" And thisContact.Body2 <> player Or objcor2.name = "enemybullet" And thisContact.Body1 <> player Then
If objcor1.key = "fireball" Or objcor2.key = "fireball" Then
If objcor1.key = "fireball" Then
If objcor2.name = "lava" Then
If objcor2.hit = False Then
objcor2.hit = True
objcor2.xbody = "lava"
End If
else if objcor2.name = "fireball" Then
If objcor1.hit = False Then
objcor1.hit = True
End If
End If
else If objcor2.key = "fireball" Then
If objcor1.name = "lava" Then
If objcor1.hit = False Then
objcor1.hit = True
objcor1.xbody = "lava"
End If
else if objcor1.name = "fireball" Then
If objcor2.hit = False Then
objcor2.hit = True
End If
End If
End If
else If objcor1.name = "wall" Or objcor1.name = "ground" Or objcor1.name = "movingwall" Or objcor1.name = "spikes" Or objcor1.name = "sticky" Or objcor1.name = "groundvis" Or objcor1.name = "fallground" Or objcor1.name = "lift" Or objcor1.name = "fallstone" Or objcor2.name = "wall" Or objcor2.name = "ground" Or objcor2.name = "movingwall" Or objcor2.name = "spikes" Or objcor2.name = "sticky" Or objcor2.name = "groundvis" Or objcor2.name = "fallground" Or objcor2.name = "lift" Or objcor2.name = "fallstone" Then
If objcor1.name = "enemybullet" Then
Dim bullet As objcor = thisContact.Body1.UserData
bullet.hit = True
Else
Dim bullet As objcor = thisContact.Body2.UserData
bullet.hit = True
End If
End If
else if objcor1.name = "enemy" And objcor2.name = "train" Or objcor2.name = "enemy" And objcor1.name = "train" Then
If objcor2.name = "train" Then
If objcor1.key = "stone" Then
If trainstop = False Then
If Abs(trainbody.getLinearVelocityFromWorldPoint(trainbody.WorldCenter).x) < 1 Then
trainstop = True
Dim LeftWheelJoint As lgBox2DRevoluteJoint = Joint_arr.Get(0)
Dim RightWheelJoint As lgBox2DRevoluteJoint = Joint_arr.Get(1)
LeftWheelJoint.enableMotor(False)
RightWheelJoint.enableMotor(False)
End If
End If
End If
Else
If objcor2.key = "stone" Then
If trainstop = False Then
If Abs(trainbody.getLinearVelocityFromWorldPoint(trainbody.WorldCenter).x) < 1 Then
trainstop = True
Dim LeftWheelJoint As lgBox2DRevoluteJoint = Joint_arr.Get(0)
Dim RightWheelJoint As lgBox2DRevoluteJoint = Joint_arr.Get(1)
LeftWheelJoint.enableMotor(False)
RightWheelJoint.enableMotor(False)
End If
End If
End If
End If
else if objcor1.name = "water" And thisContact.Body2 = player Or objcor2.name = "water" And thisContact.Body1 = player Then
Dim waterbody As lgBox2DBody
If thisContact.Body2 = player Then waterbody = thisContact.Body1 Else waterbody = thisContact.Body2
Dim waterobj As objcor = waterbody.UserData
If waterobj.hit = False Then waterobj.hit = True
inwater = True
else if objcor1.name = "lava" And thisContact.Body2 = player Or objcor2.name = "lava" And thisContact.Body1 = player Then
Dim lavabody As lgBox2DBody
If thisContact.Body2 = player Then lavabody = thisContact.Body1 Else lavabody = thisContact.Body2
Dim lavaobj As objcor = lavabody.UserData
If lavaobj.hit = False Then
lavaobj.hit = True
lavaobj.xbody = "player"
End If
If medead = False Then
killplayer
changeplayertosensor
End If
else If objcor1.name = "fallground" And thisContact.Body2 = player Or objcor2.name = "fallground" And thisContact.Body1 = player Then
Dim fallg As lgBox2DBody
If player = thisContact.Body2 Then fallg = thisContact.Body1 Else fallg = thisContact.Body2
Dim fallgobj As objcor = fallg.UserData
If fallgobj.hit = False Then
fallgobj.hit = True
fallg.GravityScale = 0.5 'set gravity to falling ground!
fallgroundtouched = True
End If
else if objcor1.name = "groundsh" And thisContact.Body2 = player Or objcor2.name = "groundsh" And thisContact.Body1 = player Then
If thisContact.Body2 = player Then
If objcor1.key = "right" Then
player.setLinearVelocity2(speed*0.8,player.getLinearVelocityFromWorldPoint(player.WorldCenter).y)
Else
player.setLinearVelocity2(-speed*0.8,player.getLinearVelocityFromWorldPoint(player.WorldCenter).y)
End If
Else
If objcor2.key = "right" Then
player.setLinearVelocity2(speed*0.8,player.getLinearVelocityFromWorldPoint(player.WorldCenter).y)
Else
player.setLinearVelocity2(-speed*0.8,player.getLinearVelocityFromWorldPoint(player.WorldCenter).y)
End If
End If
ongroundsh = True
else If objcor1.name = "velocity" And thisContact.Body2 = player Or objcor2.name = "velocity" And thisContact.Body1 = player Then
Dim velobjcor As objcor
If thisContact.Body2 = player Then velobjcor = thisContact.Body1.UserData Else velobjcor = thisContact.Body2.UserData
If velobjcor.horizontal = 1 Then
autovelocityON = True
Else
If autovelocityON = True Then
autovelocityON = False
goright = False
End If
End If
else If objcor1.name = "bottle" And thisContact.Body2 = player Or objcor2.name = "bottle" And thisContact.Body1 = player Then
Dim bottleobjcor As objcor
If thisContact.Body2 = player Then bottleobjcor = thisContact.Body1.UserData Else bottleobjcor = thisContact.Body2.UserData
If bottleobjcor.hit = False Then
bottleobjcor.hit = True
End If
else if objcor1.name = "buttonaction" And thisContact.Body2 = player Or objcor2.name = "buttonaction" And thisContact.Body1 = player Then
Dim btnact As lgBox2DBody
If thisContact.Body2 = player Then btnact = thisContact.Body1 Else btnact = thisContact.Body2
Dim btncor As objcor = btnact.UserData
If btncor.hit = False Then
If player.Position.y-(20/scaleY) > btnact.Position.y Then
btncor.hit = True
movingwallint = btncor.frame
If soundon = 1 Then opensound.Play2(0.4)
End If
End If
else if objcor1.name = "knife" And objcor2.name = "knifestation" Or objcor2.name = "knife" And objcor1.name = "knifestation" Then
If objcor1.name = "knife" Then
If objcor2.shoot = 0 Then 'knife hit reciver
objcor1.hit = True
End If
Else
If objcor1.shoot = 0 Then 'knife hit reciver
objcor2.hit = True
End If
End If
else If objcor1.name = "knife" And thisContact.Body2 = player Or objcor2.name = "knife" And thisContact.Body1 = player Then
If medead = False Then
killplayer
changeplayertosensor
End If
Else If objcor1.name = "rails" And thisContact.Body2 = player Or objcor2.name = "rails" And thisContact.Body1 = player Then
If medead = False Then
killplayer
changeplayertosensor
End If
else If objcor1.name = "JointB" And thisContact.Body2 = player Or objcor2.name = "JointB" And thisContact.Body1 = player Then
Dim jbody As lgBox2DBody
If player = thisContact.Body2 Then jbody = thisContact.Body1 Else jbody = thisContact.Body2
Dim jbodycor1 As objcor = jbody.UserData
If jbodycor1.key = "enemy" Then
If medead = False Then
killplayer
changeplayertosensor
End If
Else
'do nothing just a dnamic body with swing simulation
End If
End If
else if Contact.FixtureA.Body.UserData Is sword And Contact.Fixtureb.Body.UserData Is objcor Or Contact.Fixtureb.Body.UserData Is sword And Contact.Fixturea.Body.UserData Is objcor Then
If Contact.FixtureA.Body.UserData Is sword Then
Dim cor1 As objcor = Contact.Fixtureb.Body.UserData
If cor1.name = "wall" Or cor1.name = "ground" Or cor1.name = "movingwall" Or cor1.name = "spikes" Or cor1.name.Contains("canon") Then
Dim sword1 As sword = Contact.FixtureA.Body.UserData
If sword1.hit = False Then
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
else if cor1.name = "treasure" Then
If cor1.key = "0" Then
cor1.key = "1"
Dim sword1 As sword = Contact.FixtureA.Body.UserData
If sword1.hit = False Then
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
End If
else if cor1.name = "enemy" Then
If cor1.hit = False Then
Dim sword1 As sword = Contact.FixtureA.Body.UserData
If cor1.key <> "superspike" And cor1.key <> "blade" And cor1.key <> "stone" And cor1.key <> "axe" Then
If sword1.hit = False Then
cor1.hitallowed = cor1.hitallowed - selectedSword.swordPower
cor1.redCD = 10
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
If cor1.hitallowed < 1 Then cor1.hit = True
else If sword1.hit = False Then
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
End If
else if cor1.name = "JointB" Then
Dim sword1 As sword = Contact.FixtureA.Body.UserData
If sword1.hit = False Then
sword1.hit = True
Dim vec2 As lgMathVector2
If sword1.direction = 1 Then
vec2.Set(4,0)
Else
vec2.Set(-4,0)
End If
Contact.Fixtureb.Body.applyLinearImpulse(vec2,Contact.Fixtureb.Body.WorldCenter,True)
If soundon = 1 Then hitsound.Play2(0.5)
End If
else if cor1.name = "box" Then
Dim sword1 As sword = Contact.FixtureA.Body.UserData
If sword1.hit = False Then
sword1.hit = True
Dim vec2 As lgMathVector2
If sword1.direction = 1 Then
vec2.Set(2.5,0)
Else
vec2.Set(-2.5,0)
End If
Contact.Fixtureb.Body.applyLinearImpulse(vec2,Contact.Fixtureb.Body.WorldCenter,True)
If soundon = 1 Then hitsound.Play2(0.5)
End If
else if cor1.name = "fallstone" Then
Dim sword1 As sword = Contact.FixtureA.Body.UserData
If sword1.hit = False Then
cor1.hitallowed = cor1.hitallowed - selectedSword.swordPower
sword1.hit = True
End If
If soundon = 1 Then hitsound.Play2(0.5)
End If
Else
Dim cor1 As objcor = Contact.FixtureA.Body.UserData
If cor1.name = "wall" Or cor1.name = "ground" Or cor1.name = "movingwall" Or cor1.name = "spikes" Or cor1.name.Contains("canon") Then
Dim sword1 As sword = Contact.Fixtureb.Body.UserData
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
else if cor1.name = "treasure" Then
If cor1.key = "0" Then
cor1.key = "1"
Dim sword1 As sword = Contact.Fixtureb.Body.UserData
If sword1.hit = False Then
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
End If
else if cor1.name = "enemy" Then
If cor1.hit = False Then
Dim sword1 As sword = Contact.Fixtureb.Body.UserData
If sword1.hit = False Then
If cor1.key <> "superspike" And cor1.key <> "blade" And cor1.key <> "stone" And cor1.key <> "axe" Then
If sword1.hit = False Then
cor1.hitallowed = cor1.hitallowed - selectedSword.swordPower
cor1.redCD = 10
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
If cor1.hitallowed < 1 Then cor1.hit = True
else If sword1.hit = False Then
sword1.hit = True
If soundon = 1 Then hitsound.Play2(0.5)
End If
End If
End If
else if cor1.name = "JointB" Then
Dim sword1 As sword = Contact.Fixtureb.Body.UserData
If sword1.hit = False Then
sword1.hit = True
Dim vec2 As lgMathVector2
If sword1.direction = 1 Then
vec2.Set(4,0)
Else
vec2.Set(-4,0)
End If
Contact.Fixturea.Body.applyLinearImpulse(vec2,Contact.Fixturea.Body.WorldCenter,True)
If soundon = 1 Then hitsound.Play2(0.5)
End If
else if cor1.name = "box" Then
Dim sword1 As sword = Contact.Fixtureb.Body.UserData
If sword1.hit = False Then
sword1.hit = True
Dim vec2 As lgMathVector2
If sword1.direction = 1 Then
vec2.Set(2.5,0)
Else
vec2.Set(-2.5,0)
End If
Contact.Fixturea.Body.applyLinearImpulse(vec2,Contact.Fixturea.Body.WorldCenter,True)
If soundon = 1 Then hitsound.Play2(0.5)
End If
else if cor1.name = "fallstone" Then
Dim sword1 As sword = Contact.Fixtureb.Body.UserData
If sword1.hit = False Then
cor1.hitallowed = cor1.hitallowed - selectedSword.swordPower
sword1.hit = True
End If
If soundon = 1 Then hitsound.Play2(0.5)
End If
End If
End If
End Sub