public void ExplosionSpawn(MeatSprite oldMeat) { int size = oldMeat.Size + 1; Vector2 oldDirection = oldMeat.direction; Vector2 newSpeed1 = new Vector2(), newSpeed2 = new Vector2(), speed1, speed2; //rotation for the new meat float r = (2 * (float) Math.PI) / 8; newSpeed1.X = (float) (Math.Cos(r) * oldMeat.direction.X) - (float) (Math.Sin(r) * oldMeat.direction.Y); newSpeed1.Y = (float) (Math.Cos(r) * oldMeat.direction.Y) + (float) (Math.Sin(r) * oldMeat.direction.X); Vector2.Multiply(ref newSpeed1, (float)1.4, out speed1); newSpeed2.X = (float) (Math.Cos(-r) * oldMeat.direction.X) - (float) (Math.Sin(-r) * oldMeat.direction.Y); newSpeed2.Y = (float) (Math.Cos(-r) * oldMeat.direction.Y) + (float) (Math.Sin(-r) * oldMeat.direction.X); Vector2.Multiply(ref newSpeed2, (float)1.4, out speed2); if (size == 2 ) { meatList.Add(new MeatSprite(content.Load<Texture2D>(@"images\meat2"), 2, oldMeat.getPosition, new Point(50, 50), 10, new Point(0, 0), new Point(0, 0), speed1)); meatList.Add(new MeatSprite(content.Load<Texture2D>(@"images\meat2"), 2, oldMeat.getPosition, new Point(50, 50), 10, new Point(0, 0), new Point(0, 0), speed2)); } else if (size == 3) { meatList.Add(new MeatSprite(content.Load<Texture2D>(@"images\meat3"), 3, oldMeat.getPosition, new Point(25, 25), 5, new Point(0, 0), new Point(0, 0), speed1)); meatList.Add(new MeatSprite(content.Load<Texture2D>(@"images\meat3"), 3, oldMeat.getPosition, new Point(25, 25), 5, new Point(0, 0), new Point(0, 0), speed2)); } }
public bool CollisionDetect(out MeatSprite oldMeat) { oldMeat = null; for (int i = 0; i < meatList.Count; i++) { //first check if the player is being hit MeatSprite m = meatList[i]; if (m.CollisionRect.Intersects(player.CollisionRect)) { oldMeat = meatList[i]; if (lifeList.Count > 0) { lifeList.RemoveAt(lifeList.Count - 1); explodingList.Add(new ExplodingMeatSprite(content.Load<Texture2D>(@"images\explodingsheet"), new Vector2(m.getPosition.X - 50, m.getPosition.Y - 50), new Point(200, 200), 0, new Point(2, 1), new Point(7, 1), new Vector2(0, 0))); meatList.RemoveAt(i); break; } else return true; } //then check if a fork has hit one of the meat for (int j = 0; j < forkList.Count; j++) { ForkSprite f = forkList[j]; if (m.CollisionRect.Intersects(f.CollisionRect)) { explodingList.Add(new ExplodingMeatSprite(content.Load<Texture2D>(@"images\explodingsheet"), new Vector2(m.getPosition.X - 50, m.getPosition.Y - 50), new Point(200, 200), 0, new Point(2, 1), new Point(7, 1), new Vector2(0, 0))); oldMeat = meatList[i]; meatList.RemoveAt(i); forkList.RemoveAt(j); i--; break; } } //Do the same for the networked player if(isNetworkGame) { if (m.CollisionRect.Intersects(netPlayer.CollisionRect)) { explodingList.Add(new ExplodingMeatSprite(content.Load<Texture2D>(@"images\explodingsheet"), new Vector2(m.getPosition.X - 50, m.getPosition.Y - 50), new Point(200, 200), 0, new Point(2, 1), new Point(7, 1), new Vector2(0, 0))); meatList.RemoveAt(i); break; } for (int j = 0; j < networkForkList.Count; ++j) { ForkSprite f = networkForkList[j]; if(m.CollisionRect.Intersects(f.CollisionRect)) { explodingList.Add(new ExplodingMeatSprite(content.Load<Texture2D>(@"images\explodingsheet"), new Vector2(m.getPosition.X - 50, m.getPosition.Y - 50), new Point(200, 200), 0, new Point(2, 1), new Point(7, 1), new Vector2(0, 0))); meatList.RemoveAt(i); networkForkList.RemoveAt(j); break; } } } } return false; }