Skip to content
Snippets Groups Projects
Commit 9f9e79f1 authored by Chan Yong Lee's avatar Chan Yong Lee
Browse files

fix bug in swing practice

parent 2ec58114
Branches
No related tags found
2 merge requests!60Code cleanup lukas fix,!54fix bug in swing practice
......@@ -103,6 +103,7 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
var showRedLine = false
var leftHandCanSwing = false
var rightHandCanSwing = false
var bodyOnSwingPracticeGround = false
// MARK: - Tutorial Scene
override func didMove(to view: SKView) {
......@@ -161,7 +162,7 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
self.ground = obstacleCreator.createRectObstacle(rectSize: CGSize(width: groundWidth, height: groundHeight), type: .StartPoint, texture: nil)
//MARK: why is the position not changed?
self.ground?.position = CGPoint(x: 0, y: -self.frame.width / 6)
ground?.name = "ground"
ground!.name = "ground"
obstacles["ground"] = ground!
addChild(self.ground!)
......@@ -331,6 +332,8 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
if resetGrabStatus {
character.makeHandReleaseFromObstacle(hand: .LeftHand)
character.makeHandReleaseFromObstacle(hand: .RightHand)
leftGrabButtonPressed = false
rightGrabButtonPressed = false
resetGrabStatus = false
}
......@@ -623,7 +626,7 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
if startSwingPractice && convert(character.bodyParts[.LeftUpperArm]!.position, from: character).y < ground!.position.y &&
convert(character.bodyParts[.RightUpperArm]!.position, from: character).y < ground!.position.y {
if leftHandCanSwing && rightHandCanSwing {
if leftHandCanSwing && rightHandCanSwing && !bodyOnSwingPracticeGround {
hangingSuccesful = true
......@@ -691,8 +694,11 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
character.makeHandGrabbingObstacle(hand: .LeftHand)
character.leftHandGrabbingAt = contactNodeB as? SKShapeNode
HapticResponseController.grabSucceedFeedback()
if contactNodeB.name == "ground" {
leftHandCanSwing = true
}
}
if contactNodeB.name == "handsUpLine" && canReachTiltUp {
character.leftHandFirstLineContact = true
......@@ -719,11 +725,15 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
character.makeHandGrabbingObstacle(hand: .LeftHand)
HapticResponseController.grabSucceedFeedback()
character.leftHandGrabbingAt = contactNodeB as? SKShapeNode
if contactNodeA.name == "ground" {
leftHandCanSwing = true
}
}
if contactNodeA.name == "handsUpLine" && canReachTiltUp {
character.leftHandFirstLineContact = true
}
if contactNodeA.name == "firstFlag" {
......@@ -748,8 +758,11 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
character.makeHandGrabbingObstacle(hand: .RightHand)
character.rightHandGrabbingAt = contactNodeB as? SKShapeNode
HapticResponseController.grabSucceedFeedback()
if contactNodeB.name == "ground" {
rightHandCanSwing = true
}
}
if contactNodeB.name == "handsUpLine" && canReachTiltUp {
character.rightHandFirstLineContact = true
......@@ -776,8 +789,11 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
character.makeHandGrabbingObstacle(hand: .RightHand)
character.rightHandGrabbingAt = contactNodeB as? SKShapeNode
HapticResponseController.grabSucceedFeedback()
if contactNodeA.name == "ground" {
rightHandCanSwing = true
}
}
if contactNodeA.name == "handsUpLine" && canReachTiltUp {
character.rightHandFirstLineContact = true
......@@ -803,10 +819,13 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
secondFlagReached = true
}
if contact.bodyB.node!.name == "swingPractice" {
bodyOnSwingPracticeGround = true
}
if contact.bodyB.node!.name == "swingPractice" && startMovingPracticeGround && hangingSuccesful {
landed = true
}
}
} else if contact.bodyB.node! == character.bodyParts[.Body]! {
if obstacles.values.contains(contact.bodyA.node!) {
......@@ -819,6 +838,10 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
secondFlagReached = true
}
if contact.bodyB.node!.name == "swingPractice" {
bodyOnSwingPracticeGround = true
}
if contact.bodyA.node!.name == "swingPractice" && startMovingPracticeGround && hangingSuccesful {
landed = true
}
......@@ -868,6 +891,20 @@ class TutorialScene: SKScene, SKPhysicsContactDelegate {
rightHandCanSwing = false
}
}
if contact.bodyA.node! == character.bodyParts[.Body]! {
if obstacles.values.contains(contact.bodyB.node!) {
if contact.bodyB.node!.name == "swingPractice" {
bodyOnSwingPracticeGround = false
}
}
} else if contact.bodyB.node! == character.bodyParts[.Body]! {
if obstacles.values.contains(contact.bodyA.node!) {
if contact.bodyB.node!.name == "swingPractice" {
bodyOnSwingPracticeGround = false
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment