상속: MonoBehaviour
예제 #1
0
    public void TakeDamage(Pellet inPellet)
    {
        //optimize by just sending pelletValue instead of entire object
        int brickValue = BrickPointsRemaining;

        //Debug.Log( "takeDamage()  pellet = " + pelletValue + "   brick = " + brickValue );

        BrickPointsRemaining -= inPellet.Value;;
        inPellet.Value       -= brickValue;

        //Debug.Log( "    HIT   pellet  = " + inPellet.PelletValue + "    brick = " + BrickValue );

        if (BrickPointsRemaining <= 0)
        {
            //play sound
            //SFX.playSound( SFX.ByeewDown );

            //play particle anim
            RemoveBrick();
        }
        else
        {
            //SFX.playSound( SFX.Pyoo );

            //maybe later show this with mini level bar or something
            //alpha = BrickPointsRemaining / BrickValue;
        }
    }
예제 #2
0
    private void SpawnPellets()
    {
        for (float i = 0; i <= 14; i += 0.5f)
        {
            for (float j = 0; j <= 13; j += 0.5f)
            {
                // Don't spawn in the center, or near the warp tunnel
                if (i >= 5 && i <= 10 && ((j >= 3 && j <= 10) || (j <= 2) || (j >= 11)))
                {
                    continue;
                }

                Vector3 pos = new Vector3(j, i, 2);

                // Don't spawn if intersecting a wall
                if (Physics2D.OverlapCircle(pos, 0.3f) != null)
                {
                    continue;
                }

                GameManager.Instance.IncrementTotalPellets();
                Pellet thisPellet = Instantiate(pellet, pos, Quaternion.identity);
                if (i == 3 || i == 13)
                {
                    if (j == 0 || j == 13)
                    {
                        thisPellet.SetAsSuperPellet();
                    }
                }
            }
        }
    }
        public void GeneratePellet()
        {
            var emptyCell = FindEmptyCell();

            if (_gridIsFull)
            {
                return;
            }

            if (_random.Next(4) == 4 - 1)
            {
                if (!maxGhost())
                {
                    if (!CheckAdjacency(emptyCell))
                    {
                        GenerateGhost(emptyCell);
                    }
                    return;
                }
            }

            Pellet newPellet = new Pellet(_texture, _font, Tuple.Create(emptyCell.Row, emptyCell.Col), _random.Next(1, 3));

            Tiles.Remove(emptyCell);
            Tiles.Add(newPellet);
        }
예제 #4
0
        /*
         *  TODO:
         *  - Cases to cover:
         *      - If no enemy is nearby:
         *          - Catch the closest pellets
         *          - If Sped up and Switched but enemy is no longer nearby, focus on pellets
         *      - If enemy is nearby:
         *          - Switch type to counter enemy -- Set Switch flag to true -- REMEMBER cool down is 10 turns!
         *          - If already switched and ability cooled-down
         *              - Check if PacDude can beat enemy
         *                  - If it can Speed up and chase enemy -- We'll need a flag for Switch such that it's false after speed up
         *          - If already switched but still cooling-down, catch the closest pellets
         *          - If PacDude is  still in the same coordinate then move away... It means we've clashed with another pacDude!
         *  - Within this function we'd have to implement the pathfinding function
         */
        /* This is the function where all the decision making is to be made */
        public string GetCommand(PacMan enemy, int enemyDistance, Pellet pellet, int pelletDistance, Map map, int width, int height)
        {
            /* If we're cooled down then let's put our abilities to good use! */
            if ((m_abilityCooldown == 0) && (m_speedTurnsLeft == 0))
            {
                return(Speed());
            }

            if (enemy != null && enemyDistance <= 3 && m_abilityCooldown == 0)
            {
                string counterType = CounterPacType(enemy.Type);
                if (!counterType.Equals(m_type))
                {
                    return(this.Switch(counterType));
                }
            }

            if (pellet == null)
            {
                Position next = map.BFS(m_position);
                return(next == null?this.MoveTo(m_position) : this.MoveTo(next));
            }
            else
            {
                return(this.MoveTo(pellet.Position));
            }
        }
예제 #5
0
        public void Indexer1Test()
        {
            GameState game   = GetGameState();
            Pellet    pellet = new Pellet();

            Assert.AreEqual(game.Maze[17, 12].Member().GetType(), pellet.GetType());
        }
