public void Update() { IGraphicsSettings graphicSetting = m_ScriptController.RequestData <IGraphicsSettings>(Constant.enumMessage.GET_GRAPHICS_SETTINGS).FirstOrDefault(); //IRigidBody playerRigidBody = m_ScriptController.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { m_GameObject.m_GameObjectKey, new Constant.enumComponent[] { Constant.enumComponent.RIGIDBODY } }).OfType<IRigidBody>().FirstOrDefault(); IRigidBody playerRigidBody = m_GameObject.getComponent <IRigidBody>(Constant.enumComponent.RIGIDBODY); if (playerRigidBody.m_Position.ReturnAnyLessThen(new Vector3(-90, -40, 0)) || playerRigidBody.m_Position.ReturnAnyGreaterThen(new Vector3(graphicSetting.m_ScreenSize.x, graphicSetting.m_ScreenSize.y, 0))) { // IPositionComponent3D playerPos = m_ScriptController.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "player", new Constant.enumComponent[] { Constant.enumComponent.POSITIONCOMPONENT3D } }).OfType<IPositionComponent3D>().FirstOrDefault(); IPositionComponent3D playerPos = m_GameObject.getComponent <IPositionComponent3D>(Constant.enumComponent.POSITIONCOMPONENT3D); playerPos.m_Position.x = (graphicSetting.m_ScreenSize.x / 2) - 45; playerPos.m_Position.y = graphicSetting.m_ScreenSize.y / 2; playerRigidBody.m_Velocity = new Vector3(); } string[] pressedKeys = m_ScriptController.RequestData <string>(Constant.enumMessage.GET_PRESSED_KEYS); foreach (string key in pressedKeys) { Constant.enumKey currKey = (Constant.enumKey)Enum.Parse(typeof(Constant.enumKey), key); switch (currKey) { case Constant.enumKey.Up: playerRigidBody.AddForce(0, -500, 0);; break; case Constant.enumKey.Down: playerRigidBody.AddForce(0, 500, 0);; break; case Constant.enumKey.Left: playerRigidBody.AddForce(-500, 0, 0);; break; case Constant.enumKey.Right: playerRigidBody.AddForce(500, 0, 0);; break; } } }
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)); } } }