public UnitShopBox(UnitShop parent, GraphicsDevice graphicsDevice, int capacity, Vector2 pos) { this.pos = pos; textBox = new RectBox(graphicsDevice, this.pos, width, textBoxHeight); divisorA = new Line(graphicsDevice, new Vector2(pos.X, textBox.GetBottom()), new Vector2(pos.X + width, textBox.GetBottom()), 5, Color.White); unitBoxes = new UnitShopButton[capacity]; for (int i = 0; i < capacity; i++) { unitBoxes[i] = new UnitShopButton(i, graphicsDevice, new Vector2( pos.X, (i == 0) ? textBox.GetBottom() : unitBoxes[i - 1].GetBottom()), width, unitBoxHeight); unitBoxes[i].buttonPressed += parent.SellEntry; } dimensions = new Vector2(width, textBox.GetHeight() + capacity * unitBoxHeight); }
public EmulatorButton(LTexture img, int w, int h, int x, int y, bool flag, int sizew, int sizeh) { this.color = new LColor(LColor.gray.R, LColor.gray.G, LColor.gray.B, 125); img.LoadTexture(); if (flag) { this.bitmap = img.GetSubTexture(x, y, w, h); } else { this.bitmap = img; } if (bitmap.GetWidth() != sizew || bitmap.GetHeight() != sizeh) { LTexture tmp = bitmap; this.bitmap = bitmap.Scale(sizew, sizeh); if (tmp != null) { tmp.Dispose(); tmp = null; } } this.bounds = new RectBox(0, 0, bitmap.GetWidth(), bitmap.GetHeight()); }
public PBody AddBox(bool fix, RectBox rect, float angle, float density) { PBody body = Box(fix, rect, angle, density); world.AddBody(body); return(body); }
public Actor GetOnlyIntersectingObject(Actor actor, Type cls) { RectBox rect = this.GetActorBounds(actor); lock (this.actorQuery) { this.actorQuery.Init(cls, actor); ActorNode node = GetNodeForActor(actor); if (node == null) { return(null); } do { BSPCollisionNode bspNode = node.GetBSPNode(); Actor result = this.GetOnlyObjectDownTree(actor, rect, this.actorQuery, bspNode); if (result != null) { return(result); } result = this.GetOnlyIntersectingUp(rect, this.actorQuery, actor, bspNode.GetParent()); if (result != null) { return(result); } node = node.GetNext(); } while (node != null); return(this.GetOnlyIntersectingDown(rect, this.actorQuery, actor)); } }
/// <summary> /// 矫正当前图像大小 /// </summary> /// private void CalcBounds() { ActorLayer layer = this.GetLLayer(); if (layer != null) { int width; int height; int cellSize = layer.GetCellSize(); int minY = 0; if (this.image == null) { width = location.X() * cellSize + cellSize; height = location.Y() * cellSize + cellSize; this.boundingRect = new RectBox(width, height, 0, 0); for (minY = 0; minY < 4; ++minY) { this.xs[minY] = width; this.ys[minY] = height; } } else { this.boundingRect = NumberUtils.GetBounds(location.x, location.y, this.image.GetWidth(), this.image.GetHeight(), rotation); } } }
public static LNFollow Action(LNNode followedNode, RectBox rect) { LNFollow follow = new LNFollow(); follow._followedNode = followedNode; follow._boundarySet = true; follow._boundaryFullyCovered = false; follow.winRect = LSystem.screenRect; follow.fullScreenSize = new Vector2f(follow.winRect.width, follow.winRect.height); follow.halfScreenSize = follow.fullScreenSize.Mul(0.5f); follow.leftBoundary = -((rect.x + rect.width) - follow.fullScreenSize.x); follow.rightBoundary = -rect.x; follow.topBoundary = -rect.y; follow.bottomBoundary = -((rect.y + rect.height) - follow.fullScreenSize.y); if (follow.rightBoundary < follow.leftBoundary) { follow.rightBoundary = follow.leftBoundary = (follow.leftBoundary + follow.rightBoundary) / 2; } if (follow.topBoundary < follow.bottomBoundary) { follow.topBoundary = follow.bottomBoundary = (follow.topBoundary + follow.bottomBoundary) / 2; } if ((follow.topBoundary == follow.bottomBoundary) && (follow.leftBoundary == follow.rightBoundary)) { follow._boundaryFullyCovered = true; } return(follow); }
/// <summary> /// 决定当前对象旋转方向 /// </summary> /// /// <param name="rotation_0"></param> public override void SetRotation(float rotation_0) { if (rotation_0 >= 360) { if (rotation_0 < 720) { rotation_0 -= 360; } else { rotation_0 %= 360; } } else if (rotation_0 < 0) { if (rotation_0 >= -360) { rotation_0 += 360; } else { rotation_0 = 360 + rotation_0 % 360; } } if (this.rotation != rotation_0) { this.rotation = rotation_0; this.boundingRect = null; this.SizeChanged(); } }
public void SetImage(LTexture img) { if (img != null || this.image != null) { bool sizeChanged = true; if (img != null && this.image != null && img.GetWidth() == this.image.GetWidth() && img.GetHeight() == this.image.GetHeight()) { sizeChanged = false; } if (image != null && image.GetParent() == null && image.IsChildAllClose()) { if (image != null) { image.Destroy(); image = null; } } this.image = img; if (sizeChanged) { this.boundingRect = null; this.SizeChanged(); } } }
/// <summary> /// 检查矩形与圆形是否发生了碰撞 /// </summary> /// /// <param name="rect1"></param> /// <param name="rect2"></param> /// <returns></returns> public static bool IsRectToCirc(RectBox rect1, RectBox rect2) { float radius = rect2.GetWidth() / 2; Point middle = GetMiddlePoint(rect2); Point upperLeft = new Point(rect1.GetMinX(), rect1.GetMinY()); Point upperRight = new Point(rect1.GetMaxX(), rect1.GetMinY()); Point downLeft = new Point(rect1.GetMinX(), rect1.GetMaxY()); Point downRight = new Point(rect1.GetMaxX(), rect1.GetMaxY()); bool collided = true; if (!IsPointToLine(upperLeft, upperRight, middle, radius)) { if (!IsPointToLine(upperRight, downRight, middle, radius)) { if (!IsPointToLine(upperLeft, downLeft, middle, radius)) { if (!IsPointToLine(downLeft, downRight, middle, radius)) { collided = false; } } } } return(collided); }
/// <summary> /// 获得两个矩形间距离 /// </summary> /// /// <param name="box1"></param> /// <param name="box2"></param> /// <returns></returns> public static float GetDistance(RectBox box1, RectBox box2) { float xdiff = box1.x - box2.x; float ydiff = box1.y - box2.y; return(Loon.Utils.MathUtils.Sqrt(xdiff * xdiff + ydiff * ydiff)); }
/// <summary> /// 判断指定大小的两组像素是否相交 /// </summary> /// /// <param name="rectA"></param> /// <param name="dataA"></param> /// <param name="rectB"></param> /// <param name="dataB"></param> /// <returns></returns> public static bool Intersect(RectBox rectA, int[] dataA, RectBox rectB, int[] dataB) { int top = (int)Loon.Utils.MathUtils.Max(rectA.GetY(), rectB.GetY()); int bottom = (int)Loon.Utils.MathUtils.Min(rectA.GetBottom(), rectB.GetBottom()); int left = (int)Loon.Utils.MathUtils.Max(rectA.GetX(), rectB.GetX()); int right = (int)Loon.Utils.MathUtils.Min(rectA.GetRight(), rectB.GetRight()); for (int y = top; y < bottom; y++) { for (int x = left; x < right; x++) { int colorA = dataA[(int)((x - rectA.x) + (y - rectA.y) * rectA.width)]; int colorB = dataB[(int)((x - rectB.x) + (y - rectB.y) * rectB.width)]; if ((int)(((uint)colorA) >> 24) != 0 && (int)(((uint)colorB) >> 24) != 0) { return(true); } } } return(false); }
public StageViewBox(GraphicsDevice graphicsDevice, Stage stage, SpriteFont textFont, int stageNumber, int stageIndex, Vector2 pos) { this.stage = stage; this.pos = pos; this.textFont = textFont; this.stageIndex = stageIndex; text = $"Stage {stageNumber} : {stageIndex}"; textBox = new RectBox(graphicsDevice, this.pos, width, textBoxHeight); divisorA = new Line(graphicsDevice, new Vector2(pos.X, textBox.GetBottom()), new Vector2(pos.X + width, textBox.GetBottom()), 5, Color.White); stageIconBoxes = new RectBox[stage.Length]; for (int i = 0; i < stage.Length; i++) { stageIconBoxes[i] = new RectBox(graphicsDevice, new Vector2( pos.X, (i == 0)? textBox.GetBottom() : stageIconBoxes[i - 1].GetBottom()), width, stageIconBoxHeight); } }
public LObjectCamera(RectBox r, object f, int width, int height, int horBorderPixel_0, int vertBorderPixel_1, Vector2f maxSpeed_2) { this.cameraX = 0; this.cameraY = 0; this.renderWidth = width; this.renderHeight = height; this.follow = new Bind(f); this.horBorderPixel = horBorderPixel_0; this.vertBorderPixel = vertBorderPixel_1; this.maxSpeed = maxSpeed_2; if (follow != null) { this.cameraX = follow.GetX() - (this.renderWidth / 2); this.cameraY = follow.GetY() - (this.renderHeight / 2); } this.cameraRect = r; this.visibleRect = new RectBox(cameraX - horBorderPixel_0, cameraY - vertBorderPixel_1, renderWidth + horBorderPixel_0, renderHeight + vertBorderPixel_1); this.moveRect = new RectBox(cameraX - horBorderPixel_0, cameraY - vertBorderPixel_1, renderWidth + horBorderPixel_0, renderHeight + vertBorderPixel_1); this.UpdateCamera(); }
/// <summary> /// 参考指定大小根据Layer范围生成一组不重复的随机坐标 /// </summary> /// /// <param name="act"></param> /// <param name="count"></param> /// <returns></returns> public RectBox[] GetRandomLayerLocation(int nx, int ny, int nw, int nh, int count) { if (isClose) { return(null); } if (count <= 0) { throw new Exception("count <= 0 !"); } int layerWidth = GetWidth(); int layerHeight = GetHeight(); int actorWidth = (nw > 48) ? nw : 48; int actorHeight = (nh > 48) ? nh : 48; int x = nx / actorWidth; int y = ny / actorHeight; int row = layerWidth / actorWidth; int col = layerHeight / actorHeight; RectBox[] randoms = new RectBox[count]; int oldRx = 0, oldRy = 0; int index = 0; for (int i = 0; i < count * 100; i++) { if (index >= count) { return(randoms); } int rx = LSystem.random.Next(row); int ry = LSystem.random.Next(col); if (oldRx != rx && oldRy != ry && rx != x && ry != y && rx * actorWidth != nx && ry * actorHeight != ny) { bool stop = false; for (int j = 0; j < index; j++) { if (randoms[j].x == rx && randoms[j].y == ry && oldRx != x && oldRy != y && rx * actorWidth != nx && ry * actorHeight != ny) { stop = true; break; } } if (stop) { continue; } randoms[index] = new RectBox(rx * actorWidth, ry * actorHeight, actorWidth, actorHeight); oldRx = rx; oldRy = ry; index++; } } return(null); }
public virtual GLEx Draw(Painter texture, RectBox destRect, RectBox srcRect, LColor color, float rotation) { if (rotation == 0) { return(Draw(texture, destRect.x, destRect.y, destRect.width, destRect.height, srcRect.x, srcRect.y, srcRect.width, srcRect.height, color)); } return(Draw(texture, destRect.x, destRect.y, destRect.width, destRect.height, srcRect.x, srcRect.y, srcRect.width, srcRect.height, color, rotation, null, default)); }
public void Draw(LTexture texture, Vector2f pos, Vector2f origin, float scale, float rotation, RectBox src, bool flipX, bool flipY) { Draw(texture, pos.x, pos.y, origin.x, origin.y, src.width, src.height, scale, scale, rotation, src.x, src.y, src.width, src.height, flipX, flipY, false); }
public virtual void OnClientSizeChanged(object sender, EventArgs e) { if (_game != null) { RectBox rect = GetScreenDimension(); _game.OnSizeChanged(rect.Width(), rect.Height()); } }
public virtual void SetRotation(float r) { this.rotation = r; if (rect != null) { rect = NumberUtils.GetBounds(location.x, location.y, GetWidth(), GetHeight(), r, rect); } }
/// <summary> /// 判断两个圆形是否发生了碰撞 /// </summary> /// /// <param name="rect1"></param> /// <param name="rect2"></param> /// <returns></returns> public static bool IsCircToCirc(RectBox rect1, RectBox rect2) { Point middle1 = GetMiddlePoint(rect1); Point middle2 = GetMiddlePoint(rect2); float distance = middle1.DistanceTo(middle2); float radius1 = rect1.GetWidth() / 2; float radius2 = rect2.GetWidth() / 2; return((distance - radius2) < radius1); }
public OutEffect(LTexture t, RectBox limit, int code) { this.texture = t; this.type = code; this.width = t.Width; this.height = t.Height; this.multiples = 1; this.limit = limit; this.visible = true; }
public IList GetIntersectingObjects(Actor actor, Type cls) { RectBox r = this.GetActorBounds(actor); lock (this.actorQuery) { this.actorQuery.Init(cls, actor); return(this.GetIntersectingObjects(r.ToFloat(), this.actorQuery)); } }
public void Draw(int idx, SpriteBatch batch, float x, float y, float rotation, float sx, float sy, LColor color) { RectBox rect = this._rectList[idx]; batch.SetColor(color); batch.Draw(_texture, x, y, anchor.x, anchor.y, rect.width, rect.height, sx, sy, MathUtils.ToDegrees(rotation), rect.x, rect.y, rect.width, rect.height, false, false); batch.ResetColor(); }
public bool IsCollision(SpriteBatchObject o) { RectBox src = GetCollisionArea(); RectBox dst = o.GetCollisionArea(); if (src.Intersects(dst)) { return(true); } return(false); }
public virtual void DrawRectangle(RectBox rect, float r, float g, float b, float a) { GLEx gl = GLEx.Self; if (gl != null) { gl.SetColor(r, g, b, a); gl.FillRect(rect.x, rect.y, rect.width, rect.height); gl.ResetColor(); } }
protected internal Vector2f Measure(string cs) { if (cs.Length == 0) { return(new Vector2f()); } Vector2f zero = new Vector2f(); zero.y = this.lineSpacing; float min = 0f; int count = 0; float z = 0f; bool flag = true; for (int i = 0; i < cs.Length; i++) { if (cs[i] != '\r') { if (cs[i] == '\n') { zero.x += MathUtils.Max(z, 0f); z = 0f; min = MathUtils.Max(zero.x, min); zero = new Vector2f(); zero.y = this.lineSpacing; flag = true; count++; } else { float[] vector2 = this.kerning[this.CharacterIndex(cs [i])]; if (flag) { vector2[0] = MathUtils.Max(vector2[0], 0f); } else { zero.x += this.spacing + z; } zero.x += vector2[0] + vector2[1]; z = vector2[2]; RectBox rectangle = this.cropping[this .CharacterIndex(cs[i])]; zero.y = MathUtils.Max(zero.y, rectangle.height); flag = false; } } } zero.x += MathUtils.Max(z, 0f); zero.y += count * this.lineSpacing; zero.x = MathUtils.Max(zero.x, min); return(zero); }
/// <summary> /// 参考指定角色根据Layer范围生成一组不重复的随机坐标 /// </summary> /// /// <param name="actor"></param> /// <param name="count"></param> /// <returns></returns> public RectBox[] GetRandomLayerLocation(Actor actor, int count) { if (isClose) { return(null); } RectBox rect = actor.GetRectBox(); return(GetRandomLayerLocation((int)rect.x, (int)rect.y, rect.width, rect.height, count)); }
public bool CheckCollision(Actor actor) { obj0 = actor.GetRectBox(); dx = MathUtils.Abs(obj0.GetCenterX() - x); dy = MathUtils.Abs(obj0.GetCenterY() - y); dist = MathUtils.Sqrt(dx * dx + dy * dy); return(dist <= this.r); }
internal void AddLayer(float x, float y, ActorLayer g) { if (g.IsBounded()) { x = this.LimitValue(x, g.GetWidth() - GetWidth()); y = this.LimitValue(y, g.GetHeight() - GetHeight()); } this.boundingRect = null; this.SetLayer(g); this.SetLocation(x, y); }
protected virtual void SetSize(int w, int h) { if (boundingRect != null) { boundingRect.SetBounds(location.x, location.y, w, h); } else { boundingRect = new RectBox(location.x, location.y, w, h); } }
public void SetPhysicsRect(float x, float y, float w, float h) { if (this._physicsRect == null) { this._physicsRect = new RectBox(x, y, w, h); } else { this._physicsRect.SetBounds(x, y, w, h); } }