示例#1
0
    GameObject FindClosestUnkissed()
    {
        GameObject nearestTarget = null;
        float closestDistance = Mathf.Infinity;
        Vector3 currentPosition = transform.position;

        //add switch statement that checks which room ghost is in then changes furniture options
        foreach(GameObject potentialTarget in rg.currentFurniture)
        {
            if (potentialTarget.GetComponent<KissableFurniture>())
            {
                Vector3 directionToTarget = potentialTarget.transform.position - currentPosition;
                float dSqrToTarget = directionToTarget.sqrMagnitude;
                if (dSqrToTarget < closestDistance && potentialTarget.GetComponent<KissableFurniture>().isKissed == false)
                {
                    closestDistance = dSqrToTarget;
                    nearestTarget = potentialTarget;
                }
                if (directionToTarget == Vector3.zero)
                {
                    currentState = GhostState.Kiss;
                }
            }
        }
        return nearestTarget;
    }
示例#2
0
	void Start () {

        audioSource = GetComponentInParent<AudioSource>();
        audioSource.volume = lowVolume;

        state = GhostState.Wander;
        agent = transform.parent.GetComponent<NavMeshAgent>();
        agent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;
        SetNewDestination();
    }
示例#3
0
    private void ChangeState(GhostState newState)
    {
        if(newState == GhostState.Pursue)
        {
            state = GhostState.Pursue;
            agent.destination = controller.mainCharacter.transform.position;
            audioSource.volume = highVolume;

        } else if(newState == GhostState.Wander)
        {
            state = GhostState.Wander;
            SetNewDestination();
            audioSource.volume = lowVolume;
        }
    }
示例#4
0
        public Human(Model m, Vector3 Position, Tank tank, int speed)
            : base(m)
        {
            ghostState = GhostState.IDLE;
            this.position = Position;
            this.targetTank = tank;
            this.maxSpeed = speed;

            currentVelocity = Vector3.Normalize(new Vector3(0, 0, 1));

            //RandomPatrolPoint();
            translation = Matrix.CreateTranslation(position);
            //behavious[0] = Flee;
            behavious = new Behavious[2];
        }
示例#5
0
    void NextTarget()
    {
        if (state != GhostState.eyes)
        {
            xz xz = passable[Random.Range(0, passable.Count)];
            targetObj.transform.position = controller.Xz2Coord(xz.x, xz.z);
        }
        else
        {
            if (transform.position.x > 0)
            {
                targetObj.transform.position = new Vector3(0.5f, 0, 4);
            }
            else
            {
                targetObj.transform.position = new Vector3(-0.5f, 0, 4);
            }

            trials = 0;

            if (Vector3.Distance(transform.position, targetObj.transform.position) < 2)
            {
                state = GhostState.gohome;
            }
            else
            {
                switch (trials)
                {
                case 0:
                    targetObj.transform.position = new Vector3(1, 0, 4);
                    break;

                default:
                    targetObj.transform.position = new Vector3(0, 0, 4);
                    break;
                }
                trials++;
            }
        }
        ChaseTarget();
    }
示例#6
0
        public Ghost(Texture2D spritesheet, GhostName name, int xPos, int yPos, GhostState startState) : base(spritesheet, 8, 8, xPos, yPos)
        {
            _name              = name;
            _scatterElapsed    = 0.0f;
            _chaseElapsed      = 0.0f;
            _frightenedElapsed = 0.0f;

            _cagedLength  = 1.5f;
            _cagedElapsed = 0.0f;

            _blinkLength = 0.4f;
            _numBlinks   = 4;

            _homeXPixel = -1;
            _homeYPixel = -1;

            _startPosX  = xPos;
            _startPosY  = yPos;
            _startState = startState;
            State       = startState;
        }
示例#7
0
 /// <summary>
 /// Animation that moves the Ghost outside of the spawn
 /// </summary>
 private void LeaveSpawn()
 {
     timer++;
     if (x > 51 && timer < 40)
     {
         return;
     }
     if (x < 51 || x > 51)
     {
         x = x > 51 ? x - 1 : x + 1;
     }
     else if (y > 17)
     {
         y--;
     }
     else
     {
         state = GhostState.SearchPacMan;
         timer = ghostNumber > 2 ? 0 : timer;
     }
 }
示例#8
0
    private void Move()
    {
        if (currentState == GhostState.Waiting)
        {
            return;
        }

        var speed = (currentState == GhostState.Consumed) ? modeManager.consumedStateSpeed :
                    (hasBeenEaten && !modeManager.WaitingForConsumption)? modeManager.normalSpeed : modeManager.movSpeed;
        Vector3 newPosition = gameManager.GetNewEntityPosition(speed, transform.position, currentDirection);

        if (levelManager.ReachedTargetTile(entityId, newPosition, currentDirection))
        {
            if ((currentState == GhostState.LeavingBox || currentState == GhostState.Consumed) && levelManager.ReachedBoxDoorEntrance(entityId))
            {
                isInBox = (currentState == GhostState.Consumed);
            }

            if (currentState == GhostState.Consumed && levelManager.ReachedTile(entityId, consumedBoxTile))
            {
                _animator.SetBool(_animatorEatenId, false);
                if (modeManager.currentMode == ModeManager.Mode.Frightened)
                {
                    gameManager.PlayFrightenedModeMelody();
                }
                currentState = GhostState.LeavingBox;
                hasBeenEaten = true;
            }

            levelManager.UpdateTargetTile(entityId, currentDirection);
            var chosenDirection = ChooseNewDirection();
            transform.position = gameManager.GetValidatedPosition(entityId, newPosition, currentDirection, chosenDirection);
            currentDirection   = chosenDirection;
            _animator.SetInteger(_animatorDirectionId, (int)currentDirection);
        }
        else
        {
            transform.position = newPosition;
        }
    }
