예제 #1
0
        /// <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;
                }
            }
        }
예제 #2
0
        public Ghost(Vector2 pos, string textureName, GhostIdent ident)
        {
            this.TextureName   = textureName;
            this.Position      = pos;
            this.ResetPosition = this.Position;
            this.StartPosition = new Vector2(232f, 232f);
            this.IsAlive       = false;
            this.IsMoving      = false;
            this.ident         = ident;
            this.Score         = new Score(60);
            this.Speed         = Items.Levels[Level.Count].GhostSpeed;
            switch (ident)
            {
            case GhostIdent.Red:
                this.mode      = GhostMode.Scatter;
                this.homeTimer = new Timer(10);
                break;

            case GhostIdent.Pink:
                this.mode      = GhostMode.Home;
                this.homeTimer = new Timer(540);
                break;

            case GhostIdent.Blue:
                this.mode      = GhostMode.Home;
                this.homeTimer = new Timer(360);
                break;

            case GhostIdent.Orange:
                this.mode      = GhostMode.Home;
                this.homeTimer = new Timer(180);
                break;
            }
        }
예제 #3
0
        private void CheckDotContact(Point point)
        {
            if (!Items.DotList.ContainsKey(point) || !Items.DotList[point].IsAlive)
            {
                return;
            }
            Items.DotList[point].IsAlive = false;
            ++this.DotsCounter;
            switch (Items.DotList[point].Size)
            {
            case 0:
                Items.Player.Score += 10;
                break;

            case 1:
                this.IsSpeedUp             = true;
                this.speedUpTime           = Items.Levels[Level.Count].FrightTimeSeconds * 60;
                this.speedUpTimer          = this.speedUpTime;
                this.GhostDestroyedCounter = 0;
                Items.Player.Score        += 50;
                this.previousMode          = this.mode;
                this.mode = GhostMode.Frightened;
                this.ChangeGhostsDirections();
                break;
            }
        }
예제 #4
0
        public IEnumerator FrightenedActions()
        {
            //Debug.Log("Frightening");
            SetGhostColor(frightenedMaterial); // Make it look frightened

            // Make sure scatter is not running
            if (scatterCoroutine != null)
            {
                StopCoroutine(scatterCoroutine);
                scatterCoroutine = null;
            }

            float start = Time.time;

            // Wait until the timer is up
            while (Time.time - start < frightenedTime)
            {
                yield return(null);
            }

            // Go back to normal
            ghostMode = GhostMode.Chase;

            frightenedCoroutine = null;

            SetGhostColor(ghostMaterials[(int)ghostType]);
            yield return(null);
        }
예제 #5
0
    private void Awake()
    {
        _spriteAnimator = GetComponentInChildren <Animator>();

        _player           = GameObject.FindGameObjectWithTag("Player");
        _playerController = _player.GetComponent <PlayerController>();

        // sets the first movement of each ghost to scatter, using the out of bounds tiles
        CurrentGhostMode = GhostMode.Scatter;
        GetScatterTile();

        var nextTile = Helpers.GetIntersectionTile(transform.localPosition);

        if (nextTile != null)
        {
            _currentIntersectionTile = nextTile;
        }

        // only blinky starts outside the ghost house, and moves left first
        // the other 3 ghosts need to leave the ghost house first
        if (IsInGhostHouse)
        {
            _currentMoveDirection   = MoveDirection.Up;
            _targetIntersectionTile = _currentIntersectionTile.UpNeighbor;
        }
        else
        {
            _currentMoveDirection   = MoveDirection.Left;
            _targetIntersectionTile = ChooseNextTile();
        }

        _previousIntersectionTile = _currentIntersectionTile;
        _previousMoveSpeed        = NormalSpeed;
    }
예제 #6
0
 public void changeMode(GhostMode mode)
 {
     foreach (IGhost ghost in ghost_list)
     {
         ghost.changeMode(mode);
     }
 }
예제 #7
0
    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;
            }
        }
    }
예제 #8
0
 void Start()
 {
     mode             = GhostMode.Normal;
     targetWaypoint   = startingPoint;
     direction        = Vector2.up;
     previousWaypoint = startingPoint;
     gameData         = GameObject.Find("GameData").GetComponent <GameData>();
 }
