ios - Simple combo multiplier in sprite-kit -


i making reaction game, can destroy enemys , earn points. have combo points if destroy them fast , if there specific time gap combo multiplier should go 0 again.

i multiple points this: 2 * 2 = 4 * 2 = 8 * 2 = 16 * 2... (you 2 points if destroy enemy).

i add points here:

if (cgrectintersectsrect(enemy.frame, player.frame)) {         points = points + 1;         [enemy removefromparent];     } 

i multiply current points 2, want reset combo multiplier if there specific amount of time without getting points.

i hope can me. (code in objective c please)

it seems no more complicated recording time last enemy destroyed , in update: method deciding if combo has elapsed no more enemies hit in whatever timeout period allow.

i not familiar sprite kit, update appears pass current time; excellent. need record following:

  • timeout (time): current timeout. reduce game progresses, making harder.
  • lastenemykilltime (time): time last enemy killed.
  • combopoints (integer): how many points user gets per hit. increase combo extends.
  • points (integer): current score.

so, this:

@interface myclass () {     nstimeinterval _timeout;     nstimeinterval _lastenemykilltime;     bool _combofactor;     nsuinteger _points;  } @end 

i guess sprite kit uses init: method; use initialize variables:

- (id)init {     self = [super init];     if (self != nil) {         _timeout = 1.0;         _lastenemykilltime = 0.0;         _points = 0;         _combopoints = 1;     } } 

the update: method like:

- (void)update:(nstimeinterval)currenttime {     bool withintimeout = currenttime - _lastenemykilltime <= _timeout;     if (cgrectintersectsrect(enemy.frame, player.frame)) {         _incombo = withintimeout;         if (_incombo)             _combopoints *= 2;         _points += _combopoint;         _lastenemykilltime = currenttime;         [enemy removefromparent];     } else if (_combopoints > 1 && !withintimeout) {         _lastenemykilltime = 0.0;         _combopoints = 1;     } } 

Comments