public override bool InitOne(ContentManager content, int id) { try { XmlDocument _doc = new XmlDocument(); _doc.Load(_xmlInfo); XmlNode _menuFrame = _doc.SelectSingleNode(@"//MenuFrame[@id = '"+ id.ToString() +"']"); //Menu frame chi bao gom 1 texture.. _prototype[id] = new MenuFrame (); _prototype[id]._nsprite = 1; _prototype[id]._sprite = new GameSprite[_prototype[id]._nsprite]; _prototype[id]._sprite[0] = new GameSprite(content.Load<Texture2D>(_menuFrame.SelectSingleNode(@"Background").InnerText), 0, 0); _prototype[id].Height = int.Parse(_menuFrame.SelectSingleNode(@"Height").InnerText); _prototype[id].Width = int.Parse(_menuFrame.SelectSingleNode(@"Width").InnerText); _prototype[id].X = int.Parse(_menuFrame.SelectSingleNode(@"X").InnerText); _prototype[id].Y = int.Parse(_menuFrame.SelectSingleNode(@"Y").InnerText); _prototype[id].Rect = new Rectangle((int)_prototype[id].X, (int)_prototype[id].Y, (int)_prototype[id].Width, (int)_prototype[id].Height); ((MenuFrame)_prototype[id]).DelayTime = int.Parse(_menuFrame.SelectSingleNode(@"DelayTime").InnerText); MotionInfo _menuMoveInfo = new MotionInfo(); XmlNode moveInfo = _menuFrame.SelectSingleNode(@"MoveInfo"); _menuMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_menuMoveInfo.FirstDection == "Null") // frame đứng yên { _menuMoveInfo = null; } else { _menuMoveInfo.IsStanding = false; // bật cờ di chuyển string temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") _menuMoveInfo.StandingGround = float.MinValue; else _menuMoveInfo.StandingGround = float.Parse(temp); _menuMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText) / 10; _menuMoveInfo.Owner = _prototype[id]; } ((MenuFrame)_prototype[id])._motionInfo = _menuMoveInfo; } catch { return false; } return true; }
public GameFrame() { _child = new List <VisibleGameObject>(); _motion = null; _nChild = 0; _delayTime = 0; _iDelayTime = 0; }
public void CreateMotion_GoOut() { _motionGoOut = new MotionInfo(); _motionGoOut.FirstDection = "Up"; _motionGoOut.IsStanding = true; _motionGoOut.StandingGround = float.MinValue; _motionGoOut.Vel = new Vector2(0, 0); _motionGoOut.Accel = new Vector2(0, 1f); _motionGoOut.DecelerationRate = 0.6f; }
public void CreateMotion_GoIn() { _motionGoIn = new MotionInfo(); _motionGoIn.FirstDection = "Left"; _motionGoIn.IsStanding = true; _motionGoIn.StandingGround = 400; _motionGoIn.Vel = new Vector2(31, 0); _motionGoIn.Accel = new Vector2(1.055f, 0); _motionGoIn.DecelerationRate = 0.6f; }
public void CreateMotion_GoIn() { _motionGoIn = new MotionInfo(); _motionGoIn.FirstDection = "Up"; _motionGoIn.IsStanding = true; _motionGoIn.StandingGround = 449; _motionGoIn.Vel = new Vector2(0, 19); _motionGoIn.Accel = new Vector2(0, 1.06f); _motionGoIn.DecelerationRate = 0.6f; }
private MotionInfo SetButtonMotion(MotionInfo _preMotion) { MotionInfo _newMotion = _preMotion; _newMotion.IsStanding = false; _newMotion.FirstDection = "Right"; _newMotion.StandingGround = float.MinValue; _newMotion.Vel = new Vector2(25, 0); _newMotion.Accel = new Vector2(4, 0); return(_newMotion); }
//----------------------FUNCTION----------------------------------------------------- public MotionInfo Clone() { MotionInfo _save = new MotionInfo(); _save.Owner = Owner; _save.FirstDection = FirstDection; _save.NowDirection = NowDirection; _save.StandingGround = StandingGround; _save.Vel = Vel; _save.Accel = Accel; _save.DecelerationRate = DecelerationRate; _save.IsStanding = IsStanding; return(_save); }
public override void MouseClick(MouseObserver mo) { //Khi button được click thì sẽ kiểm tra các yếu tố sau // -Nếu button chưa dừng lại (đang chạy ra màn hinh) // -Nều button đã được click //--> Không xử lý if (!_motionInfo.IsStanding) { return; } if (_isClicked) { return; } _isClicked = true; //Xét lại hướng chuyển động và một số tham số cần thiết để cho button //chuyển động theo cách mong muốn. _motionInfo = SetButtonMotion(_motionInfo); //Hàm này sẽ được gọi trong update (vì button sau khi đã đi ra ngoài màn hình // thì hàm này mới được dọi để xử lý ở mức State) //OnMouse_Click(this, null); }
public void CreateMotion_GoOut() { _motionGoOut = new MotionInfo(); _motionGoOut.FirstDection = "Left"; _motionGoOut.IsStanding = true; _motionGoOut.StandingGround = float.MinValue; _motionGoOut.Vel = new Vector2(0, 0); _motionGoOut.Accel = new Vector2(1.8f, 0); _motionGoOut.DecelerationRate = 0.6f; }
public override bool InitPrototypes(ContentManager content, string fileName) { try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNodeList list = doc.SelectNodes(@"//Menu"); _nprototype = list.Count; _prototype = new Menu[_nprototype]; for (int i = 0; i < _nprototype; ++i) { /*_prototype[i] = new Menu(); * _prototype[i]._nsprite = 0; * _prototype[i]._sprite = null; * _prototype[i].X = 0; * _prototype[i].Y = 0;*/ _prototype[i] = new Menu(); _prototype[i]._nsprite = 1; _prototype[i]._sprite = new GameSprite[_prototype[i]._nsprite]; _prototype[i]._sprite[0] = new GameSprite(content.Load <Texture2D>(list[i].SelectSingleNode(@"Background").InnerText), 0, 0); _prototype[i].Height = int.Parse(list[i].SelectSingleNode(@"Height").InnerText); _prototype[i].Width = int.Parse(list[i].SelectSingleNode(@"Width").InnerText); _prototype[i].X = int.Parse(list[i].SelectSingleNode(@"X").InnerText); _prototype[i].Y = int.Parse(list[i].SelectSingleNode(@"Y").InnerText); _prototype[i].Rect = new Rectangle((int)_prototype[i].X, (int)_prototype[i].Y, (int)_prototype[i].Width, (int)_prototype[i].Height); ((Menu)_prototype[i]).DelayTime = int.Parse(list[i].SelectSingleNode(@"DelayTime").InnerText); MotionInfo _menuMoveInfo = new MotionInfo(); XmlNode moveInfo = list[i].SelectSingleNode(@"MoveInfo"); _menuMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_menuMoveInfo.FirstDection == "Null") { _menuMoveInfo.IsStanding = true; } else { _menuMoveInfo.IsStanding = false; } string temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") { _menuMoveInfo.StandingGround = float.MinValue; } else { _menuMoveInfo.StandingGround = float.Parse(temp); } _menuMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText); _menuMoveInfo.Owner = _prototype[i]; ((Menu)_prototype[i])._motionInfo = _menuMoveInfo; for (int j = 0; j < list[i].ChildNodes.Count; ++j) { if (list[i].ChildNodes[j].Name.CompareTo("Button") == 0) { XmlNode _node = list[i].ChildNodes[j]; Button _b = (Button)GlobalVariables.Btm.CreateObject(int.Parse(_node.SelectSingleNode("Type").InnerText)); _b.X = int.Parse(_node.SelectSingleNode("X").InnerText); _b.Y = int.Parse(_node.SelectSingleNode("Y").InnerText); _b.DelayTime = int.Parse(_node.SelectSingleNode("DelayTime").InnerText); _b.Rect = new Rectangle((int)_b.X, (int)_b.Y, (int)_b.Width, (int)_b.Height); MotionInfo _buttonMoveInfo = new MotionInfo(); moveInfo = _node.SelectSingleNode(@"MoveInfo"); _buttonMoveInfo.Owner = _b; _buttonMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_buttonMoveInfo.FirstDection == "Null") { _buttonMoveInfo.IsStanding = true; } else { _buttonMoveInfo.IsStanding = false; } temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") { _buttonMoveInfo.StandingGround = float.MinValue; } else { _buttonMoveInfo.StandingGround = float.Parse(temp); } _buttonMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _buttonMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _buttonMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText); _b._motionInfo = _buttonMoveInfo; ((Menu)_prototype[i]).Child.Add(_b); } } } return(true); } catch (Exception e) { return(false); } }
public override void InitState(GameObjectManager[] objectManagerArray, MainGame owner) { //Trong innit tao base.InitState(objectManagerArray, owner); _newgameFrame = (GameFrame)objectManagerArray[1].CreateObject(0); _newgameFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_NewGame); _newgameButton = (Button)objectManagerArray[2].CreateObject(0); _newgameFrame.AddChild(_newgameButton); _newgameButton.Owner = _newgameFrame; _newgameButton.Mouse_Click += new Button.OnMouseClickHandler(StateMenu_Mouse_Click_NewGame); _newgameButton.Mouse_Hover += new Button.OnMouseHoverHandler(StateMenu_Mouse_Hover_NewGame); _newgameFrameMotion = _newgameFrame.Motion.Clone(); _newgameDelayTimeGoIn = _newgameFrame.DelayTime; _loadgameFrame = (GameFrame)objectManagerArray[1].CreateObject(1); _loadgameFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_Load); _loadgameButton = (Button)objectManagerArray[2].CreateObject(1); _loadgameFrame.AddChild(_loadgameButton); _loadgameButton.Owner = _loadgameFrame; _loadgameButton.Mouse_Click += new Button.OnMouseClickHandler(StateMenu_Mouse_Click_Load); _loadgameButton.Mouse_Hover += new Button.OnMouseHoverHandler(StateMenu_Mouse_Hover_Load); _loadgameFrameMotion = _loadgameFrame.Motion.Clone(); _loadgameDelayTimeGoIn = _loadgameFrame.DelayTime; _optionFrame = (GameFrame)objectManagerArray[1].CreateObject(2); _optionFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_Option); _optionButton = (Button)objectManagerArray[2].CreateObject(2); _optionFrame.AddChild(_optionButton); _optionButton.Owner = _optionFrame; _optionButton.Mouse_Click += new Button.OnMouseClickHandler(StateMenu_Mouse_Click_Option); _optionButton.Mouse_Hover += new Button.OnMouseHoverHandler(StateMenu_Mouse_Hover_Option); _optionFrameMotion = _optionFrame.Motion.Clone(); _optionDelayTimeGoIn = _optionFrame.DelayTime; _helpFrame = (GameFrame)objectManagerArray[1].CreateObject(3); _helpFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_Help); _helpButton = (Button)objectManagerArray[2].CreateObject(3); _helpFrame.AddChild(_helpButton); _helpButton.Owner = _helpFrame; _helpButton.Mouse_Click += new Button.OnMouseClickHandler(StateMenu_Mouse_Click_Help); _helpButton.Mouse_Hover += new Button.OnMouseHoverHandler(StateMenu_Mouse_Hover_Help); _helpFrameMotion = _helpFrame.Motion.Clone(); _helpDelayTimeGoIn = _helpFrame.DelayTime; _aboutFrame = (GameFrame)objectManagerArray[1].CreateObject(4); _aboutFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_About); _aboutButton = (Button)objectManagerArray[2].CreateObject(4); _aboutFrame.AddChild(_aboutButton); _aboutButton.Owner = _aboutFrame; _aboutButton.Mouse_Click += new Button.OnMouseClickHandler(StateMenu_Mouse_Click_About); _aboutButton.Mouse_Hover += new Button.OnMouseHoverHandler(StateMenu_Mouse_Hover_About); _aboutFrameMotion = _aboutFrame.Motion.Clone(); _aboutDelayTimeGoIn = _aboutFrame.DelayTime; _quitFrame = (GameFrame)objectManagerArray[1].CreateObject(5); _quitFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_Quit); _quitButton = (Button)objectManagerArray[2].CreateObject(5); _quitFrame.AddChild(_quitButton); _quitButton.Owner = _quitFrame; _quitButton.Mouse_Click += new Button.OnMouseClickHandler(StateMenu_Mouse_Click_Quit); _quitButton.Mouse_Hover += new Button.OnMouseHoverHandler(StateMenu_Mouse_Hover_Quit); _quitFrameMotion = _quitFrame.Motion.Clone(); _quitDelayTimeGoIn = _quitFrame.DelayTime; _menuFrame = (GameFrame)objectManagerArray[1].CreateObject(6); _menuFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(StateMenu_Move_Complete_MenuFrame); _menuFrameMotion = _menuFrame.Motion.Clone(); _menuFrameDelayTimeGoIn = _menuFrame.DelayTime; }
public override void InitState(GameObjectManager[] objectManagerArray, MainGame owner) { base.InitState(objectManagerArray, owner); //_introFrame = (GameFrame)objectManagerArray[1].CreateObject(7); //_introMotion = _introFrame.Motion.Clone(); //_introDelayTime = _introFrame.DelayTime; _introFrames = (GameFrame)objectManagerArray[1].CreateObject(7); _introFrameMotion = _introFrames.Motion.Clone(); _introFrameDelayTime = _introFrames.DelayTime; _dacPhuFrame = (GameFrame)objectManagerArray[1].CreateObject(13); _minhQuanFrame = (GameFrame)objectManagerArray[1].CreateObject(14); _introGameFrame = (GameFrame)objectManagerArray[1].CreateObject(15); _introFrames.AddChild(_introGameFrame); _introFrames.AddChild(_dacPhuFrame); _introFrames.AddChild(_minhQuanFrame); _currentIntroFrame = 0; _selectMode = (GameFrame)objectManagerArray[1].CreateObject(8); _selectMode.Move_Complete += new GameFrame.OnMoveCompletedHandler(Move_Complete_SelectFrame); _selectMotion = _selectMode.Motion.Clone(); _selectDelayTime = _selectMode.DelayTime; _aboutGameButtonFrame = (GameFrame)objectManagerArray[1].CreateObject(9); _aboutGameButton = (Button)objectManagerArray[2].CreateObject(6); _aboutGameButton.IsPressButton = true; _aboutGameButtonFrame.AddChild(_aboutGameButton); _aboutGameButton.Mouse_Down += new Button.OnMouseDownHandler(AboutGame_Down); _aboutGameButton.Mouse_Hover += new Button.OnMouseHoverHandler(AboutGame_Hover); _aboutMotion = _aboutGameButtonFrame.Motion.Clone(); _aboutDelayTime = _aboutGameButtonFrame.DelayTime; //Set Button này được Click trước _aboutGameButton._sprite[0].Itexture2D = 1; _programer1ButtonFrame = (GameFrame)objectManagerArray[1].CreateObject(10); _programer1Button = (Button)objectManagerArray[2].CreateObject(7); _programer1Button.IsPressButton = true; _programer1ButtonFrame.AddChild(_programer1Button); _programer1Button.Mouse_Down += new Button.OnMouseDownHandler(Programer1_Down); _programer1Button.Mouse_Hover += new Button.OnMouseHoverHandler(Programer1_Hover); _programer1Motion = _programer1ButtonFrame.Motion.Clone(); _programer1DelayTime = _programer1ButtonFrame.DelayTime; _programer2ButtonFrame = (GameFrame)objectManagerArray[1].CreateObject(11); _programer2Button = (Button)objectManagerArray[2].CreateObject(8); _programer2Button.IsPressButton = true; _programer2ButtonFrame.AddChild(_programer2Button); _programer2Button.Mouse_Down += new Button.OnMouseDownHandler(Programer2_Down); _programer2Button.Mouse_Hover += new Button.OnMouseHoverHandler(Programer2_Hover); _programer2Motion = _programer2ButtonFrame.Motion.Clone(); _programer2DelayTime = _programer2ButtonFrame.DelayTime; _exitButtonFrame = (GameFrame)objectManagerArray[1].CreateObject(12); _exitButtonFrame.Move_Complete += new GameFrame.OnMoveCompletedHandler(Move_Complete_ExitFrame); _exitButton = (Button)objectManagerArray[2].CreateObject(5); _exitButtonFrame.AddChild(_exitButton); _exitButton.Mouse_Click += new Button.OnMouseClickHandler(Exit_Clicked); _exitButton.Mouse_Hover += new Button.OnMouseHoverHandler(Exit_Hover); _exitMotion = _exitButtonFrame.Motion.Clone(); _exitDelayTime = _exitButtonFrame.DelayTime; }
public override bool InitOne(ContentManager content, int id) { try { XmlDocument _doc = new XmlDocument(); _doc.Load(_xmlInfo); XmlNode _menuFrame = _doc.SelectSingleNode(@"//MenuFrame[@id = '" + id.ToString() + "']"); //Menu frame chi bao gom 1 texture.. _prototype[id] = new MenuFrame(); _prototype[id]._nsprite = 1; _prototype[id]._sprite = new GameSprite[_prototype[id]._nsprite]; _prototype[id]._sprite[0] = new GameSprite(content.Load <Texture2D>(_menuFrame.SelectSingleNode(@"Background").InnerText), 0, 0); _prototype[id].Height = int.Parse(_menuFrame.SelectSingleNode(@"Height").InnerText); _prototype[id].Width = int.Parse(_menuFrame.SelectSingleNode(@"Width").InnerText); _prototype[id].X = int.Parse(_menuFrame.SelectSingleNode(@"X").InnerText); _prototype[id].Y = int.Parse(_menuFrame.SelectSingleNode(@"Y").InnerText); _prototype[id].Rect = new Rectangle((int)_prototype[id].X, (int)_prototype[id].Y, (int)_prototype[id].Width, (int)_prototype[id].Height); ((MenuFrame)_prototype[id]).DelayTime = int.Parse(_menuFrame.SelectSingleNode(@"DelayTime").InnerText); MotionInfo _menuMoveInfo = new MotionInfo(); XmlNode moveInfo = _menuFrame.SelectSingleNode(@"MoveInfo"); _menuMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_menuMoveInfo.FirstDection == "Null") // frame đứng yên { _menuMoveInfo = null; } else { _menuMoveInfo.IsStanding = false; // bật cờ di chuyển string temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") { _menuMoveInfo.StandingGround = float.MinValue; } else { _menuMoveInfo.StandingGround = float.Parse(temp); } _menuMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText) / 10; _menuMoveInfo.Owner = _prototype[id]; } ((MenuFrame)_prototype[id])._motionInfo = _menuMoveInfo; } catch { return(false); } return(true); }
public override bool InitPrototypes(ContentManager content, string fileName) { try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNodeList list = doc.SelectNodes(@"//Menu"); _nprototype = list.Count; _prototype = new Menu[_nprototype]; for (int i = 0; i < _nprototype; ++i) { /*_prototype[i] = new Menu(); _prototype[i]._nsprite = 0; _prototype[i]._sprite = null; _prototype[i].X = 0; _prototype[i].Y = 0;*/ _prototype[i] = new Menu(); _prototype[i]._nsprite = 1; _prototype[i]._sprite = new GameSprite[_prototype[i]._nsprite]; _prototype[i]._sprite[0] = new GameSprite(content.Load<Texture2D>(list[i].SelectSingleNode(@"Background").InnerText), 0, 0); _prototype[i].Height = int.Parse(list[i].SelectSingleNode(@"Height").InnerText); _prototype[i].Width = int.Parse(list[i].SelectSingleNode(@"Width").InnerText); _prototype[i].X = int.Parse(list[i].SelectSingleNode(@"X").InnerText); _prototype[i].Y = int.Parse(list[i].SelectSingleNode(@"Y").InnerText); _prototype[i].Rect = new Rectangle((int)_prototype[i].X, (int)_prototype[i].Y, (int)_prototype[i].Width, (int)_prototype[i].Height); ((Menu)_prototype[i]).DelayTime = int.Parse(list[i].SelectSingleNode(@"DelayTime").InnerText); MotionInfo _menuMoveInfo = new MotionInfo(); XmlNode moveInfo = list[i].SelectSingleNode(@"MoveInfo"); _menuMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_menuMoveInfo.FirstDection == "Null") _menuMoveInfo.IsStanding = true; else _menuMoveInfo.IsStanding = false; string temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") _menuMoveInfo.StandingGround = float.MinValue; else _menuMoveInfo.StandingGround = float.Parse(temp); _menuMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _menuMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText); _menuMoveInfo.Owner = _prototype[i]; ((Menu)_prototype[i])._motionInfo = _menuMoveInfo; for (int j = 0; j < list[i].ChildNodes.Count; ++j) { if (list[i].ChildNodes[j].Name.CompareTo("Button") == 0) { XmlNode _node = list[i].ChildNodes[j]; Button _b = (Button)GlobalVariables.Btm.CreateObject(int.Parse(_node.SelectSingleNode("Type").InnerText)); _b.X = int.Parse(_node.SelectSingleNode("X").InnerText); _b.Y = int.Parse(_node.SelectSingleNode("Y").InnerText); _b.DelayTime = int.Parse(_node.SelectSingleNode("DelayTime").InnerText); _b.Rect = new Rectangle((int)_b.X, (int)_b.Y, (int)_b.Width, (int)_b.Height); MotionInfo _buttonMoveInfo = new MotionInfo(); moveInfo = _node.SelectSingleNode(@"MoveInfo"); _buttonMoveInfo.Owner = _b; _buttonMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_buttonMoveInfo.FirstDection == "Null") _buttonMoveInfo.IsStanding = true; else _buttonMoveInfo.IsStanding = false; temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") _buttonMoveInfo.StandingGround = float.MinValue; else _buttonMoveInfo.StandingGround = float.Parse(temp); _buttonMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _buttonMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), int.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _buttonMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText); _b._motionInfo = _buttonMoveInfo; ((Menu)_prototype[i]).Child.Add(_b); } } } return true; } catch (Exception e) { return false; } }
public override void MouseClick(MouseObserver mo) { //Khi button được click thì sẽ kiểm tra các yếu tố sau // -Nếu button chưa dừng lại (đang chạy ra màn hinh) // -Nều button đã được click //--> Không xử lý if (!_motionInfo.IsStanding) return; if (_isClicked) return; _isClicked = true; //Xét lại hướng chuyển động và một số tham số cần thiết để cho button //chuyển động theo cách mong muốn. _motionInfo = SetButtonMotion(_motionInfo); //Hàm này sẽ được gọi trong update (vì button sau khi đã đi ra ngoài màn hình // thì hàm này mới được dọi để xử lý ở mức State) //OnMouse_Click(this, null); }
private MotionInfo SetButtonMotion(MotionInfo _preMotion) { MotionInfo _newMotion = _preMotion; _newMotion.IsStanding = false; _newMotion.FirstDection = "Right"; _newMotion.StandingGround = float.MinValue; _newMotion.Vel = new Vector2(25, 0); _newMotion.Accel = new Vector2(4, 0); return _newMotion; }
public override bool InitOne(ContentManager content, int id) { XmlDocument _doc = new XmlDocument(); _doc.Load(_xmlInfo); XmlNode _frame = _doc.SelectSingleNode(@"//Frame[@id = '" + id.ToString() + "']"); _prototype[id] = new GameFrame(); string _backgroundPath = _frame.SelectSingleNode("BackGround").InnerText; if (_backgroundPath == "Null") { _prototype[id]._nsprite = 0; _prototype[id]._sprite = null; } else { _prototype[id]._nsprite = 1; _prototype[id]._sprite = new GameSprite [_prototype[id]._nsprite]; Texture2D _temp = content.Load <Texture2D>(_backgroundPath); _prototype[id]._sprite[0] = new GameSprite(_temp, 0, 0); } _prototype[id].X = int.Parse(_frame.SelectSingleNode("X").InnerText); _prototype[id].Y = int.Parse(_frame.SelectSingleNode("Y").InnerText); _prototype[id].OffSetX = _prototype[id].X; _prototype[id].OffSetY = _prototype[id].Y; _prototype[id].Width = int.Parse(_frame.SelectSingleNode("Width").InnerText); _prototype[id].Height = int.Parse(_frame.SelectSingleNode("Height").InnerText); _prototype[id].Rect = new Rectangle((int)_prototype[id].X, (int)_prototype[id].Y, (int)_prototype[id].Width, (int)_prototype[id].Height); ((GameFrame)_prototype[id]).DelayTime = int.Parse(_frame.SelectSingleNode("DelayTime").InnerText); MotionInfo _frameMoveInfo = new MotionInfo(); XmlNode moveInfo = _frame.SelectSingleNode(@"MoveInfo"); _frameMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_frameMoveInfo.FirstDection == "Null") { _frameMoveInfo = null; } else { _frameMoveInfo.IsStanding = false; string temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") { _frameMoveInfo.StandingGround = float.MinValue; } else { _frameMoveInfo.StandingGround = float.Parse(temp); } _frameMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _frameMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _frameMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText) / 10; //Cái này la thang Owner nó sẽ trỏ tới cái gameframe trên prototype //Khi clone ra 1 gameframe mới thì phai set lai cai owner này //trỏ tới đúng đối tượng button mới duoc clone ra //---->>Khong là mọi chuyện hỏng bét. _frameMoveInfo.Owner = _prototype[id]; } ((GameFrame)_prototype[id]).Motion = _frameMoveInfo; return(true); }
public override bool InitOne(ContentManager content, int id) { XmlDocument _doc = new XmlDocument(); _doc.Load(_xmlInfo); XmlNode _frame = _doc.SelectSingleNode(@"//Frame[@id = '" + id.ToString() + "']"); _prototype[id] = new GameFrame(); string _backgroundPath = _frame.SelectSingleNode("BackGround").InnerText; if (_backgroundPath == "Null") { _prototype[id]._nsprite = 0; _prototype[id]._sprite = null; } else { _prototype[id]._nsprite = 1; _prototype[id]._sprite = new GameSprite [_prototype[id]._nsprite]; Texture2D _temp = content.Load<Texture2D>(_backgroundPath); _prototype[id]._sprite[0] = new GameSprite(_temp, 0, 0); } _prototype[id].X = int.Parse(_frame.SelectSingleNode("X").InnerText); _prototype[id].Y = int.Parse(_frame.SelectSingleNode("Y").InnerText); _prototype[id].OffSetX = _prototype[id].X; _prototype[id].OffSetY = _prototype[id].Y; _prototype[id].Width = int.Parse(_frame.SelectSingleNode("Width").InnerText); _prototype[id].Height = int.Parse(_frame.SelectSingleNode("Height").InnerText); _prototype[id].Rect = new Rectangle((int)_prototype[id].X, (int)_prototype[id].Y, (int)_prototype[id].Width, (int)_prototype[id].Height); ((GameFrame)_prototype[id]).DelayTime = int.Parse(_frame.SelectSingleNode("DelayTime").InnerText); MotionInfo _frameMoveInfo = new MotionInfo(); XmlNode moveInfo = _frame.SelectSingleNode(@"MoveInfo"); _frameMoveInfo.FirstDection = moveInfo.SelectSingleNode(@"FirstDirection").InnerText; if (_frameMoveInfo.FirstDection == "Null") _frameMoveInfo = null; else { _frameMoveInfo.IsStanding = false; string temp = moveInfo.SelectSingleNode(@"StandingGround").InnerText; if (temp == "Null") _frameMoveInfo.StandingGround = float.MinValue; else _frameMoveInfo.StandingGround = float.Parse(temp); _frameMoveInfo.Vel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Velocity").SelectSingleNode(@"Y").InnerText)); _frameMoveInfo.Accel = new Vector2(float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"X").InnerText), float.Parse(moveInfo.SelectSingleNode(@"Acceleration").SelectSingleNode(@"Y").InnerText)); _frameMoveInfo.DecelerationRate = float.Parse(moveInfo.SelectSingleNode(@"DecelerationRate").InnerText) / 10; //Cái này la thang Owner nó sẽ trỏ tới cái gameframe trên prototype //Khi clone ra 1 gameframe mới thì phai set lai cai owner này //trỏ tới đúng đối tượng button mới duoc clone ra //---->>Khong là mọi chuyện hỏng bét. _frameMoveInfo.Owner = _prototype[id]; } ((GameFrame)_prototype[id]).Motion = _frameMoveInfo; return true; }