예제 #6
0
파일: Core.cs 프로젝트: davidbarile/Atoms
 public void TakeDamage(Pellet inPellet)
 {           /*
              * //optimize by just sending pelletValue instead of entire object
              * int pelletValue = inPellet.mPelletValue;
              * int coreValue = mHealth;
              *
              * mHealth -= pelletValue;
              * Debug.Log( "mHealth = " + mHealth );
              * inPellet.mPelletValue -= coreValue;
              *
              * //shrink core radius
              * float healthRatio = mHealth / mMaxHealth / 2 + .5;
              * scaleX = healthRatio;
              * scaleY = healthRatio;
              * mRadius = healthRatio;
              *
              * //if just core, shrink total atom radius
              * if( mAtom.mNumBricksRemaining == 0 )
              * {
              *      mAtom.mRadius = healthRatio;
              * }
              *
              * //core killed
              * if( mHealth <= 0 )
              * {
              *      if( mAtom.mIsAlive )
              *      {
              *              Debug.Log( "mAtom = " + mAtom + " die" );
              *              mAtom.die();
              *      }
              * }*/
 }
예제 #7
0
    /// <summary>
    /// Called when player collides with pellet
    /// </summary>
    /// <param name="pellet">The pellet.</param>
    protected void HandlePellet(Pellet pellet)
    {
        // Boost speed/points gained if powerup
        if (pellet.powerUp)
        {
            score += gameController.powerUpScore;

            //moveSpeed += gameController.powerUpSpeedIncrease;
        }
        else
        {
            score += gameController.pelletScore;
        }

        // Set pellet inactive
        pellet.gameObject.SetActive(false);

        if (!PelletsLeft())
        {
            // Display win message
            Debug.Log("you found all the pellets!");
            //scoreText.text = "You Win!";

            audioSource.PlayOneShot(audioSource.clip);

            InvokeRepeating("FadeIn", Time.deltaTime, Time.deltaTime);
        }
        else
        {
            // Update score text
            scoreText.text = score.ToString();
        }
    }
예제 #8
0
    protected override void Start()
    {
        base.Start();

        button = GetComponentInChildren <CustomButton>(); //Get the buy button

        if (defaultWeapon)                                //If is the default weapon
        {
            isBought = true;
            isActive = true;

            if (type == ShopItemType.WEAPON)                //If it's a weapon
            {
                ShopManager.Instance.CurrentWeapon = this;  //Set the last weapon to this, the default weapon
                Player.Instance.changeWeapon(weaponPrefab); //Set the player's initial weapon to this
            }
        }

        //Construct description text
        string txt = "";

        if (type == ShopItemType.WEAPON)
        {
            Weapon wp = weaponPrefab.GetComponent <Weapon>();

            txt += "Weapon type: ";
            if (wp is Lazer)
            {
                txt += "Lazer\n";
            }
            else if (wp is Pellet)
            {
                txt += "Projectile\n";
            }

            txt += "\nDamage: " + wp.DamageAmount;
            txt += "\nCooldown: " + wp.Cooldown;
            txt += "\nRange: " + wp.Range;

            if (wp is Lazer)
            {
                Lazer lz = (Lazer)wp;
                txt += "\nDuration: " + lz.Duration;
            }
            else if (wp is Pellet)
            {
                Pellet pl = (Pellet)wp;
                txt += "\nSpeed: " + pl.Speed;
            }
        }
        else if (type == ShopItemType.HEALTH)
        {
            txt = "Heals " + healAmount + " health";
        }

        descriptionText.text = txt;

        UpdateItem(); //Update the item GUI
    }
예제 #9
0
        public void PathConstructorTest_ValidMemberInputNotNull()
        {
            Pellet      expected = new Pellet();
            Path        path     = new Path(1, 1, expected);
            ICollidable actual   = path.Member;

            Assert.AreEqual(expected, actual);
        }
예제 #10
0
        public void PositionPropertyTestSet_InvalidInput()
        {
            Pellet  member   = new Pellet();
            Path    path     = new Path(26, 26, member);
            Vector2 expected = new Vector2(-30, 30);

            path.Position = expected;
        }
