public bool isCollision(ref Bullet bullet, Smile currSmile) { float deltaX = bullet.Position.X - currSmile.Position.X; float deltaY = bullet.Position.Y - currSmile.Position.Y; double r = Math.Sqrt(deltaX * deltaX + deltaY * deltaY); if (r <= sizeOfSmile) { double k = sizeOfSmile / r; float newX = currSmile.Position.X * (1 - (float)k) + bullet.Position.X * (float)k; float newY = currSmile.Position.Y * (1 - (float)k) + bullet.Position.Y * (float)k; bullet.Position = new Vector2(newX, newY); bullet.Rectangle = new Rectangle((int)newX, (int)newY, bullet.Rectangle.Width, bullet.Rectangle.Height); return true; } return false; }
public bool isImposition(Bullet bullet, Smile currSmile) { int deltaX = (int)Math.Abs(bullet.Position.X - currSmile.Position.X); int deltaY = (int)Math.Abs(bullet.Position.Y - currSmile.Position.Y); if (Math.Sqrt(deltaX * deltaX + deltaY * deltaY) <= sizeOfSmile / 2 + sizeOfSmile / 4) return true; return false; }
public static void newGame() { setConstants(); amountOfShot = 0; smile = new Smile(); lifeBonus = new LifeBonus(); choiceBonus = new ChoiceBonus(); sightBonus = new SightBonus(); for (int i = 0; i < maxNumInRow; i++) for (int j = 0; j < maxNumInCol; j++) { if (smile.Create(i, j)) ; else if (heartIsAvailable && lifeBonus.Create(i, j)); else if (sightIsAvailable && choiceBonus.Create(i, j)); else if (palmIsAvailable && sightBonus.Create(i, j)); } bullet = new Bullet(); bullet.Create(); nextBullet = new Bullet(); nextBullet.Create(); nextBullet.Position = new Vector2(140, ScreenSize.Y - sizeOfSmile - 20); }