Note that there are some explanatory texts on larger screens.

plurals
  1. POcocos2d fruit ninja parabola math
    primarykey
    data
    text
    <p>i am making a game similar to fruit ninja. birds flying down the water and then up (just like fruits up side down)</p> <p>but some of the birds fly too far and the others too near. can someone check my code? vy should quite close to each other.(vx is not a problem)</p> <pre><code>static float tuna = 10.0f; -(void) reset { float vy = 0.0f; float vx = 0.0f; int sign = 1; if (CCRANDOM_0_1() &gt;= 0.5) { sign = -1; } float hurry = 0.0f; if (CCRANDOM_0_1() &lt;= 0.1) { hurry = 1.0f; } switch (birdType) { case BirdType1: vx = 1.0f * sign + (CCRANDOM_0_1() - 0.5f) * 0.08f; vy = -6.5f; break; case BirdType2: vx = 1.5f * sign + (CCRANDOM_0_1() - 0.5f) * 0.08f; vy = -6.2f + (CCRANDOM_0_1() - 0.5f) * 0.1f; break; case BirdType3: vx = 1.0f * sign + (CCRANDOM_0_1() - 0.5f) * 0.1f; vy = -5.8f - hurry; break; default: [NSException exceptionWithName:@"BirdMoveComponent exception" reason:@"unhandled bird type" userInfo:nil]; break; } velocity = CGPointMake(vx * 5, vy * 5); if ((int)([[GameManager sharedManager] score] / 100) &gt;= prevLevel) { if (tuna &lt;= 12.0f) { tuna += 0.01f; } prevLevel = (int)[[GameManager sharedManager] score] / 100; } } -(void) update:(ccTime) delta { if (self.parent.visible) { NSAssert([self.parent isKindOfClass:[BirdEntity class]], @"node is not an entity"); BirdEntity* bird = (BirdEntity*) self.parent; bird.position = ccpAdd(bird.position, ccpMult(velocity, delta * tuna)); velocity = ccpAdd(velocity, ccpMult(acceleration, delta * tuna)); acceleration = ccp(0, 0.3f); float birdHeight = CGRectGetHeight([bird boundingBox]); //20 is the bottom trap if (bird.position.y &lt;= (birdHeight / 2) + 20) { [bird dieAccidently]; } if (CGRectIntersectsRect([GameScene screenRect], [bird boundingBox]) == NO) { bird.visible = NO; [bird stopAllActions]; [bird unscheduleAllSelectors]; [bird unscheduleUpdate]; [self reset]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload