예제 #1
0
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                ship = EntityFactory.InstanceEntity <ShipBase>();
                ship.Create(new Vector3(3, 3, 3));
            }

            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                EntityFactory.ReleaseEntity(ship);
            }

            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                EntityFactory.ClearReleasedObjects();
            }
        }
예제 #2
0
        //==============================================================================================================

        public void EnterFrame(int frameIndex)
        {
            if (!m_isRunning)
            {
                return;
            }

            if (frameIndex < 0)
            {
                m_context.curFrameIndex++;
            }
            else
            {
                m_context.curFrameIndex = frameIndex;
            }

            // 清理被释放的对象
            EntityFactory.ClearReleasedObjects();

            // 更新玩家动作
            foreach (FlyingPlayer player in m_playerList)
            {
                player.EnterFrame(frameIndex);
            }

            // 更新地图逻辑
            if (m_map != null)
            {
                m_map.EnterFrame(frameIndex);
            }

            // 如果有玩家死亡,调用玩家死亡事件
            HandlePlayerDied();

            // 如果有玩家到达终点,调用玩家到达终点事件
            HandlePlayerArriveEnd();
        }
예제 #3
0
        //===========================================================================

        public void EnterFrame(int frameIndex)
        {
            if (!m_isRunning)
            {
                return;
            }

            if (frameIndex < 0)
            {
                m_context.currentFrameIndex++;
            }
            else
            {
                m_context.currentFrameIndex = frameIndex;
            }

            EntityFactory.ClearReleasedObjects();

            for (int i = 0; i < m_listPlayer.Count; ++i)
            {
                m_listPlayer[i].EnterFrame(frameIndex);
            }


            List <uint> listDiePlayerId = new List <uint>();

            for (int i = 0; i < m_listPlayer.Count; i++)
            {
                SnakePlayer player = m_listPlayer[i];

                if (player.TryHitBound(m_context))
                {
                    listDiePlayerId.Add(player.Id);
                    ReleasePlayerAt(i);
                    i--;

                    continue;
                }

                if (player.TryHitEnemies(m_listPlayer))
                {
                    listDiePlayerId.Add(player.Id);
                    ReleasePlayerAt(i);
                    i--;
                    continue;
                }

                for (int j = 0; j < m_listFood.Count; j++)
                {
                    EntityObject food = m_listFood[j];
                    if (player.TryEatFood(food))
                    {
                        RemoveFoodAt(j);
                        j--;
                    }
                }
            }

            if (m_map != null)
            {
                m_map.EnterFrame(frameIndex);
            }

            if (onPlayerDie != null)
            {
                for (int i = 0; i < listDiePlayerId.Count; ++i)
                {
                    onPlayerDie(listDiePlayerId[i]);
                }
            }
        }