예제 #9
0
    public void ResetState()
    {
        released = false;
        Mode     = GhostManager.Instance.CurrentModeInQueue;
        MovementHandler.ResetState();

        AdditionalResetBehaviour();
    }
 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);
 }
예제 #11
0
 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);
 }
예제 #12
0
    //Sets the ghost mode and reverses movement when previous mode was chase or scatter
    public void SetMode(GhostMode mode)
    {
        if (Mode == GhostMode.Chasing || Mode == GhostMode.Scattering)
        {
            MovementHandler.ShouldReverseMovement = true;
        }

        Mode = mode;
    }
예제 #13
0
 public void Reset()
 {
     this.Position = this.ResetPosition;
     this.mode     = GhostMode.Home;
     this.Speed    = Items.Levels[Level.Count].GhostSpeed;
     this.ResetTimers();
     this.IsAlive  = true;
     this.IsMoving = false;
 }
예제 #14
0
        // 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++;
        }
예제 #15
0
        private void CalculateGhostMode()
        {
            ticksMode++;
            if (modeIntervals.Count() > 0 && ticksMode > modeIntervals.First())
            {
                modeIntervals.RemoveAt(0);
                ticksMode = 0;

                ghostMode = ghostMode == GhostMode.Scatter ? GhostMode.Chase : GhostMode.Scatter;
            }
        }
예제 #16
0
 public Ghost(int x, int y, GamePlan gamePlan, GhostMode mode, int homeTileX, int homeTileY) : base(x, y, gamePlan)
 {
     this.mode            = mode;
     this.startMode       = mode;
     this.startTileX      = x;
     this.startTileY      = y;
     this.homeTileX       = homeTileX;
     this.homeTileY       = homeTileY;
     this.modeLastChanged = TimeSpan.FromSeconds(0);
     this.direction       = new Tuple <int, int>(0, 0);
 }
예제 #17
0
    private void ChangeMode(GhostMode ghostMode)
    {
        if (_currentGhostMode != GhostMode.Scare)
        {
            foreach (BaseGhost ghost in _ghosts)
            {
                ghost.ReceieveCanTurnBack();
            }
        }

        _previousGhostMode = _currentGhostMode;
        _currentGhostMode  = ghostMode;
    }
예제 #18
0
    private void Awake()
    {
        skills = new Dictionary <string, SkillBase>();
        WeirdPill Pill = new WeirdPill();

        skills.Add("SpeedAura", Pill);
        GhostMode ghost = new GhostMode();

        skills.Add("GhostMode", ghost);

        ActiveSpeedSkill active = new ActiveSpeedSkill();

        skills.Add("ActiveSpeedSkill", active);
    }
예제 #19
0
    /// <summary>
    /// Changes the Mode of a Ghost and stores the previous Mode to easy change
    /// </summary>
    /// <param name="mode">The desired mode to change</param>
    private void ChangeGhostMode(GhostMode mode)
    {
        if (CurrentGhostMode == mode)
        {
            return;
        }

        if (CurrentGhostMode != GhostMode.Frightened && CurrentGhostMode != GhostMode.Eaten)
        {
            _previousGhostMode = CurrentGhostMode;
        }

        CurrentGhostMode = mode;
    }
예제 #20
0
    public void MakeGhost()
    {
        // make me invisible for everyone
        this.transform.GetChild(0).GetComponent <MeshRenderer>().enabled = false;

        this.gameObject.tag = "Untagged";
        if (photonView.IsMine) // only disable my controllers for me
        {
            this.GetComponent <CharacterController>().enabled = false;
            this.GetComponent <BunnyController>().enabled     = false;
            GhostMode spectator = this.GetComponent <GhostMode>();
            spectator.ActivateSpectate();
            this.GetComponent <BoxCollider>().enabled = true; // collider for ghost mode

            Camera.main.GetComponent <FollowCam>().pitch_min_max.x = -25f;
        }
    }
