source/doodlejump.c
//---------------------------------------------------------------------------------
//Only if the index is EVEN
Only if the index is EVEN
Only if the index is EVEN
void createPlatformPvp(int index) {
	if(index % 2 == 1) {
		return;	
	}
	platformArrPvp[index].type = NORMAL;
	platformArrPvp[index].animation = 0;
	platformArrPvp[index].dy = 0; 	
	platformArrPvp[index].dx = 0;	
	platformArrPvp[index].speed = (rand() % (PLATFORM_MOVE_SPEED_MAX - PLATFORM_MOVE_SPEED_MIN)) + PLATFORM_MOVE_SPEED_MIN;
	switch(currentGameState) {
		case STATE_NORMAL:
			if(rand() % 3 == 0) {
				platformArrPvp[index].type = SPRING;
			}
			break;	
		case STATE_NORMAL_MOV:
			if(rand() % 2 == 0) {
				if(rand() % 5 == 0) {
					platformArrPvp[index].type = MOVING_VERT;
				} else {
					platformArrPvp[index].type = MOVING_HORIZ;
				}
			}
			break;
		case STATE_NORMAL_BR:
			if(platformArrPvp[index].type != MOVING_HORIZ) {
				 OUT OF non-moving platforms
				if(rand() % 2 == 0) {
					platformArrPvp[index].type = BREAKING;
				}
			}
			break;
		case STATE_GHOST:
			if(rand() % 2 == 0) {
				platformArrPvp[index].type = GHOST;
			} else {
				platformArrPvp[index].type = BREAKING;
			}
			break;
		case STATE_COUNT_VAR:
			break;
	}
	if(rand() % PLATFORM_GOLD_RARITY == 0) {
		platformArrPvp[index].type = GOLD;
	}
	if(platformArrPvp[index].type == MOVING_HORIZ) {
		platformArrPvp[index].x = rand() % (320 - 64 - PLATFORM_MOVE_DISTANCE);  	
		platformArrPvp[index].dx = rand() % PLATFORM_MOVE_DISTANCE;				
		platformArrPvp[index].direction = rand() % 2;								
	} else if(platformArr[index].type == MOVING_VERT) {
		platformArrPvp[index].x = rand() % (320 - 64);  
		platformArrPvp[index].dy = rand() % PLATFORM_MOVE_DISTANCE_VERT;
		platformArrPvp[index].direction = rand() % 2;
	} else {
		platformArrPvp[index].x = rand() % (320 - 64);  
	}
	int minY = 480;
	int i;
	int breaking = 0;
	int moving_vert = 0;
	for(i = 0; i < NUM_PLATFORMS; i++) {
		if(i == index) {
			continue;
		}
		if(platformArrPvp[i].y == 0) {
			continue;
		}
		if(platformArrPvp[i].type == BREAKING) {
			breaking++;
			continue;
		}
		if(platformArrPvp[i].type == MOVING_VERT) {
			moving_vert++;
		}		
		if(platformArrPvp[i].y < minY) {
			minY = platformArrPvp[i].y;
		}
	}
	if(moving_vert == 1 && platformArrPvp[index].type == MOVING_VERT) {
		createPlatformPvp(index);
	}
	if(breaking > (NUM_PLATFORMS / 2) && platformArrPvp[index].type == BREAKING) {
		switch(currentGameState) {
			case STATE_GHOST:
				platformArrPvp[index].type = GHOST;
				break;
			default:
				platformArrPvp[index].type = NORMAL;
				break;
		}
	}
	if(platformArrPvp[index].type == MOVING_VERT) {
		platformArrPvp[index].y = minY - PLAYER_JUMP_HEIGHT - PLATFORM_MOVE_DISTANCE_VERT;
	} else {
		platformArrPvp[index].y = minY - PLAYER_JUMP_HEIGHT;
	}
	platformArrPvp[index + 1].x = platformArrPvp[index].x + 320;
	platformArrPvp[index + 1].y = platformArrPvp[index].y;
	platformArrPvp[index + 1].type = platformArrPvp[index].type;
	platformArrPvp[index + 1].dx = platformArrPvp[index].dx;
	platformArrPvp[index + 1].dy = platformArrPvp[index].dy;
	platformArrPvp[index + 1].direction = platformArrPvp[index].direction;
	platformArrPvp[index + 1].animation = platformArrPvp[index].animation;
	platformArrPvp[index + 1].speed = platformArrPvp[index].speed;
}
void createPlatformPvp ( int index ) { if ( index % 2 == 1 ) { return ; } platformArrPvp [ index ] . type = NORMAL ; platformArrPvp [ index ] . animation = 0 ; platformArrPvp [ index ] . dy = 0 ; platformArrPvp [ index ] . dx = 0 ; platformArrPvp [ index ] . speed = ( rand ( ) % ( PLATFORM_MOVE_SPEED_MAX - PLATFORM_MOVE_SPEED_MIN ) ) + PLATFORM_MOVE_SPEED_MIN ; switch ( currentGameState ) { case STATE_NORMAL : if ( rand ( ) % 3 == 0 ) { platformArrPvp [ index ] . type = SPRING ; } break ; case STATE_NORMAL_MOV : if ( rand ( ) % 2 == 0 ) { if ( rand ( ) % 5 == 0 ) { platformArrPvp [ index ] . type = MOVING_VERT ; } else { platformArrPvp [ index ] . type = MOVING_HORIZ ; } } break ; case STATE_NORMAL_BR : if ( platformArrPvp [ index ] . type != MOVING_HORIZ ) { if ( rand ( ) % 2 == 0 ) { platformArrPvp [ index ] . type = BREAKING ; } } break ; case STATE_GHOST : if ( rand ( ) % 2 == 0 ) { platformArrPvp [ index ] . type = GHOST ; } else { platformArrPvp [ index ] . type = BREAKING ; } break ; case STATE_COUNT_VAR : break ; } if ( rand ( ) % PLATFORM_GOLD_RARITY == 0 ) { platformArrPvp [ index ] . type = GOLD ; } if ( platformArrPvp [ index ] . type == MOVING_HORIZ ) { platformArrPvp [ index ] . x = rand ( ) % ( 320 - 64 - PLATFORM_MOVE_DISTANCE ) ; platformArrPvp [ index ] . dx = rand ( ) % PLATFORM_MOVE_DISTANCE ; platformArrPvp [ index ] . direction = rand ( ) % 2 ; } else if ( platformArr [ index ] . type == MOVING_VERT ) { platformArrPvp [ index ] . x = rand ( ) % ( 320 - 64 ) ; platformArrPvp [ index ] . dy = rand ( ) % PLATFORM_MOVE_DISTANCE_VERT ; platformArrPvp [ index ] . direction = rand ( ) % 2 ; } else { platformArrPvp [ index ] . x = rand ( ) % ( 320 - 64 ) ; } int minY = 480 ; int i ; int breaking = 0 ; int moving_vert = 0 ; for ( i = 0 ; i < NUM_PLATFORMS ; i ++ ) { if ( i == index ) { continue ; } if ( platformArrPvp [ i ] . y == 0 ) { continue ; } if ( platformArrPvp [ i ] . type == BREAKING ) { breaking ++ ; continue ; } if ( platformArrPvp [ i ] . type == MOVING_VERT ) { moving_vert ++ ; } if ( platformArrPvp [ i ] . y < minY ) { minY = platformArrPvp [ i ] . y ; } } if ( moving_vert == 1 && platformArrPvp [ index ] . type == MOVING_VERT ) { createPlatformPvp ( index ) ; } if ( breaking > ( NUM_PLATFORMS / 2 ) && platformArrPvp [ index ] . type == BREAKING ) { switch ( currentGameState ) { case STATE_GHOST : platformArrPvp [ index ] . type = GHOST ; break ; default : platformArrPvp [ index ] . type = NORMAL ; break ; } } if ( platformArrPvp [ index ] . type == MOVING_VERT ) { platformArrPvp [ index ] . y = minY - PLAYER_JUMP_HEIGHT - PLATFORM_MOVE_DISTANCE_VERT ; } else { platformArrPvp [ index ] . y = minY - PLAYER_JUMP_HEIGHT ; } platformArrPvp [ index + 1 ] . x = platformArrPvp [ index ] . x + 320 ; platformArrPvp [ index + 1 ] . y = platformArrPvp [ index ] . y ; platformArrPvp [ index + 1 ] . type = platformArrPvp [ index ] . type ; platformArrPvp [ index + 1 ] . dx = platformArrPvp [ index ] . dx ; platformArrPvp [ index + 1 ] . dy = platformArrPvp [ index ] . dy ; platformArrPvp [ index + 1 ] . direction = platformArrPvp [ index ] . direction ; platformArrPvp [ index + 1 ] . animation = platformArrPvp [ index ] . animation ; platformArrPvp [ index + 1 ] . speed = platformArrPvp [ index ] . speed ; }
Only if the index is EVEN
Only if the index is EVEN
//--------------------------------------------------------------------------------- //ERROR, this event should never occur //reset dy //reset dx	 // 1/2 probability // 1/2 probability OUT OF non-moving platforms //if(score > 3000) //dx and dy are only changed for moving platforms //cannot exceed too far //This value takes into account the size of the platform //Gives platform a random x value (so all generated platforms don't look the same) //Gives platform a random direction //This value takes into account the size of the platform //This value takes into account the size of the platform //Determins y value for this platform to be generated (the type has already been determined here) //Ignore this index, we're writing to this index //If platform is null?, ignore it TODO: Remove this //Ignore breaking platforms, these "don't exist" //Get min value of y. //Re-generate this platform, don't have more than 1 moving vertical one per NUM_PLATFORMS //(Can cause levels to be impossible) //If there is a surplus of breaking platforms, replace it with a normal platform /* Recreate the exact same platform for the next index */