CollisionDetectionTest/EnemyBullets.c
/* Create a new Enemy Bullet object with the provided data */
Create a new Enemy Bullet object with the provided data
Create a new Enemy Bullet object with the provided data
EnemyBullet* EnemyBullet_Create(Sound *sound, Enemy *enemy, int arc)
{
	EnemyBullet *enemyBullet;
	enemyBullet = (EnemyBullet*)malloc(sizeof(EnemyBullet));
	if (enemyBullet == NULL)
	{
		return NULL; 
	}
	if (enemy->id == 1)
		enemyBullet->direction = 1;
	else enemyBullet->direction = -1;
	enemyBullet->left = enemyBullet->right = 0;
	if (enemy->type == 5)
	{
		enemyBullet->x_Pos = enemy->x_Pos + arc;
		if (arc == 0)
			enemyBullet->left = 1;
		else if (arc == 3)
			enemyBullet->right = 1;
	}
	else
		enemyBullet->x_Pos = enemy->x_Pos + ((rand() % 1) + 1);
	enemyBullet->y_Pos = enemy->y_Pos - enemyBullet->direction;
	enemyBullet->frames = 150;
	enemyBullet->base_timer = 0;
	enemyBullet->timer = enemyBullet->base_timer;
	enemyBullet->pass_through = 0;
	EnemyBullet_Type_Init(enemyBullet, enemy);
	WorldData_GoToXY(enemyBullet->x_Pos, enemyBullet->y_Pos);
	printf("%c", enemyBullet->art);
	if (sound != NULL)
		EnemyFire_SFX(enemy, sound);
	return enemyBullet;
}
EnemyBullet * EnemyBullet_Create ( Sound * sound , Enemy * enemy , int arc ) { EnemyBullet * enemyBullet ; enemyBullet = ( EnemyBullet * ) malloc ( sizeof ( EnemyBullet ) ) ; if ( enemyBullet == NULL ) { return NULL ; } if ( enemy -> id == 1 ) enemyBullet -> direction = 1 ; else enemyBullet -> direction = -1 ; enemyBullet -> left = enemyBullet -> right = 0 ; if ( enemy -> type == 5 ) { enemyBullet -> x_Pos = enemy -> x_Pos + arc ; if ( arc == 0 ) enemyBullet -> left = 1 ; else if ( arc == 3 ) enemyBullet -> right = 1 ; } else enemyBullet -> x_Pos = enemy -> x_Pos + ( ( rand ( ) % 1 ) + 1 ) ; enemyBullet -> y_Pos = enemy -> y_Pos - enemyBullet -> direction ; enemyBullet -> frames = 150 ; enemyBullet -> base_timer = 0 ; enemyBullet -> timer = enemyBullet -> base_timer ; enemyBullet -> pass_through = 0 ; EnemyBullet_Type_Init ( enemyBullet , enemy ) ; WorldData_GoToXY ( enemyBullet -> x_Pos , enemyBullet -> y_Pos ) ; printf ( " " , enemyBullet -> art ) ; if ( sound != NULL ) EnemyFire_SFX ( enemy , sound ) ; return enemyBullet ; }
Create a new Enemy Bullet object with the provided data
Create a new Enemy Bullet object with the provided data
/* the new object to be returned */ /* allocate the memory for a new object */ /* malloc can fail */ /* Sets which direction bullet should travel depending on which player it faces */ /* Bullet should not be moving left or rightwards */ /* ..except for Arc bullets */ /* First bullet created on this x position etc... */ /* First bullet moves left ward */ /* Last bullet moves rightward */ /* Randomise bullet to spawn anywhere between enemy */ /* Randomise bullet to spawn in front of enemy */ /* Updates every 80 frames AT MOST, WILL NOT CHANGE */ /* Adjusts the speed, ex. if increases to 1, takes 1 less frame to update */ /* Timer always starts from base_timer's value */ /* Whether bullet is passing through an enemy and should not be printed, initialised as not passing through anything */ /* Initialises the bullet based on current data */ /* Go to its x and y pos and prints the bullet */ /* Returns the object */