예제 #21
0
    //Gets the next target cell based on ghost mode, returns early if release conditions not met
    public Vector3Int GetNextTargetCellPos(Vector3Int previousCellPos, Vector3Int currentCellPos)
    {
        if (PlayerManager.Instance.DotsEaten < dotsBeforeRelease && (SecondsBeforeRelease -= Time.deltaTime) >= 0)
        {
            return(currentCellPos);
        }
        else if (!released)
        {
            SecondsBeforeRelease = 0;

            if (MovementHandler.CurrentCellPos != GhostManager.RedGhostStartCellPos && !LevelManager.Instance.ScrollingMode)
            {
                return(GetNextTargetCellTowardsGoal(GhostManager.RedGhostStartCellPos, currentCellPos, currentCellPos));
            }
            else
            {
                released = true;
            }
        }

        if (Mode == GhostMode.RunningHome && currentCellPos == GhostManager.GhostHomeCenter)
        {
            Mode = GhostMode.Chasing;
        }

        switch (Mode)
        {
        case GhostMode.Chasing:
            return(GetNextTargetCellTowardsGoal(GetGoalCell(), previousCellPos, currentCellPos));

        case GhostMode.Scattering:
            return(GetNextTargetCellTowardsGoal(scatterGoalCellPos, previousCellPos, currentCellPos));

        case GhostMode.Frightened:
        case GhostMode.Exiting:
            var candidatePositions = GetCandidateCellTargets(previousCellPos, currentCellPos).Select(tuple => tuple.Pos).ToList();
            return(candidatePositions[Random.Range(0, candidatePositions.Count)]);

        case GhostMode.RunningHome:
            return(GetNextTargetCellTowardsGoal(GhostManager.GhostHomeCenter, previousCellPos, currentCellPos));

        case GhostMode.Idle:
        default:
            return(currentCellPos);
        }
    }
예제 #22
0
        public void Die()
        {
            // Set it back to chasing (after it "respawns")
            ghostMode = GhostMode.Chase;

            // Make sure it isn't moving anymore
            if (frightenedCoroutine != null)
            {
                StopCoroutine(frightenedCoroutine);
            }
            frightenedCoroutine = null;

            // Set it back to its original color
            SetGhostColor(ghostMaterials[(int)ghostType]);

            // Send it home to start over again
            movement.WarpToLocation(spawnLocation);
        }
예제 #23
0
        // 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);
        }
예제 #24
0
        /// <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);
        }
예제 #25
0
    public void ReadyForStart()
    {
        _currentGhostMode  = GhostMode.Scatter;
        _previousGhostMode = GhostMode.Scatter;

        _receiveTurnBackCount = 0;

        _scatterModeEndCount    = 0;
        _scatterModeResetTime   = 7f;
        _currentScatterModeTime = 0.0f;

        _chaseModeResetTime   = 20.0f;
        _currentChaseModeTime = 0.0f;

        _scareModeResetTime   = 7.0f;
        _currentScareModeTime = 0.0f;

        _isStartWhiteMode = false;
    }
예제 #26
0
    public void OnEnable()
    {
        Node node = GetNodeAtPosition(transform.position);

        if (node != null)
        {
            CurrentNode  = node;
            PreviousNode = CurrentNode;
        }


        Scatter1 = 7;
        Scatter2 = 7;
        Scatter3 = 5;
        Scatter4 = 5;

        Chase1    = 20;
        Chase2    = 20;
        Chase3    = 20;
        Chase4    = 20;
        Direction = Vector3.zero;
        speed     = 0f;

        this.GetComponent <Animator>().enabled       = true;
        this.GetComponent <SpriteRenderer>().enabled = true;
        Frighted.SetActive(false);
        GetComponent <Ghost>().GetComponent <CircleCollider2D>().enabled = true;
        if (ghostMode == GhostMode.Die)
        {
            this.transform.position = StartObject.transform.position;
            CurrentNode             = SCurrentNode;
            PreviousNode            = SPreviousNode;
            MoveToNode = SMoveToNode;
            CheckingGoastTypeAfterDie();
        }
        else
        {
            CheckingGoastType();
        }

        ghostMode = GhostMode.Chase;
    }
예제 #27
0
        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);
        }
