// check for snake collisions bool CheckSnakeCollisions(ContinuousSnake testSnake) { foreach (ContinuousSnake snake in snakes) { // run self collision code on the snake if the snakes are the same if (snake == testSnake) { if (snake.SelfCollision()) { return(true); // if snake collided with itself, the snake definetly collided } } else { foreach (BodySegment segment in snake.bodySegments) // check for collision with all body segments of other snakes { if ((testSnake.Collided(segment.picBox) & ContinuousSnake.HEAD_COLLISION) != 0) { return(true); // snake head collided with another snake so return true } } } } // if the function reached this point, not collision occured return(false); }
void CheckFollowerCollision(ContinuousSnake snake) // kill snake whos head collides with enemy { foreach (EnemyFollower enemy in followers) { if ((snake.Collided(enemy.picBox) & ContinuousSnake.HEAD_COLLISION) != 0) // kill the snake if head collision { Death(snake); } } }
// check for projectile collision with snake void CheckProjectileCollision(ContinuousSnake snake) { foreach (Projectile projectile in projectiles) { if (projectile.finalized) { continue; // don't check the projectile if its finalized } // only kill the snake if it collides with the snake head if ((snake.Collided(projectile.picBox) & ContinuousSnake.HEAD_COLLISION) != 0) { Death(snake); } } }
void foodCollision(ContinuousSnake snake) { // check for collision with food for (int i = 0; i < foodItems.Count; i++) { // retrieve current food item Food food = foodItems[i]; if ((snake.Collided(food.picBox) & ContinuousSnake.HEAD_COLLISION) != 0) // check for head collision { snake.ChangeSize(food.Change); // change snake size depending on food // delete the food item food.finalize(); foodItems.Remove(food); // subtract one from i to stop from skipping food items i--; } } }
// run mysterbox handler void RunMysteryBoxes(ContinuousSnake snake) { List <MysteryBox> removeQueue = new List <MysteryBox>(); foreach (MysteryBox box in mysteryBoxes) // check all boxes for collision { if (snake.Collided(box.picBox) != 0) { box.Invoke(snake); // run the box's function if collided } if (box.Finalized) { removeQueue.Add(box); } } foreach (MysteryBox box in removeQueue) { mysteryBoxes.Remove(box); } RunMysterySpawners(); }
// check for body collision with snake public bool BodyCollision(ContinuousSnake snake) { return((snake.Collided(Bounds) & ContinuousSnake.BODY_COLLISION) > 0); // true if body collision occurred }
// check for head collisions with snake public bool HeadCollision(ContinuousSnake snake) { return((snake.Collided(Bounds) & ContinuousSnake.HEAD_COLLISION) > 0); // true if head collision occurred }