public void GrowSnake(int growAmount) { for (int i = 0; i < growAmount; i++) { SnakeBody snake = new SnakeBody( new Position(BodyParts.First.Value.Position.X, BodyParts.First.Value.Position.Y), BodyParts.First.Value.Orientation); BodyParts.AddFirst(snake); } }
public event ScoreChangedEvent ScoreChangedEventHandler; // BottomPanel will sub to this event public Snake(int playerNumber, int startingSpeed, Bitmap headTexture, Bitmap bodyTexture, Position startingPosition, SnakeEngine.Direction startingDir, int boardWidth, int boardHeight) { PlayerNumber = playerNumber; BoardWidth = boardWidth; BoardHeight = boardHeight; Score = 0; StartingSpeed = startingSpeed; StartingPosition = startingPosition; Direction = startingDir; // Create the HeadTextures for each direction based on the original bitmap that is facing up. (FACING UP IS IMPORTANT) for (int i = 0; i < 4; i++) { HeadTextures[i] = headTexture.Clone(new Rectangle(0, 0, 16, 16), headTexture.PixelFormat); // RotateFlipType enum is using number 0,1,2,3 for RotateNoneFlip,Rotate90Flip,Rotate180Flip,Rotate270Flip HeadTextures[i].RotateFlip((RotateFlipType)i); } // Same procedure for the bodyparts. for (int i = 0; i < 4; i++) { BodyTextures[i] = bodyTexture.Clone(new Rectangle(0, 0, 16, 16), bodyTexture.PixelFormat); // RotateFlipType enum is using number 0,1,2,3 for RotateNoneFlip,Rotate90Flip,Rotate180Flip,Rotate270Flip BodyTextures[i].RotateFlip((RotateFlipType)i); } MoveTrigger = new Trigger(startingSpeed); MoveTrigger.Triggered += Move; MegaSpeedTrigger = new Trigger(Settings.MegaSpeedDuration); // Will never trigger unless threshold changes MegaSpeedTrigger.Active = false; MegaSpeedTrigger.Triggered += DeactivateHyperDrive; DeathAnimationTrigger = new Trigger(startingSpeed / 3); DeathAnimationTrigger.Triggered += RemoveBodyPart; BodyParts.AddFirst(new SnakeHead(StartingPosition, Direction)); BodyParts.AddFirst(new SnakeBody(new Position(StartingPosition.X + Settings.SquareSize, startingPosition.Y), Direction)); }