예제 #28
0
        public override void CalculateDirection()
        {
            if ((mode == GhostMode.Chase || mode == GhostMode.Scatter) && mode != Game.ghostMode)
            {
                nextDirection = DirectionHelper.Opposite(direction);
                mode          = Game.ghostMode;
            }
            else
            {
                double d = 0;
                if (nodeFrom.neighbors[direction] != null)
                {
                    d = Helper.CalculateDistance(nodeFrom.x, nodeFrom.y, nodeFrom.neighbors[direction].node.x, nodeFrom.neighbors[direction].node.y);
                }

                if (Math.Abs(distance - d) < speed)
                {
                    CalculateTarget();
                    double minDistance = -1;

                    Node baseNode = nodeFrom;
                    if (baseNode.neighbors[direction] != null)
                    {
                        baseNode = baseNode.neighbors[direction].node;
                    }
                    foreach (Direction key in baseNode.neighbors.Keys)
                    {
                        if (baseNode.neighbors[key] != null)
                        {
                            double distanceBetween = Helper.CalculateDistance(baseNode.neighbors[key].node.x, baseNode.neighbors[key].node.y, targetX, targetY);
                            if ((distanceBetween < minDistance || minDistance == -1) && !DirectionHelper.IsOpposite(direction, key))
                            {
                                minDistance   = distanceBetween;
                                nextDirection = key;
                            }
                        }
                    }
                }
            }
        }
예제 #29
0
        public IEnumerator ScatterActions()
        {
            // Ensure the ghost is not frightened
            if (frightenedCoroutine != null)
            {
                StopCoroutine(frightenedCoroutine);
                scatterCoroutine = null;
            }
            yield return(null);

            float start = Time.time;

            // Scatter for the duration
            while (Time.time - start < scatterTime)
            {
                yield return(null);
            }

            // Go back to normal
            ghostMode = GhostMode.Chase;
            yield return(null);
        }
예제 #30
0
    private void CheckMode()
    {
        // if ghost is frightened, check time to change them back to normal and reset multiplier
        if (mode == GhostMode.Frightened)
        {
            TimeSpan time = DateTime.Now - scaredStartingTime;
            if (time.Seconds >= scaredDuration)
            {
                gameData.ResetMultiplier();
                mode = GhostMode.Normal;
            }
        }

        // // if ghost is scattered, check time to change them back to normal
        if (mode == GhostMode.Scatter)
        {
            TimeSpan time = DateTime.Now - scatterStartingTime;
            if (time.Seconds >= scatterDuration)
            {
                mode = GhostMode.Normal;
            }
        }
    }
예제 #31
0
파일: Ghost.cs 프로젝트: prShadoko/Pacman
        /// <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] * ;
            }*/
        }
예제 #32
0
파일: Ghost.cs 프로젝트: prShadoko/Pacman
        /// <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;
                }
            }
        }
예제 #33
0
        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;
        }
예제 #34
0
        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;
            }
        }
예제 #35
0
        // 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();
        }
예제 #36
0
 private void Caught()
 {
     Debug.Log("发现玩家");
     ghostMode = GhostMode.pursuing;
 }
예제 #37
0
 // if ghosts become scatter, they will move to their starting position, it is the element at index 0 in their waypoints list
 public void BecomeScatter()
 {
     mode = GhostMode.Scatter;
     scatterStartingTime = DateTime.Now;
     cur = 0;
 }
예제 #38
0
 // 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);
 }
예제 #39
0
    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;
    }