示例#9
0
        /// <summary>
        /// Changes the state of a ghost
        /// </summary>
        /// <param name="state">The state in which the ghost is changed to</param>
        public void ChangeState(GhostState state)
        {
            this.CurrentState = state;
            switch (state)
            {
            case GhostState.Scared:
                currentState = new Scared(this, this.maze);
                break;

            case GhostState.Chase:
                switch (Name)
                {
                case GhostName.Blinky:
                    this.currentState = new Chase(this, maze, pacman);
                    break;

                case GhostName.Speedy:
                    this.currentState = new Ambush(this, maze, pacman);
                    break;

                case GhostName.Inky:
                    this.currentState = new Predict(this, GhostAssistant, maze, pacman);
                    break;

                case GhostName.Clyde:
                    this.currentState = new Proximity(this, maze, pacman);
                    break;
                }
                break;

            case GhostState.Released:
                position = ReleasePosition;
                ChangeState(GhostState.Chase);
                break;

            case GhostState.Zombie:
                currentState = new Zombie(this, this.maze, pen.Entrance);
                break;
            }
        }
示例#10
0
 /// <summary>
 /// Check for collisions againts PacMan
 /// </summary>
 private void CheckCollision()
 {
     if ((x >= pacman.X && x <= pacman.X + 4 && y == pacman.Y) ||
         (x + 4 >= pacman.X && x + 4 <= pacman.X + 4 && y == pacman.Y) ||
         (x == pacman.X && y <= pacman.Y && y >= pacman.Y + 2) ||
         (x == pacman.X && y + 2 >= pacman.Y && y <= pacman.Y + 2))
     {
         if (isVulnerable)
         {
             timer          = 0;
             isVulnerable   = false;
             pacman.Points += 1500;
             IsDead         = true;
             state          = GhostState.ReturnToSpawn;
         }
         else
         {
             pacman.IsDead = true;
             pacman.Respawn();
         }
     }
 }
示例#11
0
    public List <Vector3> GetAllowedDirs(GhostState state, Vector3 direction)
    {
        List <Vector3> res = new List <Vector3>();

        if (up && (Vector3.forward != -direction))
        {
            res.Add(Vector3.forward);
        }
        if (left && (Vector3.left != -direction))
        {
            res.Add(Vector3.left);
        }
        if (down && (Vector3.back != -direction))
        {
            res.Add(Vector3.back);
        }
        if (right && (Vector3.right != -direction))
        {
            res.Add(Vector3.right);
        }

        if (isHouseNode)
        {
            if (state != GhostState.Dead && !pacman.Dead)
            {
                res.Remove(Vector3.back);
            }
        }

        if (isSpecialNode)
        {
            if (state == GhostState.Dead || state == GhostState.Frightened)
            {
                res.Add(Vector3.forward);
            }
        }

        return(res);
    }
示例#12
0
        /// <summary>
        /// Returns the Ghost to spawn
        /// </summary>
        private void ReturnToSpawn()
        {
            if (IsDead)
            {
                BackToNormal();
                IsDead = false;

                x = 51;
                y = 21;
            }
            else if (!IsDead)
            {
                timer++;
                // Animate the Ghosts currently trapped in the spawn to move from side to side
                Move();
                if (timer > 140)
                {
                    state = GhostState.LeavingSpawn;
                    timer = 0;
                }
            }
        }
示例#13
0
        public void ObserverUpdate(Object sender, Object message)
        {
            if (message is PacManState)
            {
                PacManState p = (PacManState)message;
                gameConsole.GameConsoleWrite(this + " notified " + p + " from " + sender);
                if (p == PacManState.Dying)
                {
                    this.State = GhostState.Roving;
                }
            }
            if (message is string)
            {
                string strMessage = (string)message;
                switch (strMessage)
                {
                case "PowerUP":
                    this.Evade();
                    break;

                case "PowerUP Elapsed":
                    this.ghostState = GhostState.Roving;
                    break;

                case "Alive":
                    if (this.Intersects(pacMan))
                    {
                        while (this.Intersects(pacMan))
                        {
                            gameConsole.GameConsoleWrite(this + " relocated ");
                            this.Location = this.GetRandLocation();
                            this.SetTranformAndRect();
                        }
                    }
                    break;
                }
            }
        }
