jeudi 3 janvier 2019

My if statement in spritekit (swift isn't working). I'm trying to increase the number of obstacles as the score gets higher

I'm creating a game in Spritekit where a player has to collect coins. While collecting them, they have to avoid bombs. Basically, I want to increase the number of bombs that appear as the score gets higher... so I used an if statement - but it isn't working. The number of bombs that appear tends to stay the same:

if self.score >= 0 && self.score < 20 {

        bombTimer = Timer.scheduledTimer(withTimeInterval: 4, repeats: true, block: { (timer) in
                self.createBomb()
            })

        } else if self.score >= 20 && self.score < 35 {

            bombTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true, block: { (timer) in
                self.createBomb()
            })

        } else if self.score >= 35 && self.score < 50 {

            bombTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true, block: { (timer) in
                self.createBomb()
            })

        } else if self.score >= 50 && self.score < 150 {

            bombTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { (timer) in
                self.createBomb()
            })

    }

Aucun commentaire:

Enregistrer un commentaire