예제 #40
0
        public override void Update(GameTime gameTime)
        {
            this.current = Keyboard.GetState();
            if (PacmanGame.GameState == GameState.Game)
            {
                if (this.IsReload & !this.IsGameOver)
                {
                    this.DisableGhosts();
                    this.ready.IsAlive = true;
                    if (this.ready.IsAlive)
                    {
                        this.ready.Update();
                    }
                    if (!this.IsAlive & this.ready.IsAlive)
                    {
                        this.Reset();
                        this.IsAlive = true;
                        this.IsReset = true;
                        --Items.Player.Lives;
                    }
                    if (this.ready.Timer.IsFinished)
                    {
                        this.IsReady  = true;
                        this.IsReload = false;
                        this.ready.Timer.Reset();
                        this.ready.IsAlive = false;
                    }
                }
                if (!this.IsAlive)
                {
                    return;
                }
                if (this.IsReady && !this.GhostModeTimer.IsFinished)
                {
                    switch (this.GhostModeTimer.Count)
                    {
                    case 0:
                    case 1620:
                    case 3240:
                    case 4740:
                        this.mode = GhostMode.Scatter;
                        break;

                    case 420:
                    case 2040:
                    case 3540:
                        this.mode = GhostMode.Chase;
                        break;

                    case 5040:
                        this.mode = GhostMode.Chase;
                        this.GhostModeTimer.IsFinished = true;
                        break;
                    }
                    this.GhostModeTimer.Update();
                }
                if (this.current.IsKeyDown(Keys.Up) & this.IsReady)
                {
                    Point map = Serve.WorldToMap(new Vector2(this.Position.X, this.Position.Y + 7f));
                    if (PacmanGame.Map.IsOpenLocation(map.X, map.Y - 1))
                    {
                        this.Direction   = 270;
                        this.Position.Y -= this.Speed;
                        this.Position.X  = this.SnaptoX(this.Position);
                        this.CheckDotContact(map);
                        this.CheckBonusContact(map);
                        this.CheckGhostContact(map);
                    }
                }
                if (this.current.IsKeyDown(Keys.Down) & this.IsReady)
                {
                    Point map = Serve.WorldToMap(new Vector2(this.Position.X, this.Position.Y - 7f));
                    if (PacmanGame.Map.IsOpenLocation(map.X, map.Y + 1))
                    {
                        this.Direction   = 90;
                        this.Position.Y += this.Speed;
                        this.Position.X  = this.SnaptoX(this.Position);
                        this.CheckDotContact(map);
                        this.CheckBonusContact(map);
                        this.CheckGhostContact(map);
                    }
                }
                if (this.current.IsKeyDown(Keys.Left) & this.IsReady)
                {
                    Point map = Serve.WorldToMap(new Vector2(this.Position.X + 7f, this.Position.Y));
                    if (PacmanGame.Map.IsOpenLocation(map.X - 1, map.Y))
                    {
                        this.Direction   = 180;
                        this.Position.X -= this.Speed;
                        this.Position.Y  = this.SnaptoY(this.Position);
                        this.CheckDotContact(map);
                        this.CheckBonusContact(map);
                        this.CheckGhostContact(map);
                        if (PacmanGame.Map.IsInTunnel & map.X == -1)
                        {
                            this.Position.X = 445f;
                        }
                    }
                }
                if (this.current.IsKeyDown(Keys.Right) & this.IsReady)
                {
                    Point map = Serve.WorldToMap(new Vector2(this.Position.X - 7f, this.Position.Y));
                    if (PacmanGame.Map.IsOpenLocation(map.X + 1, map.Y))
                    {
                        this.Direction   = 0;
                        this.Position.X += this.Speed;
                        this.Position.Y  = this.SnaptoY(this.Position);
                        this.CheckDotContact(map);
                        this.CheckBonusContact(map);
                        this.CheckGhostContact(map);
                        if (PacmanGame.Map.IsInTunnel & map.X == 29)
                        {
                            this.Position.X = -1f;
                        }
                    }
                }
                if (this.IsSpeedUp)
                {
                    if (this.speedUpTime > 0)
                    {
                        --this.speedUpTime;
                    }
                    else
                    {
                        this.IsSpeedUp = false;
                        this.mode      = this.previousMode;
                    }
                }
                if (this.DotsCounter == 50 & !this.Dots50Eat)
                {
                    Items.Bonus.Timer.Reset();
                    Items.Bonus.IsAlive = true;
                    this.Dots50Eat      = true;
                }
                if (this.DotsCounter == 150 & !this.Dots150Eat)
                {
                    Items.Bonus.Timer.Reset();
                    Items.Bonus.IsAlive = true;
                    this.Dots150Eat     = true;
                }
                if (this.DotsCounter == 244)
                {
                    this.IsReady = false;
                    Items.InterMission.IsAlive = true;
                }
                this.pacmanAnimation.Position  = this.Position;
                this.pacmanAnimation.Direction = (float)this.Direction;
                this.pacmanAnimation.Update(gameTime);
            }
            this.previous = this.current;
            base.Update(gameTime);
        }
예제 #41
0
        // 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;
            }
        }
예제 #42
0
 public void SetGhostMode(GhostMode mode)
 {
     ghostMode = mode;
 }
예제 #43
0
        /// <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;
        }
예제 #44
0
 public void BecomeScared()
 {
     mode = GhostMode.Frightened;
     scaredStartingTime = DateTime.Now;
 }
예제 #45
0
파일: Map.cs 프로젝트: prShadoko/Pacman
        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;
        }