示例#14
0
文件: Ghost.cs 项目: Firellon/LD48
        private void Update()
        {
            if (isDead)
            {
                if (timeToDie > 0f)
                {
                    timeToDie -= Time.deltaTime;
                }
                else
                {
                    Destroy(gameObject);
                }
                return;
            }
            // Reduce amount of expensive calls
            if (Random.value > 0.9f)
            {
                state = GetCurrentState();
            }

            switch (state)
            {
            case GhostState.Idle:
                Idle();
                break;

            case GhostState.Attack:
                Attack();
                break;

            case GhostState.Flee:
                Flee();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#15
0
    //From IObservable messages from PacMan
    public void ObserverUpdate(object sender, object message)
    {
        if (sender is PacMan)
        {
            if (message is string)
            {
                //TODO should be subclassed to avoid using Debug.Log in non unity specific class
                this.Log(string.Format("{0} recieved message from {1} : {2}", this, sender, message));
                switch (message.ToString())
                {
                case "SuperPacMan":
                    this.state = GhostState.Evading;
                    break;

                case "SuperPacMan End":
                    this.state = GhostState.Roving;
                    break;
                }
            }
            if (message is PacManState)
            {
                switch ((PacManState)message)
                {
                case PacManState.SuperPacMan:
                    break;

                case PacManState.Spawning:
                    break;

                case PacManState.Chomping:
                    break;

                case PacManState.Still:
                    break;
                }
            }
        }
    }
示例#16
0
    private void RestartLevel()
    {
        _pacman.Initialize();

        for (int i = 0; i < _ghosts.Length; i++)
        {
            _ghosts[i].Initialize();
            _ghostTiles[i] = _board.GetTile(_ghosts[i].transform.position);
        }

        _permaChase        = false;
        _ongoingFright     = false;
        _currentAlternance = 0;
        CurrentGhostState  = GhostState.Scatter;

        _textMessage.gameObject.SetActive(true);
        _textMessage.text = _LEVEL_START;
        _levelStartTime   = Time.time;
        _levelStarted     = false;

        _timesinceLastBonus = 0;
        _board.BonusTile.Collectable.gameObject.SetActive(false);
    }
示例#17
0
    public void Reset()
    {
        state = GhostState.ready;

        switch (tag)
        {
        case "Blinky":
            transform.position = new Vector3(0, 0, 4);
            break;

        case "Inky":
            transform.position = new Vector3(-1.5f, 0, 1);
            break;

        case "Pinky":
            transform.position = new Vector3(0, 0, 1);
            break;

        case "Clyde":
            transform.position = new Vector3(1.5f, 0, 1);
            break;
        }
    }
示例#18
0
    public void _on_AnimatedSprite_animation_finished()
    {
        if (_movement == Vector2.Zero && IsOnFloor())
        {
            _state = GhostState.Walking;
        }

        else if (IsOnFloor())
        {
            _state = GhostState.Walking;
        }

        if (_state == GhostState.Attacking)
        {
            _state = GhostState.Walking;
        }

        if (_state == GhostState.Dead || _animationState == GhostAnimationState.Death)
        {
            EmitSignal(nameof(GhostKilled));

            QueueFree();
        }
    }
示例#19
0
        /// <summary>
        /// The method ChangeState  take an Enum type GhostState and change
        /// the state of our current ghost depending the state given.
        /// Also, if we switch to scare mode a timer is activated and the ghosts are feared
        /// for 9 seconds.
        /// </summary>
        /// <param name="state">state is an Enum that represent the new state that we gonna give to our ghost</param>
        public void ChangeState(GhostState state)
        {
            switch (state)
            {
            case GhostState.Chase:
                this.state   = GhostState.Chase;
                currentState = new Chase(this, maze, pacman, pacman.Position);
                break;

            case GhostState.Scared:
                this.state      = GhostState.Scared;
                currentState    = new Scared(this, maze);
                scared.Interval = 7000;
                scared.Enabled  = true;
                scared.Elapsed += UpdateState;
                break;

            case GhostState.Released:
                this.state    = GhostState.Chase;
                currentState  = new Chase(this, maze, pacman, pacman.Position);
                this.Position = ReleasedPos;
                break;
            }
        }
示例#20
0
        /// <summary>
        /// Changes the state of the ghost to scared/released/chase, depending on the parameter.
        /// </summary>
        /// <param name="stateParam">The state we want to set the ghost into</param>
        public void ChangeState(GhostState stateParam)
        {
            if (stateParam == GhostState.Scared)
            {
                currentState       = new Scared(this, maze);
                colour             = Color.White;
                scaredTime.Enabled = false;
                scaredTime.Enabled = true;
            }
            else if (stateParam == GhostState.Chase)
            {
                currentState = new Chase(this, maze, pacman, target);
                colour       = originalClr;
            }
            else if (stateParam == GhostState.Released)
            {
                currentState  = new Chase(this, maze, pacman, target);
                this.Position = Ghost.releasedPosition;
                colour        = originalClr;
                stateParam    = GhostState.Chase;
            }

            CurrentState = stateParam;
        }
示例#21
0
 /// <summary>
 /// Constructor of the class Ghost
 /// </summary>
 /// <param name="x"> The wanted X position </param>
 /// <param name="y"> the wanted Y position </param>
 /// <param name="allMapPieces"> The List of all Physics Objects</param>
 public Ghost(int x, int y, List <Object> allMapPieces, int cX, int cY,
              char visual, int value = 0)
 {
     // Creates a new Position vector and assigns it the x and y value
     Pos = new Position(x, y);
     // Creates a new Position and assigns it the x value -1 and y value
     OldPos = new Position(x - 1, y);
     // Assigns a character to be displayed while rendering
     Visuals = visual;
     // Creates the collider bounding box
     BoxCollider = new int[4] {
         x, y, x + 1, y + 1
     };
     // Assigns this Object list the one passed as argument
     allPieces = allMapPieces;
     // Assigns the ghost state to chase mode
     state = GhostState.chase;
     // Assigns the ghost it's respective corner
     corner = new DefaultObject(cX, cY, ' ', ObjectType.target);
     // Assigns the type to Ghost
     ObjType = ObjectType.ghost;
     // Sets the score it should give
     ScoreVal = value;
 }
示例#22
0
    void Kiss()
    {
        if (kissCooldown > 0)
        {
            furnToKiss.GetComponent<KissableFurniture>().KissFurniture();

            int chanceToWander = Random.Range(1, 4);

            if (chanceToWander != 3)
            {
                currentState = GhostState.Find;
            }
            else
            {
                currentState = GhostState.Wander;
                rand = Random.Range(1, 3);
                waypoint = Random.insideUnitCircle * 25;
            }
            kissCooldown--;
        }
        else
        {
            currentState = GhostState.Wander;
            rand = Random.Range(1, 3);
        }
    }
示例#23
0
 private void SetState(GhostState state)
 {
     _state = state;
       TargetSpeed = 4;
       switch (state)
       {
     case GhostState.Scatter: _stateCountDown.Start(_scatterTime); break;
     case GhostState.Chase: _stateCountDown.Start(_chaseTime); break;
     case GhostState.Frightened:
       _stateCountDown.Start(_frightendTime);
       if (Maze.IsCellOpen(this, GetOppositeDirection()))
       {
     CurrentDirection = GetOppositeDirection();
       }
       TargetSpeed = 2;
       break;
     case GhostState.Recovering:
       _stateCountDown.Start(_warnTime);
       TargetSpeed = 2;
       break;
     case GhostState.Dead:
       if (Maze.IsCellOpen(this, GetOppositeDirection()))
       {
     CurrentDirection = GetOppositeDirection();
       }
       break;
       }
       SetCharacterAnimation();
 }
示例#24
0
 public void SetGhostState(GhostState gs)
 {
     ghostState = gs;
     onGhostStateChange.Invoke(ghostState);
 }
示例#25
0
        private void StateEval()
        {
            GhostState initialState = State;

            scheduleStateEval_ = false;

            switch (State)
            {
            case GhostState.Home:
                // Ghost exit the home state for the scatter state when they get to the row
                // above the home
                if (position_.Tile.Y == 11 && position_.DeltaPixel.Y == 0)
                {
                    // Select inital direction based on scatter tiles
                    if (Constants.scatterTiles(identity_)[0].X < 13)
                    {
                        direction_ = Direction.Left;
                    }
                    else
                    {
                        direction_ = Direction.Right;
                    }
                    if (scatterModesLeft_ > 0)
                    {
                        State = GhostState.Scatter;
                    }
                    else
                    {
                        State = GhostState.Attack;
                    }
                    return;
                }
                // Ghosts move up when they are aligned with the entrance
                else if (position_.Tile.X == 13 && position_.DeltaPixel.X == 8)
                {
                    direction_ = Direction.Up;
                }
                // When on one side, move towards middle when on the bottom and time's up
                // If time's not up, keep bouncing up and down
                else if ((position_.DeltaPixel.Y == 8) &&
                         ((position_.Tile.X == 11 && position_.DeltaPixel.X == 8) ||
                          (position_.Tile.X == 15 && position_.DeltaPixel.X == 8)))
                {
                    if (position_.Tile.Y == 14)
                    {
                        initialJumps_--;
                        if (initialJumps_ == 0)
                        {
                            if (position_.Tile.X == 11)
                            {
                                direction_ = Direction.Right;
                            }
                            else
                            {
                                direction_ = Direction.Left;
                            }
                        }
                        else
                        {
                            direction_ = Direction.Up;
                        }
                    }
                    else if (position_.Tile.Y == 13)
                    {
                        direction_ = Direction.Down;
                    }
                }
                break;

            case GhostState.Scatter:
                // Attempt to reverse direction upon entering this state
                if (previousState_ == GhostState.Attack)
                {
                    scatterModesLeft_--;
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                AIScatter();
                int timeInScatterMode = scatterModesLeft_ <= 2 ? 5 : 7;
                if ((DateTime.Now - timeInCurrentState) > TimeSpan.FromSeconds(timeInScatterMode))
                {
                    State = GhostState.Attack;
                }
                break;

            case GhostState.Dead:
                // Attempt to reverse direction upon entering this state
                if (previousState_ != GhostState.Dead && previousState_ != GhostState.Blue)
                {
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                else
                {
                    AIDead();
                }
                if (position_.DeltaPixel.X == 8 && position_.DeltaPixel.Y == 8)
                {
                    if (position_.Tile.Y == 14)
                    {
                        State = GhostState.Home;
                    }
                }
                break;

            case GhostState.Attack:
                // Attempt to reverse direction upon entering this state
                if (previousState_ != GhostState.Attack && previousState_ != GhostState.Blue)
                {
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                else
                {
                    AIAttack();
                }

                if ((DateTime.Now - timeInCurrentState) > TimeSpan.FromSeconds(20))
                {
                    State = GhostState.Scatter;
                }
                break;

            case GhostState.Blue:
                // Attempt to reverse direction upon entering this state
                if (previousState_ != GhostState.Blue)
                {
                    if (NextTile(OppositeDirection(direction_)).IsOpen)
                    {
                        direction_ = OppositeDirection(direction_);
                    }
                }
                else
                {
                    // TODO : make special blue AI
                    AIAttack();
                }

                // When blue time is over, revert to attack mode.
                if ((DateTime.Now - timeInCurrentState) > TimeSpan.FromSeconds(Constants.BlueTime()))
                {
                    State = GhostState.Attack;
                }
                break;
            }

            // TODO : move all these magic numbers to the Constants class.
            // We select a new sound only upon some state change, or when
            // the number of crumps goes below certain thresholds.
            if ((initialState != previousState_) ||
                (Grid.NumCrumps == 199 && previousNumCrumps_ == 200) ||
                (Grid.NumCrumps == 19 && previousNumCrumps_ == 20))
            {
                PlaySound();
            }
            previousState_ = initialState;
        }
    private void FixedUpdate()
    {
        timer += Time.deltaTime;
        switch (m_GhostState)
        {
        case GhostState.Chase:
            animator.Play("ghost-Idle", 0);    //we can set an animation
            targetPosition.x = player.transform.position.x;
            targetPosition.y = player.transform.position.y;


            break;

        case GhostState.Attack:
            animator.Play("ghost-Attack", 0);    //we can set an animation
            targetPosition.x = player.transform.position.x;
            targetPosition.y = player.transform.position.y;

            break;

        case GhostState.Spawning:
            animator.Play("ghost-Spawn", 0);    //we can set an animation
            if (timer > animationTimeDelay)
            {
                timer = 0f;
                //batAudio.clip = batFlyingClip;
                //batAudio.Play();
                m_GhostState = GhostState.Chase;
                GetComponent <Enemy>().active = true;
            }

            break;

        case GhostState.Despawning:
            animator.Play("ghost-despawn", 0);    //we can set an animation
            if (timer > animationTimeDelay)
            {
                m_GhostState = GhostState.Inactive;
                GetComponent <Enemy>().active = false;
                timer = 0f;
            }

            break;

        case GhostState.Inactive:
            transform.position = new Vector3(transform.position.x, transform.position.y, -100);
            if (timer > 8f)
            {
                transform.position = new Vector3(transform.position.x, transform.position.y, 1);
                m_GhostState       = GhostState.Spawning;
                timer = 0f;
            }

            break;
        }//end switch


        playerLocation = player.transform.position;

        direction = rigBody.velocity;


        if (targetPosition.x > transform.position.x + 0.1)
        {
            direction.x = 1 * speed;
        }
        else if (targetPosition.x < transform.position.x - 0.1)
        {
            direction.x = -1 * speed;
        }
        else
        {
            direction.x = 0;
        }

        if (targetPosition.y > transform.position.y + 0.1)
        {
            direction.y = 1 * speed;
        }
        else if (targetPosition.y < transform.position.y - 0.1)
        {
            direction.y = -1 * speed;
        }
        else
        {
            direction.y = 0;
        }
        rigBody.velocity = direction;
    }
示例#27
0
    void Wander()
    {
        timer -= Time.deltaTime;
        if(timer <= 0)
        {
            kissCooldown = 3;
            currentState = GhostState.Find;
            timer = 3;
        }

        switch(rand)
        {
            case 1:
                transform.position = Vector3.MoveTowards(transform.position, RandomVector(), ghostSpeed * Time.deltaTime);
                break;
            case 2:
                transform.position = Vector3.MoveTowards(transform.position, closestPlayer.transform.position, ghostSpeed * Time.deltaTime);
                break;
            case 3:
                transform.position = Vector3.MoveTowards(transform.position, furnToKiss.transform.position, ghostSpeed * Time.deltaTime);
                break;
        }

        if(this.transform.position == randomVec)
        {
            randomVec = Vector3.zero;
        }
    }
示例#28
0
 public void Evade()
 {
     this.ghostState = GhostState.Evading;
 }
示例#29
0
 public void TakeDamage(Vector2 pos)
 {
     FSoundManager.PlaySound("enemyHurt");
     Go.killAllTweensWithTarget(this);
     this.health--;
     if (health > 0)
         State = GhostState.INVULNERABLE;
     else
         State = GhostState.DYING;
     Vector2 dist = (this.GetPosition() - pos).normalized * 4;
     maxVel = 50;
     xVel = dist.x;
     yVel = dist.y;
     xAcc = 0;
     yAcc = 0;
 }
示例#30
0
 public virtual void Hit()
 {
     this.ghoststate = GhostState.Dead;
 }
示例#31
0
 public Ghost()
 {
     this.State = GhostState.Roving;
     //pac.Attach(this);
 }
示例#32
0
 //Ghost class is dependant on the PacMan class
 public Ghost(PacMan pac)
 {
     this.State = GhostState.Roving;
 }
示例#33
0
    public override void OnFixedUpdate()
    {
        if (C.isTransitioning)
            return;
        if (State == GhostState.MOVING)
        {

            if (RXRandom.Float() < .2f)
                SpawnParticles();
        }
        else
        {
            if (RXRandom.Float() < .01f)
                SpawnParticles();
        }
        switch (State)
        {
            case GhostState.IDLE:
            case GhostState.MOVING:
                if (stateCount > minState)
                {
                    if (RXRandom.Float() < .03f)
                    {
                        switch (State)
                        {
                            case GhostState.IDLE:

                                float randAngle = RXRandom.Float() * Mathf.PI * 2.0f;
                                if (RXRandom.Float() < .5f)
                                    randAngle = Mathf.Atan2(this.y - world.player.y, this.x - world.player.x);
                                xAcc = Mathf.Cos(randAngle) * -moveSpeed;
                                yAcc = Mathf.Sin(randAngle) * -moveSpeed;
                                State = GhostState.MOVING;
                                break;
                            case GhostState.MOVING:
                                if (RXRandom.Float() < .3f)
                                {
                                    //stop
                                    State = GhostState.IDLE;
                                    PlayAnim(true);
                                    xAcc = 0;
                                    yAcc = 0;

                                }
                                else
                                {

                                }
                                break;
                        }

                    }
                }
                if (State == GhostState.MOVING)
                {
                    if (hitUp)
                        yAcc = -Mathf.Abs(yAcc);
                    else if (hitDown)
                        yAcc = Mathf.Abs(yAcc);
                    if (hitLeft)
                        xAcc = Mathf.Abs(xAcc);
                    else if (hitRight)
                        xAcc = -Mathf.Abs(xAcc);
                }
                if (xAcc == 0)
                    xVel *= .8f;
                if (yAcc == 0)
                    yVel *= .8f;
                break;
            case GhostState.INVULNERABLE:

                if (RXRandom.Float() < .2f)
                    SpawnParticles(1);
                this.isVisible = stateCount * 100 % 10 < 5;
                if (stateCount > invulnerableCount)
                {
                    State = GhostState.IDLE;

                    resetMax();
                    this.isVisible = true;
                }
                this.xVel *= .9f;
                this.yVel *= .9f;
                break;
            case GhostState.DYING:
                if (RXRandom.Float() < .4f + .4f * stateCount)
                    SpawnParticles(1 + (int)stateCount);
                this.isVisible = stateCount * 100 % 10 < 5;
                if (stateCount > invulnerableCount)
                {
                    if (!String.IsNullOrEmpty(name))
                        C.Save.requiredEnemyKills.Add(this.name);
                    FSoundManager.PlaySound("enemyDie");
                    if (RXRandom.Float() < Knight.HEART_DROP_CHANCE)
                        world.addObject(new Heart(world, this.GetPosition()));
                    SpawnParticles(25);
                    world.removeObject(this);

                }
                this.xVel *= .9f;
                this.yVel *= .9f;
                break;
        }
        base.OnFixedUpdate();
        PlayAnim();
    }
示例#34
0
        public override void Update(GameTime gameTime)
        {
            float distance = (targetTank.CurrentPosition - this.position).Length();

            if (distance < fleeDistance)
                {
                ghostCondition = GhostConditions.PLAYERNEAR;
            }
            else if (distance > 160&& distance < 700)
                    {
                ghostCondition = GhostConditions.PLAYERFAR;
            }
            else
                    {
                ghostCondition = GhostConditions.PLAYERTOOFAR;
                    }

            foreach (XElement state in states.Elements())
            {
                foreach (XElement changestate in state.Elements())
                {
                    if(state.Attribute("fromState").Value == ghostState.ToString())
                    {
                        if (changestate.Attribute("condition").Value==ghostCondition.ToString())
                        {
                            string toState = changestate.Attribute("toState").Value;
                            if(toState== GhostState.IDLE.ToString())
                            {
                                ghostState = GhostState.IDLE;

                            }
                            else if (toState == GhostState.PURSUE.ToString())
                    {
                                ghostState = GhostState.PURSUE;

                    }
                            else if (toState == GhostState.FLEE.ToString())
                    {
                                ghostState = GhostState.FLEE;

                            }

                        }
                    }
                    }

                }

            if (ghostState == GhostState.IDLE)
            {
                IDLE(gameTime);
            }
            if (ghostState == GhostState.PURSUE)
            {
                Pursue(gameTime);
            }

            if (ghostState == GhostState.FLEE)
            {
                Flee(gameTime);
            }

            //tankPosition = tank1.CurrentPosition;
            //direction = tankPosition - world.Translation;
            //direction.Normalize();

            //if (this.CollidesWith(tank1.model, tank1.world))
            //{

            //}
            //else
            //{
            //    Vector3 path = direction * speed;
            //    world *= Matrix.CreateTranslation(path);
            //}

            base.Update(gameTime);
        }
示例#35
0
 public void ResetTurning()
 {
     isPlaying       = false;
     ghostModelState = GhostState.Ridable;
 }
示例#36
0
文件: Ghost.cs 项目: prog76/Pacman
        public void setState(GhostState newState)
        {
            if (newState.isEye())
            {
                // état demandé : yeux avec déplacement yeux
                State = GhostState.EYE;
                strategy = Strategy.EYE;
            }
            else if (newState.isFlee())
            {
                // état demandé : fuite
                if (!State.isEye())
                {
                    // fuit seulement si pas en état yeux
                    fleeTime = Constants.TIME_FLEE;
                    blink = false;
                    if (!strategy.isHouse())
                    {
                        strategy = Strategy.FLEE;
                        _DesiredDirection = CurrentDirection;
                        CurrentDirection = CurrentDirection.Opposite;
                    }
                    State = GhostState.FLEE;
                }
            }
                else if (newState.isRest())
                {
                    fleeTime = Constants.TIME_REST;
                    strategy = Strategy.FLEE;

                    _DesiredDirection = CurrentDirection;
                    CurrentDirection = CurrentDirection.Opposite;
                    State = GhostState.REST;
                }
                else if (newState.isHouse())
                {
                    // état demandé : chasse avec déplacement maison
                    strategy = Strategy.HOUSE;
                    houseTime = color * Constants.TIME_HOUSE;
                    State = GhostState.HOUSE;
                }
                else if (newState.isHunt())
                {
                    // état demandé : chasse avec déplacement chasse
                    strategy = Strategy.HUNT;
                    State = GhostState.HUNT;
                }
                else if (newState.isRandom())
                {
                    // état demandé : chasse avec déplacement aléatoire
                    strategy = Strategy.RANDOM;
                    randomTime = Constants.TIME_RANDOM_OFFSET + color * Constants.TIME_RANDOM_K;
                    State = GhostState.HUNT;
                }
        }
示例#37
0
 void Start()
 {
     noDamage_script  = gameObject.GetComponent <Invincibility>();
     ghostStateScript = gameObject.GetComponent <GhostState>();
 }
示例#38
0
        /// <summary>
        /// Updates the ghost, applying movement and physics
        /// </summary>
        /// <param name="gameTime">The GameTime object</param>
        public void Update(GameTime gameTime)
        {
            if (animationState == GhostState.WalkingLeft)
            {
                Position.X -= speed;

                if (Position.X - 16 < 0)
                {
                    Position.X     = 16;
                    animationState = GhostState.WalkingRight;
                }
            }
            else if (animationState == GhostState.WalkingRight)
            {
                Position.X += speed;
                origin      = new Vector2(10, 20);
                if (Position.X + 20 > 2100)
                {
                    Position.X     = 2080;
                    animationState = GhostState.WalkingLeft;
                }
            }

            /*
             * if (Bounds.CollidesWith(player.Bounds)) // check for collisions with the player
             * {
             *  player.gameState = 2;
             *  /*
             *  if (player.Bounds.Y + player.Bounds.Height <= Bounds.Y)
             *  {
             *      //logic player bouncing off head, but ghost wont be dying, can bounce off ghost heads
             *      player.Position.Y -= 1;
             *      player.playerBounce = 1;
             *  }
             *  else if (player.Bounds.X >= Bounds.X + Bounds.Width) //&& player.Bounds.Y > Bounds.Y
             *  {
             *      //logic for player death
             *      player.gameState = 2;
             *  }
             *  else if (player.Bounds.X + player.Bounds.Width <= Bounds.X) //&& player.Bounds.Y > Bounds.Y - 18
             *  {
             *      //logic for player death
             *      player.gameState = 2;
             *  }
             *
             * }
             */



            switch (animationState)
            {
            case GhostState.WalkingLeft:
                animationTimer += gameTime.ElapsedGameTime;
                spriteEffects   = SpriteEffects.None;
                // Walking frames are 0 & 1
                if (animationTimer.TotalMilliseconds > (FRAME_RATE * 2 - (FRAME_RATE * 0.05)))       //this slight adjustment fixes the issue of seeing a small blip of frame 11 pop up
                {
                    animationTimer = new TimeSpan(0);
                }
                currentFrame = (int)animationTimer.TotalMilliseconds / FRAME_RATE;
                break;

            case GhostState.WalkingRight:
                animationTimer += gameTime.ElapsedGameTime;
                spriteEffects   = SpriteEffects.FlipHorizontally;
                // Walking frames are 0 & 1
                if (animationTimer.TotalMilliseconds > (FRAME_RATE * 2 - (FRAME_RATE * 0.05)))       //this slight adjustment fixes the issue of seeing a small blip of frame 11 pop up
                {
                    animationTimer = new TimeSpan(0);
                }
                currentFrame = (int)animationTimer.TotalMilliseconds / FRAME_RATE;
                break;
            }
        }
示例#39
0
 public virtual void Chase()
 {
     this.ghoststate = GhostState.Chasing;
 }
示例#40
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            float turnAmount = .04f;

            switch (this.ghostState)
            {
            case GhostState.Dead:

                //TODO Dead moving and dead animation.
                //Until then
                this.ghostState = GhostState.Roving;
                //Pick random direction
                Random  r = new Random();
                Vector2 v = new Vector2((float)r.NextDouble() - 0.5f, (float)r.NextDouble() - 0.5f);
                Vector2.Normalize(ref v, out v);        //Normalize
                this.Direction = v;                     //Assign random direction

                break;

            case GhostState.Chasing:
                //Change texture if Chasing
                if (!(this.spriteTexture == this.ghost))
                {
                    //gameConsole.GameConsoleWrite(this.ToString() + " Chasing changed texture to spriteTexture");
                    this.spriteTexture = this.ghost;
                }
                if (pacMan.Location.Y > this.Location.Y)
                {
                    //this.Direction.Y = 1;
                    this.Direction.Y = MathHelper.Clamp(this.Direction.Y += turnAmount, -1, 1);
                }
                else
                {
                    //this.Direction.Y = -1;
                    this.Direction.Y = MathHelper.Clamp(this.Direction.Y -= turnAmount, -1, 1);
                }
                if (pacMan.Location.X > this.Location.X)
                {
                    //this.Direction.X = 1;
                    this.Direction.X = MathHelper.Clamp(this.Direction.X += turnAmount, -1, 1);
                }
                else
                {
                    //this.Direction.X = -1;
                    this.Direction.X = MathHelper.Clamp(this.Direction.X -= turnAmount, -1, 1);
                }
                break;

            case GhostState.Evading:
                //Change texture if evading
                if (this.spriteTexture != this.ghostHit)
                {
                    //gameConsole.GameConsoleWrite(this.ToString() + " Evading changed texture to ghostHit");
                    this.spriteTexture = this.ghostHit;
                }

                if (pacMan.Location.Y > this.Location.Y)
                {
                    this.Direction.Y = -1;
                }
                else
                {
                    this.Direction.Y = 1;
                }
                if (pacMan.Location.X > this.Location.X)
                {
                    this.Direction.X = -1;
                }
                else
                {
                    this.Direction.X = -1;
                }
                break;

            case GhostState.Roving:
                //Change texture if Chasing
                if (!(this.spriteTexture == this.ghost))
                {
                    //gameConsole.GameConsoleWrite(this.ToString() + " Roving changed texture to spriteTexture");
                    this.spriteTexture = this.ghost;
                }
                //check if ghost can see pacman
                Vector2 normD = Vector2.Normalize(this.Direction);
                Vector2 p     = new Vector2(this.Location.X, this.Location.Y);
                while (p.X < graphics.GraphicsDevice.Viewport.Width &&
                       p.X > 0 &&
                       p.Y < graphics.GraphicsDevice.Viewport.Height &&
                       p.Y > 0)
                {
                    if (pacMan.LocationRect.Contains(new Point((int)p.X, (int)p.Y)))
                    {
                        this.ghostState = GhostState.Chasing;
                        gameConsole.GameConsoleWrite(this.ToString() + " saw pacman");
                        break;
                    }
                    p += this.Direction;
                }

                break;
            }

            //Borders
            if ((this.Location.Y + this.spriteTexture.Height / 2 > graphics.GraphicsDevice.Viewport.Height)
                ||
                (this.Location.Y - this.spriteTexture.Height / 2 < 0)
                )
            {
                this.Direction.Y *= -1;
                //this.ghostState = GhostState.Roving;
            }
            if ((this.Location.X + this.spriteTexture.Width / 2 > graphics.GraphicsDevice.Viewport.Width)
                ||
                (this.Location.X - this.spriteTexture.Width / 2 < 0)
                )
            {
                this.Direction.X *= -1;
                //this.ghostState = GhostState.Roving;
            }

            Location += ((this.Direction * (lastUpdateTime / 1000)) * Speed);      //Simple Move

            //Collision
            if (this.Intersects(pacMan))
            {
                //PerPixel Collision
                if (this.PerPixelCollision(pacMan))
                {
                    if (this.ghostState == GhostState.Evading)
                    {
                        this.Visible = false;
                        this.Enabled = false;
                    }
                    else
                    {
                        if (pacMan.PacManState != PacManState.Dying)
                        {
                            pacMan.Die();
                            this.Location   = new Vector2(100, 100);
                            this.ghostState = GhostState.Roving;
                        }
                    }
                }
            }



            base.Update(gameTime);
        }
示例#41
0
 void Start()
 {
     ghostState = GhostState.CHASING_PLAYER;
 }
示例#42
0
 void Start()
 {
     gm = GameObject.Find("GameManager").GetComponent<GameManager>();
     rg = GameObject.Find("GameManager").GetComponent<RoomGenerator>();
     currentState = GhostState.Find;
     currentRoom = rg.MainBaseRoomPiece;
 }