public void Move(Drctn d) { bool isin = true; mTextBox.Text = RedSquare.Crds.LB.x.ToString() + " "; mTextBox.Text += RedSquare.Crds.LB.y.ToString(); mTextBox.Text += "\n"; mTextBox.Text += RedSquare.GetMoved(d, 1).LB.x.ToString() + " "; mTextBox.Text += RedSquare.GetMoved(d, 1).LB.y.ToString(); mTextBox.Text += "\n"; foreach (GameObject gsq in GameObjects) { if (gsq != RedSquare) { if (gsq.Intersect(RedSquare.GetMoved(d, 1))) { isin = false; } } } if (isin) { RedSquare.Move(d, RedSquare.Speed); mTextBox.Text += "Move \n"; } else { mTextBox.Text += " Can`t \n"; isin = false; } }
public RectangleCrds GetMoved(Drctn direction, double delta) { RectangleCrds movedCrds; movedCrds.LB = this.Crds.LB; movedCrds.LT = this.Crds.LT; movedCrds.RB = this.Crds.RB; movedCrds.RT = this.Crds.RT; switch (direction) { case Drctn.Up: movedCrds.LB.y += delta; movedCrds.LT.y += delta; movedCrds.RT.y += delta; movedCrds.RB.y += delta; break; case Drctn.Right: movedCrds.LB.x += delta; movedCrds.LT.x += delta; movedCrds.RT.x += delta; movedCrds.RB.x += delta; break; case Drctn.Down: movedCrds.LB.y -= delta; movedCrds.LT.y -= delta; movedCrds.RT.y -= delta; movedCrds.RB.y -= delta; break; case Drctn.Left: movedCrds.LB.x -= delta; movedCrds.LT.x -= delta; movedCrds.RT.x -= delta; movedCrds.RB.x -= delta; break; } return(movedCrds); }
public void Move(Drctn direction, double delta) { switch (direction) { case Drctn.Up: ChngVrtCrd(delta); break; case Drctn.Right: ChngHrzCrd(delta); break; case Drctn.Down: ChngVrtCrd(-delta); break; case Drctn.Left: ChngHrzCrd(-delta); break; } Refresh(); }