vendredi 14 février 2020

How to use an if else statement in swift for a game; the game logic has to recognize if a node hits the right side a square

I have come upon a road block in designing my game. In this game, a brick falls from the top of the screen down, moving towards and square with different sides. If the brick matches up with the holes in side of the square, then it would be "correct". Regarding game logic, any suggestions of what code to write/change in order to print "correct."

picture of the brick falling

extension GameScene: SKPhysicsContactDelegate {

func didBegin(_ contact: SKPhysicsContact) {
    let contactMask = contact.bodyA.categoryBitMask |
         contact.bodyB.categoryBitMask

    if contactMask == PhysicsCategories.brickCategory |
        PhysicsCategories.basicBrickCategory {
        if let brick = contact.bodyA.node?.name == "Brick" ?
            contact.bodyA.node as? SKSpriteNode : contact.bodyB.node as?
            SKSpriteNode {
            if {
                print("Correct")
                brick.run(SKAction.fadeOut(withDuration: 0.5), completion: {
                    brick.removeFromParent()
                    self.spawnBrick()
                })
            } else {
                gameOver()

            }

        }
    }
}
}

Aucun commentaire:

Enregistrer un commentaire