public GfxStr(string text, Point pos, int edge) { Texture = Game1.content.Load <SpriteFont>("DefaultFont"); Text = text; Edge = edge; Bound = new Rectangle(pos, Method2D.VtP(Texture.MeasureString(Text)) + new Point(2 * Edge, 2 * Edge)); }
public GfxStr(string _text, Point pos) { Texture = Game1.content.Load <SpriteFont>("DefaultFont"); Text = _text; Pos = pos; Bound = new Rectangle(pos, Method2D.VtP(Texture.MeasureString(Text))); }
public void MoveByVector(Point v, double speed) // 벡터 v의 방향으로 speed의 속도로 등속운동한다. { double N = Method2D.Distance(new Point(0, 0), v); int Dis_X = (int)(v.X * speed / N); int Dis_Y = (int)(v.Y * speed / N); Pos = new Point(Bound.X + Dis_X, Bound.Y + Dis_Y); }
public bool RContains(Point p)//만약 Gfx의 rotate값이 0이 아닐 경우, RContains 함수가 정확합니다. 다만, 보시다시피, 비싼 계산을 요구합니다. { Vector2 v = Method2D.PtV(p); Vector3 RO = new Vector3(Pos.X + (ROrigin.X * Bound.Width) / Texture.Width, Pos.Y + (ROrigin.Y * Bound.Height) / Texture.Height, 0); v = Vector2.Transform(v, Matrix.CreateTranslation(-RO) * Matrix.CreateRotationZ(-Rotate) * Matrix.CreateTranslation(RO)); return(Bound.Contains(Method2D.VtP(v))); }
public float Rotate; // 회전각. radian을 따릅니다. public void MoveTo(int x, int y, double speed) // (x,y)를 향해 등속운동. { double N = Method2D.Distance(new Point(x, y), Pos); //두 물체 사이의 거리 if (N < speed) //거리가 스피드보다 가까우면 도착. { Pos = new Point(x, y); return; } Vector2 v = new Vector2(x - Pos.X, y - Pos.Y); v.Normalize(); v = new Vector2((float)speed * v.X, (float)speed * v.Y); Pos = new Point(Bound.X + (int)(v.X), Bound.Y + (int)(v.Y)); }
public static void Draw(Gfx2D gfx, Color c) => spriteBatch.Draw(gfx.Texture, new Rectangle(gfx.Pos.X + (gfx.ROrigin.X * gfx.Bound.Width) / gfx.Texture.Width, gfx.Pos.Y + (gfx.ROrigin.Y * gfx.Bound.Height) / gfx.Texture.Height, gfx.Bound.Width, gfx.Bound.Height), null, c, gfx.Rotate, Method2D.PtV(gfx.ROrigin), SpriteEffects.None, 0);