public void UpdatePos(SnakeEngine.Direction newOrientation) { Orientation = newOrientation; switch (Orientation) { case SnakeEngine.Direction.Down: Position.Y += Settings.SquareSize; break; case SnakeEngine.Direction.Left: Position.X -= Settings.SquareSize; break; case SnakeEngine.Direction.Right: Position.X += Settings.SquareSize; break; case SnakeEngine.Direction.Up: Position.Y -= Settings.SquareSize; break; } }
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)); }
// Updates the snakes current direction if it is a valid direction and triggers the MoveTrigger.ResetAndInvoke. public void UpdateDirection(SnakeEngine.Direction newDir) { switch (Direction) { case SnakeEngine.Direction.Down: if (newDir == SnakeEngine.Direction.Left || newDir == SnakeEngine.Direction.Right) { Direction = newDir; MoveTrigger.ResetAndInvoke(); } break; case SnakeEngine.Direction.Up: if (newDir == SnakeEngine.Direction.Left || newDir == SnakeEngine.Direction.Right) { Direction = newDir; MoveTrigger.ResetAndInvoke(); } break; case SnakeEngine.Direction.Left: if (newDir == SnakeEngine.Direction.Up || newDir == SnakeEngine.Direction.Down) { Direction = newDir; MoveTrigger.ResetAndInvoke(); } break; case SnakeEngine.Direction.Right: if (newDir == SnakeEngine.Direction.Up || newDir == SnakeEngine.Direction.Down) { Direction = newDir; MoveTrigger.ResetAndInvoke(); } break; } }
public void UpdatePos(Position p, SnakeEngine.Direction newOrientation) { Position = p; Orientation = newOrientation; }
public SnakeHead(Position position, SnakeEngine.Direction orientation) { Position = position; Orientation = orientation; //FoodType = Food.FoodType.SnakePart; }
public void UpdatePos(SnakeEngine.Direction newOrientation) { // Not used }
public SnakeBody(Position pos, SnakeEngine.Direction orientation) { Position = pos; Orientation = orientation; }