public void Update(ref Intruder[] intruder, ref ShotSystem shotSystem) { if (target == -1) getTarget(intruder); if (target != -1) { if ((pos - intruder[target].pos).LengthSquared() > 20000 || !intruder[target].alive) { target = -1; getTarget(intruder); } else { if (reloadTimer == 0) { shotSystem.createShot(pos - 70 * Vector2.UnitY, intruder[target].pos, target); reloadTimer = 20; } } } if (reloadTimer > 0) reloadTimer--; }
public void Update(ref Grid grid, Intruder[] intruder, ref ShotSystem shotSystem) { if (target == -1) target = GetNewTarget(ref grid, intruder); if (target != -1 && !intruder[target].alive) target = GetNewTarget(ref grid, intruder); if (progress % 20 == 0 && target != -1 && intruder[target].alive && (pos - intruder[target].pos).LengthSquared() < 10000) shotSystem.createShot(pos - Vector2.One * 20, intruder[target].pos, target); pos = (progress * grid.cells[nextCell].centre + (STEPS_PER_CELL - progress) * grid.cells[prevCell].centre) / (float)STEPS_PER_CELL; if (progress >= STEPS_PER_CELL) if (target != -1 && intruder[target].alive) { if (pathing == GuardPathfinding.Dumb) { float dirToTarget = (float)((Math.Atan2(grid.cells[intruder[target].nextCell].centre.Y - pos.Y, pos.X - grid.cells[intruder[target].nextCell].centre.X) / Math.PI + 1) * 3); int dirToMove = Dir.None; float diff; float minDiff = 7; for (int d = 0; d < 6; d++) { if (grid.cells[nextCell].connections[d].passable) { diff = Math.Abs(d - dirToTarget); if (diff > 3) diff = 6 - diff; if (diff < minDiff) { minDiff = diff; dirToMove = d; } } } if (dirToMove != -1) { int newNextCell = grid.cells[nextCell].connections[dirToMove].targetCell; prevCell = nextCell; nextCell = newNextCell; progress = 0; } } else { grid.CalcGuardPath(nextCell, intruder[target].nextCell); int dir = grid.cells[nextCell].guardWay; if (dir != -1) { prevCell = nextCell; nextCell = grid.cells[nextCell].connections[dir].targetCell; progress = 0; } else { prevCell = nextCell; progress = 10; } } } if (progress < STEPS_PER_CELL) progress++; }