/// <summary> /// Progress the snake's head forward. /// </summary> /// <param name="level">The current level.</param> private void moveHead(LevelType level) { PortalType portal; //If the snake is in a portal, check to see if it can teleport if (level.tryGetPortal(head.Vector, out portal)) { //If the snake's orientation is the same as the portal's, teleport. if (head.Orientation == portal.Entrance) { portal.teleport(); } //Else clear the portal and move the snake normally else { portal.clearPortal(); head.Vector += MovementFunctions.calculateLocation(Orientation); } } //If the snake is in a normal square, move normally else { head.Vector += MovementFunctions.calculateLocation(Orientation); } }
private void movement(FoodType food, LevelType level) { PortalType portal; //If the food is in a portal, clear the portal if (level.tryGetPortal(food.Vector, out portal)) { portal.clearGrid(level); } //Else empty the old grid cell else { level.Grid.GetCell(food.Vector).emptyCell(); } //Add the movement vector to the current mouse vector Vector2 newLocation = food.Vector + MovementFunctions.calculateLocation(orientation); if (level.tryGetPortal(newLocation, out portal)) { if (!portal.IsFull) { food.Vector = newLocation; portal.fillPortal(food); } } else if (level.Grid.GetCell(newLocation).content == CellContent.empty) { food.Vector = newLocation; } food.fillGrid(level); }
/// <summary> /// This function returns the content of the cell the snake is attempting to move to. /// </summary> /// <param name="grid">The game grid that contains all object data for the level.</param> /// <returns>Returns the content of the cell the snake will move into. Depending on this, the game will respond /// differently, i.e. if there is a wall, the game wil go to game over.</returns> private CellContent collision(LevelType level) { Vector2 newLocation = MovementFunctions.calculateLocation(Orientation) + Vector; try { return(level.Grid.GetCell(newLocation).content); } catch { return(CellContent.portal); } }
/// <summary> /// Acts as the food item's draw method, but instead of drawing straight to the screen, it fills the level's grid /// with its texture, which is drawn when the grid is drawn. /// </summary> /// <param name="grid">The level's grid.</param> public void fillGrid(LevelType level) { rotation = MovementFunctions.calculateRotation(ai.Orientation); PortalType portal; if (level.tryGetPortal(vector, out portal)) { portal.fillGrid(level); } fill(level.Grid); }
/// <summary> /// Turns the snake based on the input from the user. /// </summary> /// <param name="i">The game's input handler</param> private void turn(InputHandlerComponent i) { //The new orientation of the snake OrientationType newOrientation = head.Orientation; //Get the new orientation based on the input if (i.getButton("Right", true) && head.Orientation != OrientationType.left) { newOrientation = OrientationType.right; } else if (i.getButton("Up", true) && head.Orientation != OrientationType.down) { newOrientation = OrientationType.up; } else if (i.getButton("Down", true) && head.Orientation != OrientationType.up) { newOrientation = OrientationType.down; } else if (i.getButton("Left", true) && head.Orientation != OrientationType.right) { newOrientation = OrientationType.left; } //If there has been a change in the orientation, add a curve and change the snake if (newOrientation != head.Orientation) { CurveType curve = new CurveType(); curve.deepCopy(temp); curve.Vector = head.Vector; curve.Orientation = newOrientation; curve.Rotation = MovementFunctions.calculateCurveRotation(head.Orientation, newOrientation); curves.Add(curve.Vector, curve); head.Orientation = newOrientation; canTurn = false; } }
public virtual void fillGrid(GameGrid grid, Color color) { float rotation = MovementFunctions.calculateRotation(orientation); grid.GetCell(vector).fillCell(CellContent.snake, texture, rotation, color); }
/// <summary> /// Initializes the food item's AI agent and the rotation of the food item. /// </summary> public void initialize() { ai.initialize(); rotation = MovementFunctions.calculateRotation(ai.Orientation); }