예제 #11
0
    void CreateShot(Vector2 origin, Vector2 relativeDirection)
    {
        Pellet pellet = Instantiate(pelletPrefab);

        pellet.name = "Pellet";
        pellet.transform.position = transform.position + transform.rotation * origin;
        pellet.direction          = Facing + relativeDirection;
    }
예제 #12
0
        public void ConstructorTest()
        {
            int    expectedPoints = 10;
            Pellet pellet         = new Pellet();
            int    actual         = pellet.Points;

            Assert.AreEqual(expectedPoints, actual);
        }
예제 #13
0
        public void CanEnterMethodTest()
        {
            bool   expected = true;
            Pellet member   = new Pellet();
            Path   path     = new Path(26, 26, member);
            bool   actual   = path.CanEnter();

            Assert.AreEqual(expected, actual);
        }
예제 #14
0
        public void PathConstructorTest_ValidPositionInput()
        {
            Pellet  member   = new Pellet();
            Path    path     = new Path(1, 1, member);
            Vector2 expected = new Vector2(1, 1);
            Vector2 actual   = path.Position;

            Assert.AreEqual(expected, actual);
        }
예제 #15
0
        public void PositionPropertyTestGet()
        {
            Pellet  member   = new Pellet();
            Path    path     = new Path(26, 26, member);
            Vector2 expected = new Vector2(26, 26);
            Vector2 actual   = path.Position;

            Assert.AreEqual(expected, actual);
        }
예제 #16
0
        public void IsEmptyMethodTest_NotNull()
        {
            Pellet member   = new Pellet();
            Path   path     = new Path(26, 26, member);
            bool   expected = false;
            bool   actual   = path.IsEmpty();

            Assert.AreEqual(expected, actual);
        }
예제 #17
0
        public void TestGameStateParse_PelletPosition()
        {
            GameState game1  = GetGameState();
            Pellet    pellet = new Pellet();
            Tile      path   = new Path(1, 1, pellet);


            Assert.AreEqual(game1.Maze[1, 1].Member().ToString(), path.Member().ToString());
        }
예제 #18
0
        public void PointGetterTest()
        {
            Pellet pellet = new Pellet();

            pellet.Points = 200;
            int expected = 200;
            int actual   = pellet.Points;

            Assert.AreEqual(expected, actual);
        }
예제 #19
0
 public bool TryEat(Pellet pellet)
 {
     if (x == pellet.x && y == pellet.y)
     {
         score++;
         length++;
         return(true);
     }
     return(false);
 }
예제 #20
0
        public void GetDistanceMethodTest()
        {
            Pellet member   = new Pellet();
            Path   path     = new Path(26, 26, member);
            Path   path2    = new Path(30, 30, member);
            float  expected = Vector2.Distance(path2.Position, path.Position);
            float  actual   = path.GetDistance(path2.Position);

            Assert.AreEqual(expected, actual);
        }
예제 #21
0
        public void PointsSetterTest_Valid()
        {
            Pellet pellet   = new Pellet();
            int    expected = 110;

            pellet.Points += 100;
            int actual = pellet.Points;

            Assert.AreEqual(expected, actual);
        }
예제 #22
0
파일: PacMan.cs 프로젝트: andresimon/PacMan
    void ConsumePellet()
    {
        GameObject o = GameManager.instance.map.GetPelletAtPosition(transform.position);

        if (o != null)
        {
            bool didConsumed = false;

            Pellet pellet = o.GetComponent <Pellet>();

            if (GameManager.instance.isPlayerOneUp)
            {
                if (!pellet.didConsumePlayerOne)
                {
                    GameManager.instance.pelletsConsumed[0] += 1;
                    pellet.didConsumePlayerOne = true;

                    didConsumed = true;
                }
            }
            else
            {
                if (!pellet.didConsumePlayerTwo)
                {
                    GameManager.instance.pelletsConsumed[1] += 1;
                    pellet.didConsumePlayerTwo = true;

                    didConsumed = true;
                }
            }

            if (didConsumed)
            {
                o.GetComponent <SpriteRenderer>().enabled = false;

                PlayChompSound();

                if (pellet.isSuperPellet)
                {
                    GameManager.instance.IncrementScore(50);

                    GameObject[] ghosts = GameManager.instance.map.ghostObjects;
                    foreach (GameObject go in ghosts)
                    {
                        go.GetComponent <Ghost>().StartFrightenedMode();
                    }
                }
                else
                {
                    GameManager.instance.IncrementScore(10);
                }
            }
        }
    }
