ios - How can I make my bombs either fall faster or spawn faster the longer the game lasts? -
how can make bombs either fall faster or spawn faster longer game lasts? trying make game harder longer stay alive. harder every 10 bombs. have been researching days , have tried multiple answers similar questions. believe way had make bombs making harder me this. in advance!
var bombspawnspeed : nstimeinterval = 0.40 var bombcounter : int = 0
this in update func. understanding regular update func of whole scene.
override func update(currenttime: cftimeinterval) { /* called before each frame rendered */ if bombcounter >= 10 { if bombspawnspeed > 0.15 { bombspawnspeed -= 0.05 bombcounter = 0 } else { bombspawnspeed = 0.1 } }
here bombs
func enemies() { let bomb1 = skspritenode(imagenamed: "atomicbomb") let bomb2 = skspritenode(imagenamed: "emp") let bomb3 = skspritenode(imagenamed: "biobomb") let bomb4 = skspritenode(imagenamed: "chembomb") let enemy = [bomb1, bomb2, bomb3, bomb4] // enemy physics bomb in enemy { bomb1.size = cgsize(width: 55, height: 55) bomb2.size = cgsize(width: 55, height: 70) bomb3.size = cgsize(width: 30, height: 30) bomb4.size = cgsize(width: 45, height: 70) bomb.physicsbody = skphysicsbody(circleofradius: bomb.size.width / 4) bomb.physicsbody?.categorybitmask = physicscategory.enemy bomb.physicsbody?.collisionbitmask = physicscategory.missile | physicscategory.airdefense bomb.physicsbody?.contacttestbitmask = physicscategory.missile | physicscategory.airdefense bomb.physicsbody?.affectedbygravity = false bomb.runaction(skaction.speedby(10, duration: 30)) bomb.physicsbody?.dynamic = true bomb1.name = "enemy1" bomb2.name = "enemy2" bomb3.name = "enemy3" bomb4.name = "enemy4" print("bomb") } let deployatrandomposition = arc4random() % 4 switch deployatrandomposition { case 0: bomb1.position.y = frame.size.height let positionx = arc4random_uniform(uint32(frame.size.width)) bomb1.position.x = cgfloat(positionx) self.addchild(bomb1) break case 1: bomb2.position.y = frame.size.height let positionx = arc4random_uniform(uint32(frame.size.width)) bomb2.position.x = cgfloat(positionx) self.addchild(bomb2) break case 2: bomb3.position.y = frame.size.height let positionx = arc4random_uniform(uint32(frame.size.width)) bomb3.position.x = cgfloat(positionx) self.addchild(bomb3) break case 3: bomb4.position.y = frame.size.height let positionx = arc4random_uniform(uint32(frame.size.width)) bomb4.position.x = cgfloat(positionx) self.addchild(bomb4) break default: break } bomb1.runaction(skaction.moveto(airdefense.position, duration: 5)) bomb2.runaction(skaction.moveto(airdefense.position, duration: 5)) bomb3.runaction(skaction.moveto(airdefense.position, duration: 5)) bomb4.runaction(skaction.moveto(airdefense.position, duration: 5)) }
this calling in touches began create bombs
enemytimer = nstimer.scheduledtimerwithtimeinterval(0.4, target: self, selector: selector("enemies"), userinfo: nil, repeats: true)
i think better approach is
add new var called
lasttimeaddedbomb
decide on interval tracking how bombs released
- check if need add new bomb in
update
method
like this:
var lasttimeaddedbomb:nsdate var numberofbombsdropped:int = 0 var difficultylevel:float = 1 override func update(currenttime: cftimeinterval) { if (numberofbombsdropped % 10 == 0) { difficultylevel-= 0.1; } let intervalforbombs = difficultylevel let timefromlastbomb = nsdate().timeintervalsincedate(lasttimeaddedbomb) if (timefromlastbomb >= intervalforbombs) { //call bomb //save last bomb date numberofbombsdropped++ lasttimeaddedbomb = nsdate() } }
Comments
Post a Comment