diff options
Diffstat (limited to 'Classes/JumpGameMode.m')
| -rw-r--r-- | Classes/JumpGameMode.m | 46 | 
1 files changed, 30 insertions, 16 deletions
| diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index 3788c97..f3e690c 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m | |||
| @@ -25,7 +25,19 @@ | |||
| 25 | 25 | ||
| 26 | @end | 26 | @end | 
| 27 | 27 | ||
| 28 | // FallingObject flag 0 is whether the object is floating in water | 28 | @implementation FallingObject (Flags) | 
| 29 | |||
| 30 | - (BOOL)fellDuringWave | ||
| 31 | { | ||
| 32 | return flags[0]; | ||
| 33 | } | ||
| 34 | |||
| 35 | - (void)setFellDuringWave:(BOOL)value | ||
| 36 | { | ||
| 37 | flags[0] = value; | ||
| 38 | } | ||
| 39 | |||
| 40 | @end | ||
| 29 | 41 | ||
| 30 | @implementation JumpGameMode | 42 | @implementation JumpGameMode | 
| 31 | 43 | ||
| @@ -141,10 +153,12 @@ static GameModeInfo* info; | |||
| 141 | } | 153 | } | 
| 142 | } | 154 | } | 
| 143 | 155 | ||
| 156 | [ledges minusSet:discardedSet]; | ||
| 157 | |||
| 144 | NSMutableSet* discardedObjects = [NSMutableSet set]; | 158 | NSMutableSet* discardedObjects = [NSMutableSet set]; | 
| 145 | for (FallingObject* object in objects) | 159 | for (FallingObject* object in objects) | 
| 146 | { | 160 | { | 
| 147 | if ((object.sprite.position.y < 86) && (![object flag:0])) | 161 | if (object.sprite.position.y < (64+object.sprite.boundingBox.size.height/2)) | 
| 148 | { | 162 | { | 
| 149 | for (CCSprite* ledge in ledges) | 163 | for (CCSprite* ledge in ledges) | 
| 150 | { | 164 | { | 
| @@ -167,20 +181,14 @@ static GameModeInfo* info; | |||
| 167 | } | 181 | } | 
| 168 | } | 182 | } | 
| 169 | 183 | ||
| 170 | if ((waterTick >= 180) || ((waterTick > 0) && ([object flag:0]))) | 184 | if (object.fellDuringWave) | 
| 171 | { | 185 | { | 
| 172 | object.sprite.position = ccp(object.sprite.position.x, MAX(object.sprite.position.y, water.position.y+80+11)); | 186 | object.sprite.position = ccp(object.sprite.position.x, MAX(object.sprite.position.y, water.position.y+80+11)); | 
| 173 | } else { | 187 | } else { | 
| 174 | object.sprite.position = ccp(object.sprite.position.x-ledgeScrollSpeed, object.sprite.position.y); | 188 | object.sprite.position = ccp(object.sprite.position.x-ledgeScrollSpeed, object.sprite.position.y); | 
| 175 | } | 189 | } | 
| 176 | |||
| 177 | if ((waterTick > 0) && (object.sprite.position.y <= (water.position.y+80+11))) | ||
| 178 | { | ||
| 179 | [object setFlag:0 withValue:YES]; | ||
| 180 | } | ||
| 181 | } | 190 | } | 
| 182 | 191 | ||
| 183 | [ledges minusSet:discardedSet]; | ||
| 184 | [objects minusSet:discardedObjects]; | 192 | [objects minusSet:discardedObjects]; | 
| 185 | 193 | ||
| 186 | if (rightmost <= 480) | 194 | if (rightmost <= 480) | 
| @@ -205,6 +213,9 @@ static GameModeInfo* info; | |||
| 205 | if ((cart.sprite.position.y < 86) && (cart.boundedByScreen)) | 213 | if ((cart.sprite.position.y < 86) && (cart.boundedByScreen)) | 
| 206 | { | 214 | { | 
| 207 | cart.boundedByScreen = NO; | 215 | cart.boundedByScreen = NO; | 
| 216 | } else if ((cart.sprite.position.y >= 86) && (!cart.boundedByScreen)) | ||
| 217 | { | ||
| 218 | cart.boundedByScreen = YES; | ||
| 208 | } | 219 | } | 
| 209 | 220 | ||
| 210 | if (cart.sprite.position.y == (0-cart.sprite.boundingBox.size.height/2)) | 221 | if (cart.sprite.position.y == (0-cart.sprite.boundingBox.size.height/2)) | 
| @@ -300,13 +311,6 @@ static GameModeInfo* info; | |||
| 300 | isGesturing = NO; | 311 | isGesturing = NO; | 
| 301 | } | 312 | } | 
| 302 | 313 | ||
| 303 | - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration | ||
| 304 | { | ||
| 305 | [super accelerometer:accelerometer didAccelerate:acceleration]; | ||
| 306 | |||
| 307 | expectedAngle = acceleration.y*M_PI_2; | ||
| 308 | } | ||
| 309 | |||
| 310 | - (int)cartShouldFall:(Cart *)m_cart | 314 | - (int)cartShouldFall:(Cart *)m_cart | 
| 311 | { | 315 | { | 
| 312 | int bottom = 0-m_cart.sprite.boundingBox.size.height/2; | 316 | int bottom = 0-m_cart.sprite.boundingBox.size.height/2; | 
| @@ -416,6 +420,7 @@ static GameModeInfo* info; | |||
| 416 | object.delegate = self; | 420 | object.delegate = self; | 
| 417 | object.sprite.position = ccp(objectX, 360); | 421 | object.sprite.position = ccp(objectX, 360); | 
| 418 | object.sprite.scale = 1; | 422 | object.sprite.scale = 1; | 
| 423 | object.fellDuringWave = waterTick > 0; | ||
| 419 | [self addChild:object.sprite]; | 424 | [self addChild:object.sprite]; | 
| 420 | 425 | ||
| 421 | [objects addObject:object]; | 426 | [objects addObject:object]; | 
| @@ -450,6 +455,7 @@ static GameModeInfo* info; | |||
| 450 | object.delegate = self; | 455 | object.delegate = self; | 
| 451 | object.sprite.position = ccp(objectX, 360); | 456 | object.sprite.position = ccp(objectX, 360); | 
| 452 | object.sprite.scale = 1; | 457 | object.sprite.scale = 1; | 
| 458 | object.fellDuringWave = waterTick > 0; | ||
| 453 | [self addChild:object.sprite]; | 459 | [self addChild:object.sprite]; | 
| 454 | 460 | ||
| 455 | [objects addObject:object]; | 461 | [objects addObject:object]; | 
| @@ -486,6 +492,7 @@ static GameModeInfo* info; | |||
| 486 | object.delegate = self; | 492 | object.delegate = self; | 
| 487 | object.sprite.position = ccp(objectX, 360); | 493 | object.sprite.position = ccp(objectX, 360); | 
| 488 | object.sprite.scale = 1; | 494 | object.sprite.scale = 1; | 
| 495 | object.fellDuringWave = waterTick > 0; | ||
| 489 | [self addChild:object.sprite]; | 496 | [self addChild:object.sprite]; | 
| 490 | 497 | ||
| 491 | [objects addObject:object]; | 498 | [objects addObject:object]; | 
| @@ -528,6 +535,13 @@ static GameModeInfo* info; | |||
| 528 | } | 535 | } | 
| 529 | } | 536 | } | 
| 530 | 537 | ||
| 538 | - (void)setPitch:(double)m_pitch | ||
| 539 | { | ||
| 540 | [super setPitch:m_pitch]; | ||
| 541 | |||
| 542 | expectedAngle = pitch*M_PI_2; | ||
| 543 | } | ||
| 544 | |||
| 531 | @end | 545 | @end | 
| 532 | 546 | ||
| 533 | @implementation LedgeFactory | 547 | @implementation LedgeFactory | 
