/* * This function assigns new information to a new projectile. It takes the bouding box of the * target as its argument. */ ProjectileInformation NewProjectile(RectangleF targetBB, int targetIndex) { //creat a new projectile ProjectileInformation newProjectile = new ProjectileInformation(); //assign all the information to the new projectile newProjectile.x = initialXLocation; newProjectile.y = initialYLocation; newProjectile.boundingBox.Location = new PointF(initialXLocation, initialYLocation); newProjectile.boundingBox.Size = projectileSize; newProjectile.targetInstantX = targetBB.X + targetBB.Width / 2; newProjectile.targetInstantY = targetBB.Y + targetBB.Height / 2; newProjectile.startingX = initialXLocation; newProjectile.startingY = initialYLocation; newProjectile.targetSize = targetBB.Size; if (defenseTowerType == DefenseTowerType.Normal) { newProjectile.image = normalProjectileImage; } else if (defenseTowerType == DefenseTowerType.LongRange) { newProjectile.image = longRangeProjectileImage; } else { newProjectile.image = missileProjectileImage; } newProjectile.targetIndex = targetIndex; //return the new proejctile return(newProjectile); }
/* * This function resizes the projectile list to a certain size. It takes the new size as its argument. */ void ResizeProjectile(int newSize) { //create a copy for the current list ProjectileInformation[] copy = new ProjectileInformation[newSize]; if (newSize > projectiles.Length) { for (int i = HEAD, n = projectiles.Length; i < n; i++) { copy[i] = projectiles[i]; } } else { for (int i = HEAD; i < newSize; i++) { copy[i] = projectiles[i]; } } //resize the original array projectiles = new ProjectileInformation[newSize]; //transfer what's on the copy to the original array for (int i = HEAD; i < newSize; i++) { projectiles[i] = copy[i]; } }