public void Init() { m_Random = new Random(); string[] textures = { "Resources/rocktex.jpg" }; string[] spriteIDs = m_GameCommand.RequestData <string>(Constant.enumMessage.LOAD_TEXTURES, textures); //Load Textures and Get related IDS IGraphicsSettings graphicsSettings = new GraphicsSettings2D(); graphicsSettings.Initialise(new Vector2(800, 600), false, true, true); m_GameCommand.SendData(Constant.enumMessage.UPDATE_GRAPHICS_SETTINGS, new IGraphicsSettings[] { graphicsSettings }); m_ScreenHeight = graphicsSettings.m_ScreenSize.y; m_ScreenWidth = graphicsSettings.m_ScreenSize.x; IGameObject[] rocks = new IGameObject[rockCount]; for (int i = 0; i < rockCount; i++) { rockKeys[i] = "rock_" + i.ToString(); rocks[i] = new GameObject(rockKeys[i], -800, 0, 0); } m_GameCommand.SendData(Constant.enumMessage.CREATE_OBJECTS, rocks); for (int i = 0; i < rockCount; i++) { IComponent[] rockCompArray = { new RigidBody(5, 0, 0, false, true), new Collider(new Vector3(80, 80, 0)), new SpriteComponent(spriteIDs[0]) }; rockKeys[i] = "rock_" + i.ToString(); m_GameCommand.SendData(Constant.enumMessage.ADD_COMPONENTS_TO_OBJECT, new Object[] { rockKeys[i], rockCompArray }); } IGameObject[] player = { new GameObject(playerKey, 0, 0, 0) }; m_GameCommand.SendData(Constant.enumMessage.CREATE_OBJECTS, player); m_GameCommand.SendDataForObject <IScript>(Constant.enumMessage.ADD_SCRIPT_TO_OBJECT, playerKey, new TestScript()); m_GameCommand.SendData(Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS, rockKeys); }
private void GameUpdate() { string[] pressedKeys = m_GameCommand.RequestData <string>(Constant.enumMessage.GET_PRESSED_KEYS); bool altPressed = false, userClicked = false; if (m_KeyboardElapsedTime > m_InputCooldown) { foreach (string key in pressedKeys) { Constant.enumKey currKey = (Constant.enumKey)Enum.Parse(typeof(Constant.enumKey), key); switch (currKey) { case Constant.enumKey.Escape: m_CurrState = 5; break; case Constant.enumKey.Return: if (altPressed) { m_SetFullscreen = !m_SetFullscreen; } break; case Constant.enumKey.LAlt: case Constant.enumKey.RAlt: altPressed = true; break; } } m_KeyboardElapsedTime = 0.0; } else { m_KeyboardElapsedTime += Constant.elapsedTime; } string[] pressedMouseButtons = m_GameCommand.RequestData <string>(Constant.enumMessage.GET_PRESSED_MOUSEBUTTONS); if (m_MouseElapsedTime > m_InputCooldown) { foreach (string button in pressedMouseButtons) { Constant.enumMouseButton currButton = (Constant.enumMouseButton)Enum.Parse(typeof(Constant.enumMouseButton), button); switch (currButton) { case Constant.enumMouseButton.LEFT: userClicked = true; break; } } m_MouseElapsedTime = 0.0; } else { m_MouseElapsedTime += Constant.elapsedTime; } if (userClicked && m_CurrPlayer == 0) { Vector2 MousePos = m_GameCommand.RequestData <Vector2>(Constant.enumMessage.GET_MOUSE_POSITION)[0]; int[] relativePos = GetRelativeMousePos(MousePos); if (relativePos != null && !IsBoardOccupied(relativePos[0], relativePos[1])) { //m_GameCommand.SendData(Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS, new string[] {m_OObjTable[relativePos[0],relativePos[1]]}); SetBoardOccupied(relativePos[0], relativePos[1]); SwitchPlayer(); } } else if (m_CurrPlayer == 1) { int genx = m_Random.Next(3), geny = m_Random.Next(3); if (!IsBoardOccupied(genx, geny)) { //m_GameCommand.SendData(Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS, new string[] { m_XObjTable[genx, geny] }); SetBoardOccupied(genx, geny); SwitchPlayer(); } } CheckGameWin(); if (m_CurrState != 1) { ClearBoard(); } }