Esempio n. 1
0
        public void Update()
        {
            IRigidBody[] rockArray = new IRigidBody[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockArray[i] = m_GameCommand.RequestData <IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "rock_" + i.ToString(), new Constant.enumComponent[] { Constant.enumComponent.RIGIDBODY } }).OfType <IRigidBody>().FirstOrDefault();
            }

            IPositionComponent3D[] rockPosArray = new IPositionComponent3D[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockPosArray[i] = m_GameCommand.RequestData <IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "rock_" + i.ToString(), new Constant.enumComponent[] { Constant.enumComponent.POSITIONCOMPONENT3D } }).OfType <IPositionComponent3D>().FirstOrDefault();
            }

            for (int i = 0; i < rockCount; i++)
            {
                IRigidBody rock = rockArray[i];
                if (rock.m_Position.ReturnAnyLessThen(new Vector3()) || rock.m_Position.ReturnAnyGreaterThen(new Vector3(m_ScreenWidth, m_ScreenHeight, 0)))
                {
                    rockPosArray[i].m_Position = new Vector3(m_ScreenWidth - 1, m_Random.Next((int)m_ScreenHeight), 0);
                    Vector3 test       = new Vector3(30, 30, 0);
                    Boolean wrongPlace = true;
                    while (wrongPlace)
                    {
                        wrongPlace = false;
                        foreach (IPositionComponent3D rockPos in rockPosArray.Where(r => r.m_GameObjectId != rock.m_GameObjectId))
                        {
                            float distance = Math.Abs(rockPos.m_Position.y - rockPosArray[i].m_Position.y);
                            if (distance < 60 && distance > 0)
                            {
                                wrongPlace = true;
                                rockPosArray[i].m_Position = new Vector3(m_ScreenWidth - 1, m_Random.Next((int)m_ScreenHeight), 0);
                            }
                        }
                    }
                    rock.m_Velocity = new Vector3();
                    rock.AddForce(new Vector3(-30000, m_Random.Next(-3, 3) * 10000, 0));
                }
            }
        }
Esempio n. 2
0
        public void Update()
        {
            IRigidBody[] rockArray = new IRigidBody[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockArray[i] = m_GameCommand.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "rock_" + i.ToString(), new Constant.enumComponent[] { Constant.enumComponent.RIGIDBODY } }).OfType<IRigidBody>().FirstOrDefault();
            }

            IPositionComponent3D[] rockPosArray = new IPositionComponent3D[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockPosArray[i] = m_GameCommand.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "rock_" + i.ToString(), new Constant.enumComponent[] { Constant.enumComponent.POSITIONCOMPONENT3D } }).OfType<IPositionComponent3D>().FirstOrDefault();
            }

            for (int i = 0;i<rockCount;i++)
            {
                IRigidBody rock= rockArray[i];
                if (rock.m_Position.ReturnAnyLessThen(new Vector3()) || rock.m_Position.ReturnAnyGreaterThen(new Vector3(m_ScreenWidth, m_ScreenHeight, 0)))
                {
                    rockPosArray[i].m_Position = new Vector3(m_ScreenWidth - 1, m_Random.Next((int)m_ScreenHeight), 0);
                    Vector3 test = new Vector3(30,30,0);
                    Boolean wrongPlace = true;
                    while (wrongPlace)
                    {
                        wrongPlace = false;
                        foreach(IPositionComponent3D rockPos in rockPosArray.Where(r=>r.m_GameObjectId != rock.m_GameObjectId))
                        {
                            float distance = Math.Abs(rockPos.m_Position.y - rockPosArray[i].m_Position.y);
                            if(distance< 60 && distance>0)
                            {
                                wrongPlace = true;
                                rockPosArray[i].m_Position = new Vector3(m_ScreenWidth - 1, m_Random.Next((int)m_ScreenHeight), 0);
                            }
                        }
                    }
                    rock.m_Velocity = new Vector3();
                    rock.AddForce(new Vector3(-30000, m_Random.Next(-3,3)*10000, 0));
                }
            }
        }