public void changeMode(GhostMode mode) { foreach (IGhost ghost in ghost_list) { ghost.changeMode(mode); } }
void ChargeHandler() { if (Input.GetMouseButton (0)) { if (mode == GhostMode.MouseMove) mode = GhostMode.Preparing; if (mode == GhostMode.Preparing) { if ((transform.position - chainedTransform.position).magnitude > maxDistance/chargePrepareSeconds * Time.deltaTime) transform.position -= (transform.position-chainedTransform.position).normalized * maxDistance/chargePrepareSeconds * Time.deltaTime; else { chargeDirection = (transform.position - chainedTransform.position).normalized; if (chargeDirection == Vector2.zero) chargeDirection = Vector2.right; transform.position = chainedTransform.position; mode = GhostMode.Charging; transform.GetChild(0).localScale = new Vector3(transform.GetChild(0).localScale.x,-(transform.GetChild (0).transform.localScale.y),transform.GetChild(0).localScale.z); chargePowerCurrent = chargePowerMin; targetDir = chargeDirection.normalized; arrow.gameObject.SetActive(true); } } if (mode == GhostMode.Charging){ float newScale = chargingScale + (chargePowerMax-chargePowerCurrent)/chargePowerMax*(originalScale-chargingScale); transform.GetChild(0).transform.localScale = new Vector3(newScale, Mathf.Sign (transform.GetChild(0).transform.localScale.y)*newScale); chargePowerCurrent = Mathf.Min (chargePowerCurrent+Time.deltaTime/chargePowerSeconds*chargePowerMax,chargePowerMax); transform.position = chainedTransform.position; Vector2 mouse = MouseDelta().normalized; if (mouse!= Vector2.zero && mouse != targetDir) targetDir = mouse; chargeDirection = (Vector2)Vector3.RotateTowards((Vector3)chargeDirection,mouse,3*Mathf.PI*Time.deltaTime,0.0f); if (chargeDirection.y > 0) arrow.transform.rotation = Quaternion.Euler (0,0,Vector2.Angle(Vector2.right,chargeDirection)); else arrow.transform.rotation = Quaternion.Euler (0,0,360-Vector2.Angle(Vector2.right,chargeDirection)); } } else { if (mode == GhostMode.Preparing) mode = GhostMode.MouseMove; if (mode == GhostMode.Charging) { mode = GhostMode.Charge; chargePowerCurrent *= maxDistance; arrow.gameObject.SetActive(false); } } if (mode == GhostMode.Charge) { transform.position += (Vector3)chargeDirection * chargePowerCurrent*Time.deltaTime; chargePowerCurrent -= chargePowerDecay * Time.deltaTime; if (chargePowerCurrent <= 0) { chargePowerCurrent = 0; mode = GhostMode.MouseMove; } } }
public Ghost(string colour) : base(START_LOCATION_X, START_LOCATION_Y) { initialiseImageArray(colour); behaviourType = GhostMode.Aggressive; speed = BASE_SPEED; imageToggle = 0; location = new Point(START_LOCATION_X, START_LOCATION_Y); }
// ChangeMode EventHandler private void Mode_Change(object sender, EventArgs e) { mode = mode == GhostMode.Scatter ? GhostMode.Chase : GhostMode.Scatter; ghosts.changeMode(mode); int time; time = mode == GhostMode.Scatter ? _scatter_time_table[_count_changes / 2] : _chase_time_table[_count_changes / 2]; _timer.Interval = new TimeSpan(0, 0, 0, time); _count_changes++; }
// Resets timers public void reset() { mode = GhostMode.Scatter; _count_changes = 0; // _is_frightened = false; int time; time = _scatter_time_table[0]; _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 0, time); _timer.Tick += new EventHandler(Mode_Change); // Frightened timer initialize _timer_frightened = new DispatcherTimer(); _timer_frightened.Interval = new TimeSpan(0, 0, 0, _frightened_time); _timer_frightened.Tick += new EventHandler(Frightened_Off); }
public Ghost(GhostType t) { lastDir.X = 0; lastDir.Y = 0; tex = null; type = t; switch (t) { case GhostType.Blinky: scatterLoc.Y = 0; scatterLoc.X = 26; loc.Y = 116; loc.X = 116; startLoc.Y = 144; startLoc.X = 116; mode = GhostMode.Running; startMode = GhostMode.OutPen; break; case GhostType.Inky: scatterLoc.Y = 35; scatterLoc.X = 26; startLoc.Y = loc.Y = 144; startLoc.X = loc.X = 128; mode = GhostMode.Pen; startMode = GhostMode.Pen; break; case GhostType.Pinky: scatterLoc.Y = 0; scatterLoc.X = 2; startLoc.Y = loc.Y = 144; startLoc.X = loc.X = 116; mode = GhostMode.OutPen; startMode = GhostMode.Pen; break; case GhostType.Clyde: scatterLoc.Y = 35; scatterLoc.X = 0; startLoc.Y = loc.Y = 144; startLoc.X = loc.X = 100; mode = GhostMode.Pen; startMode = GhostMode.Pen; break; } }
public Ghost() { loc.Y = 40; loc.X = 16; lastDir.X = 0; lastDir.Y = 0; tex = null; type = GhostType.Blinky; scatterLoc.Y = 4; scatterLoc.X = 204; mode = GhostMode.Pen; }
public Direction GetDirectionInHouse(Vector2 coordinates, GhostMode mode, Direction dir) { Direction res = dir; try { if (_map[(int)coordinates.Y, (int)coordinates.X] == -2 || mode == GhostMode.OUTGOING && (_map[(int)coordinates.Y, (int)coordinates.X] == -8 || _map[(int)coordinates.Y, (int)coordinates.X] == -6)) { res = Direction.UP; } else if (mode == GhostMode.HOUSE && _map[(int)coordinates.Y, (int)coordinates.X] == -8 || _map[(int)coordinates.Y, (int)coordinates.X] == -4) { res = Direction.DOWN; } else if (mode == GhostMode.OUTGOING && _map[(int)coordinates.Y, (int)coordinates.X] == -3) { res = Direction.RIGHT; } else if (mode == GhostMode.OUTGOING && _map[(int)coordinates.Y, (int)coordinates.X] == -5) { res = Direction.LEFT; } /*else if (mode == GhostMode.HOUSE && ( _map[(int)coordinates.Y, (int)coordinates.X] == -3 || _map[(int)coordinates.Y, (int)coordinates.X] == -5 || _map[(int)coordinates.Y, (int)coordinates.X] == -6 )) { res = dir; }*/ } catch (Exception e) { Console.WriteLine(e.Message); return Direction.UP; } return res; }
// Algorithm to back to start position after pacman eat ghost protected Position eyesMode() { if (pos_logic.x != _default_tile.x || pos_logic.y != _default_tile.y) { SoundEffect.Instance.playAlarm(); return _default_tile; } mode = GhostMode.HouseExit; // Reset speed _speed = _speed_default; _timer_move.Interval = new TimeSpan(0, 0, 0, 0, _speed); SoundEffect.Instance.stopAlarm(); return houseExitMode(); }
// Algorithm to exit ghosts house protected Position houseExitMode() { if(pos_logic.x != _house_exit_tile.x || pos_logic.y != _house_exit_tile.y) return _house_exit_tile; mode = GhostModeControler.Instance.mode; return new Position(_house_exit_tile.x - 1, _house_exit_tile.y); }
// Change mode public void changeMode(GhostMode m) { switch(m) { case GhostMode.Chase: if (mode != GhostMode.House && mode != GhostMode.Eyes && mode != GhostMode.HouseExit) { if (mode == GhostMode.Frightened) { reverseDirection(); _speed = _speed_default; _timer_move.Interval = new TimeSpan(0, 0, 0, 0, _speed); } mode = m; Console.Write(name + " swith to mode: " + m.ToString() + "\n"); } break; case GhostMode.Eyes: if (mode == GhostMode.Frightened) { SoundEffect.Instance.playEatGhost(); SoundEffect.Instance.playAlarm(); // Create label with points int points = 200 * (int)Math.Pow(2, GameControler.Instance.ghosts_eaten - 1); Label label = new Label(); label.Content = points; label.Foreground = new SolidColorBrush(Colors.Gold); label.FontWeight = FontWeights.Bold; Thickness ma = new Thickness(); ma.Left = pos_logic.x * 16 + 16; ma.Top = (pos_logic.y - 2) * 16 - 16; label.Margin = ma; _grid.Children.Add(label); _labelPoints = label; // Init timer which will remove label with points DispatcherTimer timer; timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += new EventHandler(Label_Remove); _timerPoints = timer; timer.Start(); // Speed up ghost _speed = 5; _timer_move.Interval = new TimeSpan(0, 0, 0, 0, _speed); mode = m; Console.Write(name + " swith to mode: " + m.ToString() + "\n"); // Change graphic to eyes _ghost_image[0] = Constants.eyesGhostImg[_direction * 2 - 2]; _ghost_image[1] = Constants.eyesGhostImg[_direction * 2 - 1]; } break; case GhostMode.Frightened: if (mode != GhostMode.Scatter && mode != GhostMode.Chase && mode != GhostMode.Frightened) return; Console.Write(name + " swith to mode: " + m.ToString() + "\n"); if(mode != GhostMode.Frightened) reverseDirection(); mode = m; // Slow down ghost _speed = 50; _timer_move.Interval = new TimeSpan(0, 0, 0, 0, _speed); // Change graphic to frightened _ghost_image[0] = Constants.frightenedGhostImg[0]; _ghost_image[1] = Constants.frightenedGhostImg[1]; break; // case GhostMode.House: // break; case GhostMode.HouseExit: can_exit = true; // Reset speed _speed = _speed_default; _timer_move.Interval = new TimeSpan(0, 0, 0, 0, _speed); mode = m; break; case GhostMode.Scatter: if (mode != GhostMode.House && mode != GhostMode.Eyes) { if (mode == GhostMode.Frightened) { reverseDirection(); _speed = _speed_default; _timer_move.Interval = new TimeSpan(0, 0, 0, 0, _speed); } mode = m; Console.Write(name + " swith to mode: " + m.ToString() + "\n"); } break; } }
void LimitDistance(PushMode push) { float triedDistance = Vector2.Distance ((Vector2)transform.position, (Vector2)chainedTransform.position); if (triedDistance > maxDistance) { Vector3 moveDir = (transform.position - chainedTransform.position).normalized; transform.position = chainedTransform.position + moveDir * maxDistance; if (push != PushMode.None) { if (push == PushMode.Wiggle && graveTransform.GetComponent<Rigidbody2D>().velocity == Vector2.zero) { wiggling = true; } else if (push == PushMode.Drag) { wiggling = false; mode = GhostMode.MouseMove; gm.MoveGrave (push, (Vector2)moveDir * (triedDistance - maxDistance)); }else if (push == PushMode.Charge) { mode = GhostMode.MouseMove; gm.MoveGrave (push, (Vector2)moveDir * chargePowerCurrent); if (chargePowerMax < chargePowerBreak){ chargePowerCurrent = 0.0f; }else{ GetComponent<ChainHandler>().BreakChain(); maxDistance = Mathf.Infinity; } } } } else if (triedDistance < maxDistance - 0.05f) wiggling = false; }
/// <summary> /// Test if pacman clash ghost. /// </summary> /// <returns>True if pacman clash ghost, else return false.</returns> protected bool Clash(out int ghostIndex, out GhostMode mode) { bool isClashed = false; ghostIndex = 0; mode = GhostMode.SCATTER; for (int i = 0; i < _ghosts.Length; ++i) { if (_map.WinToMap(_pacman.Position) == _map.WinToMap(_ghosts[i].Position) && _ghosts[i].Mode != GhostMode.INCOMING) { isClashed = true; ghostIndex = i; mode = _ghosts[i].Mode; } } return isClashed; }
/// <summary> /// Allows ghost to choose a valid direction in the Monster House. /// </summary> private void ThinkInHouse() { Vector2 mapPosition = _map.WinToMap(_position); _direction = _map.GetDirectionInHouse(mapPosition, _mode, _direction); if (_mode == GhostMode.OUTGOING) { if (_map.IsInSpecialZone(mapPosition) == true) { if (_isFrightened) { _mode = GhostMode.FRIGHTENED; } else { Mode = getCurrentMode(); } _direction = Direction.LEFT; _modeChanged = false; _thinkCounter = (int)_map.TileSize.X / 2; } } }
/// <summary> /// Initialize ghost. /// </summary> public override void Initialize() { _nbMovement = 0; _speed = 100; _thinkCounter = 0; _canThink = true; _modeChanged = false; _isFrightened = false; _drawable = true; _drawCounter = 0; _blinkInterval = 16; _mode = GhostMode.HOUSE; targeting(); _modesTime = new int[3, 7] { { 420, 1200, 420, 1200, 300, 1200, 300 }, { 420, 1200, 420, 1200, 300, 61980, 1 }, { 420, 1200, 420, 1200, 300, 62220, 1 } }; _indexCurrentMode = 0; for (int l = 0; l < _modesTime.GetLength(0); ++l) { for (int t = 1; t < _modesTime.GetLength(1); ++t) { _modesTime[l, t] += _modesTime[l, t - 1]; } } _modeCounter = 0; _indexSpeedLevel = 0; _indexModeLevel = 0; if (_level > 1) { ++_indexSpeedLevel; ++_indexModeLevel; } if (_level > 4) { ++_indexSpeedLevel; ++_indexModeLevel; } if (_level > 5) { ++_indexSpeedLevel; } _speedByLevel = new int[4, 3] { {75, 50, 40}, {85, 55, 45}, {95, 60, 50}, {95, 95, 50} }; _elroySpeed = 0; Speed = _speedByLevel[_indexSpeedLevel, (int)GhostSpeed.NORM] + _elroySpeed; _frightModeCounters = new int[] { 6, 5, 4, 3, 2, 5, 2, 2, 1, 5, 2, 1, 1, 3, 1, 1, 1 }; for (int i = 0; i < _frightModeCounters.Length; ++i) { _frightModeCounters[i] *= 60; } _frightModeCounter = 0; _flashesCounters = new int[] { 5, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 3, 3, 5, 3, 3, 3 }; _flashesCounter = 0; _flashOffset = 0; /*for (int i = 0; i < _flashesCounters.Length; ++i) { _flashesCounters[i] = _frightModeCounters[i] - _flashesCounters[i] * ; }*/ }