예제 #23
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, null))
            {
                return(false);
            }

            Pellet pellet = (Pellet)obj;

            return(pellet.Location.Equals(Location) && pellet.Value == Value);
        }
예제 #24
0
 public Cell(char cell, Vector2 position)
 {
     this.IsWalkable = cell == ' ' ? true : false;
     if (IsWalkable)
     {
         this.HasPellet = true;
         Inside         = new Pellet(position, 1);
     }
     this.IsVisiblePellet = false;
     this.Position        = position;
 }
예제 #25
0
        public void PositionPropertyTestSet_ValidInput()
        {
            Pellet  member   = new Pellet();
            Path    path     = new Path(26, 26, member);
            Vector2 expected = new Vector2(30, 30);

            path.Position = expected;
            Vector2 actual = path.Position;

            Assert.AreEqual(expected, actual);
        }
예제 #26
0
        public void MemberPropertyTestSet()
        {
            Energizer e        = new Energizer();
            Path      path     = new Path(1, 1, e);
            Pellet    expected = new Pellet();

            path.Member = expected;
            ICollidable actual = path.Member;

            Assert.AreEqual(expected, actual);
        }
    // Update is called once per frame
    void Update()
    {
        Pellet p = PelletHandler.Instance.GetClosestPellet(transform.position);

        if (p != null)
        {
            float dist = (transform.position - p.transform.position).sqrMagnitude;
            //Extremely slow way to do this, don't do this normally. Just want to avoid collision issues
            if (dist < 0.01f)
            {
                p.Eat();
            }
        }
    }
예제 #28
0
        public void CollisionEventRaisedTest()
        {
            Boolean actual   = false;
            Boolean expected = true;
            Pellet  pellet   = new Pellet();

            pellet.CollisionEvent += (x) =>
            {
                x.Points += 100;
                actual    = true;
            };
            pellet.Collide();
            Assert.AreEqual(expected, actual);
        }
예제 #29
0
    // Update is called once per frame
    void Update()
    {
        Pellet p = PelletHandler.Instance.GetClosestPellet(transform.position);

        if (p != null)
        {
            Vector3 target = p.transform.position;

            //CalculatePath
            GraphNode closestStart = HW3NavigationHandler.Instance.NodeHandler.ClosestNode(transform.position);
            GraphNode closestGoal  = HW3NavigationHandler.Instance.NodeHandler.ClosestNode(target);
            path = HW3NavigationHandler.Instance.PathFinder.CalculatePath(closestStart, closestGoal);

            if (path == null || path.Length <= 1)
            {
                SetTarget(target);
            }
            else
            {
                pathIndex = 0;
                SetTarget(path[pathIndex]);
            }
        }
        else
        {
            movingTowardTarget = false;
        }

        if (movingTowardTarget)
        {
            if ((target - transform.position).sqrMagnitude < AgentConstants.THRESHOLD)
            {
                movingTowardTarget = false;
                transform.position = target;
            }
            else
            {
                Vector3 potentialNewPosition = transform.position + (target - transform.position).normalized * Time.deltaTime * speed;
                if (ObstacleHandler.Instance.AnyIntersect(new Vector2(transform.position.x, transform.position.y), new Vector2(potentialNewPosition.x, potentialNewPosition.y)))
                {
                    movingTowardTarget = false;
                }
                else
                {
                    transform.position = potentialNewPosition;
                }
            }
        }
    }
예제 #30
0
    //fire a small pellet forward. Restarts the time to fire.
    void fire()
    {
        if (fireDirection > 0)
        {
            clone = Instantiate(pellet, (transform.position), transform.rotation) as GameObject;
        }
        else
        {
            clone = Instantiate(pellet, (transform.position), transform.rotation) as GameObject;
        }
        Pellet pelletScript = clone.GetComponent <Pellet>();

        pelletScript.moveDirection = fireDirection;
        lerpTime = 0;
    }
예제 #31
0
    void OnPelletHit(Pellet p)
    {
        //remove the pellet from the pellet list as it's about to be destroyed
        pelletList.Remove(p);

        UpdateBlastRadius();
    }