private void ActionRage(UnitAction action, GameTime gameTime) { panicAnimation += (float)gameTime.ElapsedGameTime.TotalSeconds; float damage = (1) * (float)gameTime.ElapsedGameTime.TotalSeconds; {// damage surrounding wall of currentile Tile currTile = ContainingMaze.GetTile(CurrentGrid); Tile targetTile = ContainingMaze.GetTile(Helper.GetFrontOf(CurrentGrid, CurrentFacingDirection)); if (CurrentFacingDirection == Direction.Up) { if (Helper.HasWall(currTile.UpWall)) { DamageWall(currTile, Tile.Up, damage); } if (Helper.HasWall(targetTile.DownWall)) { DamageWall(targetTile, Tile.Down, damage); } if (Helper.HasWall(targetTile.UpWall)) { DamageWall(targetTile, Tile.Up, damage); } } else if (CurrentFacingDirection == Direction.Down) { if (Helper.HasWall(currTile.DownWall)) { DamageWall(currTile, Tile.Down, damage); } if (Helper.HasWall(targetTile.UpWall)) { DamageWall(targetTile, Tile.Up, damage); } if (Helper.HasWall(targetTile.DownWall)) { DamageWall(targetTile, Tile.Down, damage); } } else if (CurrentFacingDirection == Direction.Left) { if (Helper.HasWall(currTile.LeftWall)) { DamageWall(currTile, Tile.Left, damage); } if (Helper.HasWall(targetTile.RightWall)) { DamageWall(targetTile, Tile.Right, damage); } if (Helper.HasWall(targetTile.LeftWall)) { DamageWall(targetTile, Tile.Left, damage); } } else if (CurrentFacingDirection == Direction.Right) { if (Helper.HasWall(currTile.RightWall)) { DamageWall(currTile, Tile.Right, damage); } if (Helper.HasWall(targetTile.LeftWall)) { DamageWall(targetTile, Tile.Left, damage); } if (Helper.HasWall(targetTile.RightWall)) { DamageWall(targetTile, Tile.Right, damage); } } } if (panicAnimation >= 3) { StopExplode(); } }
private void ActionGhost(UnitAction action, GameTime gameTime) { panicAnimation += (float)gameTime.ElapsedGameTime.TotalSeconds; ActionMove(action, gameTime); // delegate movement to move if (CurrentAction == null) // reached destination { EndPanic(); } }
private void ActionMove(UnitAction action, GameTime gameTime) { if (CurrentGrid != TargetGrid) { // for simplicity sake, the movement in this game will only only either be in the x or y direction and never both. Vector2 move = (float)(gameTime.ElapsedGameTime.TotalSeconds) * MovementVector; Position = Position + move; if (move.X != 0) { if (move.X > 0) { if (Position.X > TargetLocation.X) { Position.X = TargetLocation.X; ReachLocation(); } } else { if (Position.X < TargetLocation.X) { Position.X = TargetLocation.X; ReachLocation(); } } } else { if (move.Y > 0) { if (Position.Y > TargetLocation.Y) { Position.Y = TargetLocation.Y; ReachLocation(); } } else { if (Position.Y < TargetLocation.Y) { Position.Y = TargetLocation.Y; ReachLocation(); } } } } else { } }
private void ActionExplode(UnitAction action, GameTime gameTime) { panicAnimation += (float)gameTime.ElapsedGameTime.TotalSeconds; float damage = (1) * (float)gameTime.ElapsedGameTime.TotalSeconds; {// damage surrounding wall of currentile Tile currentTile = ContainingMaze.GetTile(CurrentGrid); if (Helper.HasWall(currentTile.UpWall)) { DamageWall(currentTile, Tile.Up, damage); } if (Helper.HasWall(currentTile.LeftWall)) { DamageWall(currentTile, Tile.Left, damage); } if (Helper.HasWall(currentTile.RightWall)) { DamageWall(currentTile, Tile.Right, damage); } if (Helper.HasWall(currentTile.DownWall)) { DamageWall(currentTile, Tile.Down, damage); } } Tile leftTile = ContainingMaze.GetTile(new Grid(CurrentGrid.Row, CurrentGrid.Col - 1)); if (leftTile != null) { if (Helper.HasWall(leftTile.RightWall)) { DamageWall(leftTile, Tile.Right, damage); } } Tile rightTile = ContainingMaze.GetTile(new Grid(CurrentGrid.Row, CurrentGrid.Col + 1)); if (rightTile != null) { if (Helper.HasWall(rightTile.LeftWall)) { DamageWall(rightTile, Tile.Left, damage); } } Tile upTile = ContainingMaze.GetTile(new Grid(CurrentGrid.Row - 1, CurrentGrid.Col)); if (upTile != null) { if (Helper.HasWall(upTile.DownWall)) { DamageWall(upTile, Tile.Down, damage); } } Tile downTile = ContainingMaze.GetTile(new Grid(CurrentGrid.Row + 1, CurrentGrid.Col)); if (downTile != null) { if (Helper.HasWall(downTile.UpWall)) { DamageWall(downTile, Tile.Up, damage); } } if (panicAnimation >= 3) { StopExplode(); } }
private void ActionDestroyWeakWall(UnitAction action,GameTime gameTime) { Direction d = Helper.GetDirection(this.CurrentGrid, action.TargetGrid); CurrentFacingDirection = d; Grid face = Helper.GetFrontOf(this.CurrentGrid, d); Tile t = ContainingMaze.GetTile(face); float damage = (1) * (float)gameTime.ElapsedGameTime.TotalSeconds; // the (1) is the "damage per sec" done by the unit int targetwall = 0; if (d == Direction.Up) //wall target is down of tile { targetwall = Tile.Down; } else if (d == Direction.Down) { targetwall = Tile.Up; } else if (d == Direction.Left) { targetwall = Tile.Right; } else if (d == Direction.Right) { targetwall = Tile.Left; } // check for destruction first. bool destroyed = false; if (targetwall == Tile.Down) { if (t.DownWall == WallState.Broken || t.DownWall == WallState.None) { destroyed = true; } } else if (targetwall == Tile.Up) { if (t.UpWall == WallState.Broken || t.UpWall == WallState.None) { destroyed = true; } } else if (targetwall == Tile.Left) { if (t.LeftWall == WallState.Broken || t.LeftWall == WallState.None) { destroyed = true; } } else if (targetwall == Tile.Right) { if (t.RightWall == WallState.Broken || t.RightWall == WallState.None) { destroyed = true; } } if (destroyed) { CurrentAction = null; t.WallAnimateTime[targetwall] = 0; } else { if (d == Direction.Up) //wall target is down of tile { t.DownWall = WallState.Breaking; } else if (d == Direction.Down) { t.UpWall = WallState.Breaking; } else if (d == Direction.Left) { t.RightWall = WallState.Breaking; } else if (d == Direction.Right) { t.LeftWall = WallState.Breaking; } DamageWall(t, targetwall,damage); } }
public void GhostTo(UnitAction action) { CurrentAction = action; if (MovementVector != Vector2.Zero) { return; } TargetGrid = action.TargetGrid; TargetLocation = new Vector2(TargetGrid.Col * MazeMaster.TileSize, TargetGrid.Row * MazeMaster.TileSize); MovementVector = (TargetLocation - Position) / 10; MovementVector.Normalize(); MovementVector *= 50 * MazeMaster.ScreenMultiplier; CurrentFacingDirection = Helper.GetDirection(CurrentGrid, TargetGrid); }
// move to the next possible place, protected override UnitAction GetNextAction() { Grid dashTarget = new Grid(); if (CanSeeExit(out dashTarget)) { return new UnitAction(ActionType.Dash, dashTarget); } if (IsPanic) { UnitAction action = new UnitAction(ActionType.Explode, CurrentGrid); return action; } else { bool canFront = false; bool canLeft = false; bool canRight = false; bool canBack = false; Random rng = new Random(); Grid front = Helper.GetFrontOf(CurrentGrid, CurrentFacingDirection); canFront = CanMoveTo(front); // go forward first , provided that I have not visit it yet. if (canFront && !Memories.Contains(front)) { return new UnitAction(ActionType.Move, front); } Grid left = Helper.GetLeftOf(CurrentGrid, CurrentFacingDirection); canLeft = CanMoveTo(left); Grid right = Helper.GetRightOf(CurrentGrid, CurrentFacingDirection); canRight = CanMoveTo(right); Grid back = Helper.GetBackOf(CurrentGrid, CurrentFacingDirection); canBack = CanMoveTo(back); if (canLeft && canRight) { //check if my left is visited && right is not visited, turn right if (Memories.Contains(left) && !Memories.Contains(right)) { return new UnitAction(ActionType.Move, right); } else if (Memories.Contains(right) && !Memories.Contains(left)) { return new UnitAction(ActionType.Move, left); } else if (!Memories.Contains(left) && !Memories.Contains(right)) { int r = rng.Next(0, 2); if (r == 0) { return new UnitAction(ActionType.Move, right); } else { return new UnitAction(ActionType.Move, left); } } } else if (canLeft && !Memories.Contains(left)) { return new UnitAction(ActionType.Move, left); } else if (canRight && !Memories.Contains(right)) { return new UnitAction(ActionType.Move, right); } else if (canBack && !Memories.Contains(back)) { return new UnitAction(ActionType.Move, back); } List<Grid> gridChoice = new List<Grid>(); if (canFront) { gridChoice.Add(front); } if (canLeft) { gridChoice.Add(left); } if (canRight) { gridChoice.Add(right); } if (gridChoice.Count == 0) { if (canBack) { return new UnitAction(ActionType.Move, back); } else { return new UnitAction(ActionType.None, CurrentGrid); } } int rand = rng.Next(0, gridChoice.Count); return new UnitAction(ActionType.Move, gridChoice[rand]); } }
protected override UnitAction GetNextAction() { Grid dashTarget = new Grid(); if (CanSeeExit(out dashTarget)) { return new UnitAction(ActionType.Dash, dashTarget); } if (IsPanic) { UnitAction action = new UnitAction(ActionType.Rage,CurrentGrid); return action; } else { Random rng = new Random(); List<Grid> primaryChoices = new List<Grid>(); Grid front = Helper.GetFrontOf(CurrentGrid, CurrentFacingDirection); bool canFront = CanMoveTo(front); Grid left = Helper.GetLeftOf(CurrentGrid, CurrentFacingDirection); bool canLeft = CanMoveTo(left); Grid right = Helper.GetRightOf(CurrentGrid, CurrentFacingDirection); bool canRight = CanMoveTo(right); Grid back = Helper.GetBackOf(CurrentGrid, CurrentFacingDirection); bool canBack = CanMoveTo(back); if (canFront && !Memories.Contains(front)) { primaryChoices.Add(front); } if (canLeft && !Memories.Contains(left)) { primaryChoices.Add(left); } if (canRight && !Memories.Contains(right)) { primaryChoices.Add(right); } if (primaryChoices.Count != 0) { Grid choice = primaryChoices[rng.Next(0, primaryChoices.Count)]; return new UnitAction(ActionType.Move, choice); } List<Grid> secondaryChoices = new List<Grid>(); if (canFront) { secondaryChoices.Add(front); } if (canLeft) { secondaryChoices.Add(left); } if (canRight) { secondaryChoices.Add(right); } if (secondaryChoices.Count == 0) { if (canBack) { return new UnitAction(ActionType.Move, back); } else { return new UnitAction(ActionType.None, CurrentGrid); } } int rand = rng.Next(0, secondaryChoices.Count); return new UnitAction(ActionType.Move, secondaryChoices[rand]); } }