protected override void OnPointerClick(FPoint relPositionPoint, InputState istate) { if (!IsEnabled) return; if (suppressClick) return; if (!IsCursorOnButton(istate)) return; lastClickTime = MonoSAMGame.CurrentTime.GetTotalElapsedSeconds(); if (IsTripleClickMode) { multiClickCounter++; if (multiClickCounter >= 3) { multiClickCounter = 0; OnTriplePress(istate); } } else if (IsDoubleClickMode) { multiClickCounter++; if (multiClickCounter >= 2) { multiClickCounter = 0; OnDoublePress(istate); } } else if (IsSingleClickMode) { OnPress(istate); } }
public EllipsePieceSegment(FPoint center, float radiusX, float radiusY, float aStart = 0, float aEnd = FloatMath.TAU, CircularDirection dir = CircularDirection.CW) { this.center = center; this.radiusX = radiusX; this.radiusY = radiusY; this.direction = dir; angleStart = aStart; angleEnd = aEnd; if (dir == CircularDirection.CW) { Length = FloatMath.TAU * FloatMath.Sqrt((radiusX * radiusX + radiusY * radiusY) / 2f) * (angleEnd - angleStart) / FloatMath.TAU; Boundings = GeometryHelper.CalculateEllipseSegmentsBoundingBox(center.X, center.Y, radiusX, radiusY, angleStart, angleEnd); } else { // inverted Length = FloatMath.TAU * FloatMath.Sqrt((radiusX * radiusX + radiusY * radiusY) / 2f) * (angleStart - angleEnd) / FloatMath.TAU; Boundings = GeometryHelper.CalculateEllipseSegmentsBoundingBox(center.X, center.Y, radiusX, radiusY, angleEnd, angleStart); } }
public InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs) { Mouse = ms; Keyboard = ks; TouchPanel = ts; GamePad = gs; if (Mouse.LeftButton == ButtonState.Pressed) { IsDown = true; PointerPosition = adapter.PointToScreen(Mouse.Position); } else if (TouchPanel.Count > 0) { IsDown = true; PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint()); } else { IsDown = false; PointerPosition = FPoint.Zero; } currentKeyState = new Dictionary<Keys, bool>(0); }
public void ComputeBoundingBox() { float minx = float.MaxValue; float miny = float.MaxValue; float minz = float.MaxValue; float maxx = float.MinValue; float maxy = float.MinValue; float maxz = float.MinValue; int noCoords = _coordinates.Count / 3; for (int i = 0; i < noCoords; i++) { int coordIndex = 3 * i; float x = _coordinates[coordIndex]; float y = _coordinates[coordIndex + 1]; float z = _coordinates[coordIndex + 2]; if (minx > x) minx = x; if (miny > y) miny = y; if (minz > z) minz = z; if (maxx < x) maxx = x; if (maxy < y) maxy = y; if (maxz < z) maxz = z; } _minBBox = new FPoint(minx,miny,minz); _maxBBox = new FPoint(maxx, maxy, maxz); }
public CirclePieceSegment(FPoint center, float radius, float aStart = 0, float aEnd = FloatMath.TAU) { this.center = center; this.radius = radius; if (aStart < aEnd) { direction = CircularDirection.CW; angleStart = aStart; angleEnd = aEnd; } else { direction = CircularDirection.CCW; angleStart = aEnd; angleEnd = aStart; } Length = (2 * FloatMath.PI * radius) * (angleEnd - angleStart) / FloatMath.TAU; directionZero = new Vector2(radius, 0); Boundings = GeometryHelper.CalculateEllipseSegmentsBoundingBox(center.X, center.Y, radius, radius, angleStart, angleEnd); }
private InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs, InputState prev) { Mouse = ms; Keyboard = ks; TouchPanel = ts; GamePad = gs; if (Mouse.LeftButton == ButtonState.Pressed) { IsDown = true; PointerPosition = adapter.PointToScreen(Mouse.Position); } else if (TouchPanel.Count > 0) { IsDown = true; PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint()); } else { IsDown = false; PointerPosition = prev.PointerPosition; } IsJustDown = IsDown && !prev.IsDown; IsJustUp = !IsDown && prev.IsDown; lastKeyState = prev.currentKeyState; currentKeyState = lastKeyState.ToDictionary(p => p.Key, p => ks.IsKeyDown(p.Key)); }
public VectorPathBuilder HalfEllipseDown(float rx, float ry) { segments.Add(new EllipsePieceSegment(new FPoint(current.X, current.Y + ry * scale), rx * scale, ry * scale, FloatMath.RAD_NEG_090, FloatMath.RAD_POS_090)); current = new FPoint(current.X, current.Y + 2 * ry * scale); return this; }
public VectorPathBuilder HalfCircleDown(float r) { segments.Add(new CirclePieceSegment(new FPoint(current.X, current.Y + r * scale), r * scale, FloatMath.RAD_NEG_090, FloatMath.RAD_POS_090)); current = new FPoint(current.X, current.Y + 2 * r * scale); return this; }
public VectorPathBuilder HalfCircleRight(float r) { segments.Add(new CirclePieceSegment(new FPoint(current.X + r * scale, current.Y), r * scale, FloatMath.RAD_POS_180, FloatMath.RAD_000)); current = new FPoint(current.X + 2 * r * scale, current.Y); return this; }
public VectorPathBuilder LineTo(float x, float y) { var next = new FPoint(x * scale, y * scale); segments.Add(new LineSegment(current, next)); current = next; return this; }
protected override void RecalculatePosition() { if (HUD == null) return; Size = new FSize(HUD.Width, HUD.Height); Position = new FPoint(HUD.Left, HUD.Top); BoundingRectangle = new FRectangle(Position, Size); PositionInvalidated = false; }
public LineSegment(FPoint start, FPoint end) { startPoint = start; endPoint = end; direction = (end - start).NormalizedCopy(); Length = (end - start).Length(); Boundings = new FRectangle(FloatMath.Min(startPoint.X, endPoint.X), FloatMath.Min(startPoint.Y, endPoint.Y), FloatMath.Abs(startPoint.X - endPoint.X), FloatMath.Abs(startPoint.Y - endPoint.Y)); }
private void StartDrag(InputState istate) { mouseStartPos = istate.PointerPosition; startOffset = Screen.MapOffset; dragSpeed = Vector2.Zero; lastMousePos = istate.PointerPosition; lastMousePosTimer = 0f; isDragging = true; }
public HUDPauseButton() { RelativePosition = new FPoint(12, 12); Size = new FSize(DIAMETER, DIAMETER); Alignment = HUDAlignment.TOPRIGHT; #if DEBUG ClickMode = HUDButtonClickMode.Single | HUDButtonClickMode.InstantHold; #else ClickMode = HUDButtonClickMode.Single; #endif }
public HUDPauseMenuButton(HUDPauseButton owner, string buttonText, int buttonDepth, int buttonIndex, int totalButtonCount, Action buttonAction) { baseButton = owner; btnIndex = buttonIndex; btnCount = totalButtonCount; btnText = buttonText; btnAction = buttonAction; Depth = buttonDepth; RelativePosition = new FPoint(12, 12); Size = new FSize(0, 0); Alignment = owner.Alignment; }
protected virtual void OnPointerClick(FPoint relPositionPoint, InputState istate) { /* OVERRIDE ME */ }
protected override bool OnPointerUp(FPoint relPositionPoint, InputState istate) => IsVisible;
public OverworldNode_MP(GDOverworldScreen scrn, FPoint pos) : base(scrn, pos, L10NImpl.STR_WORLD_MULTIPLAYER, Levels.WORLD_ID_MULTIPLAYER) { AddOperationDelayed(new NetworkAnimationTriggerOperation(), NetworkAnimationTriggerOperation.INITIAL_DELAY); _ustate = UnlockManager.IsUnlocked(Levels.WORLD_ID_MULTIPLAYER, false); }
public Window(FPoint topLeft, FPoint bottomRight) { Domain = new PointRange(topLeft.X, bottomRight.X); Range = new PointRange(bottomRight.Y, topLeft.Y); }
/// <summary> /// Dessine le rectangle sous la coordonné /// </summary> /// <param name="coords"></param> private void DrawSelection(FPoint coords) { DrawRect(BorderOfSelection, InteriorOfSelection, coords.X * GridRectWidth, coords.Y * GridRectHeight, GridRectWidth, GridRectHeight); }
protected override void OnPointerDown(FPoint relPositionPoint, InputState istate) { HUD.Screen.PushNotification("HUDSpeedBaseButton :: Click"); if (!isOpened) { HUD.Screen.PushNotification("HUDSpeedBaseButton :: opening menu"); Open(); } else { HUD.Screen.PushNotification("HUDSpeedBaseButton :: closing menu"); Close(); } }
public PointerEventArgs(FPoint p) { X = p.X; Y = p.Y; }
/// <summary> /// Dessine le rectangle sous la coordonné /// </summary> /// <param name="coords"></param> private void DrawSelection(FPoint coords) { if (coords.X < 9 && coords.Y < 9) DrawRect(BorderOfSelection, InteriorOfSelection, coords.X * GridRectWidth, coords.Y * GridRectHeight, GridRectWidth, GridRectHeight); else if (coords.X >= 9 && coords.Y >= 9) DrawRect(BorderOfSelection, InteriorOfSelection, coords.X * GridRectWidth, coords.Y * GridRectHeight, Width - coords.X * GridRectWidth, Height - coords.Y * GridRectHeight); else if (coords.X >= 9) DrawRect(BorderOfSelection, InteriorOfSelection, coords.X * GridRectWidth, coords.Y * GridRectHeight, Width - coords.X * GridRectWidth, GridRectHeight); else if (coords.Y >= 9) DrawRect(BorderOfSelection, InteriorOfSelection, coords.X * GridRectWidth, coords.Y * GridRectHeight, GridRectWidth, Height - coords.Y * GridRectHeight); }
public WarpGameEndNode(GDWorldMapScreen scrn, WarpNodeBlueprint bp) : base(scrn, GDConstants.ORDER_MAP_NODE) { Position = new FPoint(bp.X, bp.Y); DrawingBoundingBox = new FSize(DIAMETER, DIAMETER); Blueprint = bp; }
public WallStub CanInsertWallStub(FPoint p1, FPoint p2, ILeveleditorStub ign) { if (p1.X <= 0 && p2.X <= 0) { return(null); } if (p1.Y <= 0 && p2.Y <= 0) { return(null); } if (p1.X >= LevelData.Width * GDConstants.TILE_WIDTH && p2.X >= LevelData.Width * GDConstants.TILE_WIDTH) { return(null); } if (p1.Y >= LevelData.Height * GDConstants.TILE_WIDTH && p2.Y >= LevelData.Height * GDConstants.TILE_WIDTH) { return(null); } if (p1 == p2) { return(null); } if (p1.X <= (-4) * GDConstants.TILE_WIDTH) { return(null); } if (p1.Y <= (-4) * GDConstants.TILE_WIDTH) { return(null); } if (p1.X >= (LevelData.Width + 4) * GDConstants.TILE_WIDTH) { return(null); } if (p1.Y >= (LevelData.Height + 4) * GDConstants.TILE_WIDTH) { return(null); } if (p2.X <= (-4) * GDConstants.TILE_WIDTH) { return(null); } if (p2.Y <= (-4) * GDConstants.TILE_WIDTH) { return(null); } if (p2.X >= (LevelData.Width + 4) * GDConstants.TILE_WIDTH) { return(null); } if (p2.Y >= (LevelData.Height + 4) * GDConstants.TILE_WIDTH) { return(null); } WallStub s = new WallStub(this, p1, p2); foreach (var stub in GetEntities <ILeveleditorStub>().Where(stub => stub != ign)) { if (stub.CollidesWith(s)) { return(null); } } return(s); }
protected override bool OnPointerDown(FPoint relPositionPoint, InputState istate) => true;
protected override void OnPointerClick(FPoint relPositionPoint, InputState istate) { if (_rectHeader1.Contains(relPositionPoint)) { var tabNext = 0; tabTimer = tabNext * TAB_SWITCHTIME; } else if (_rectHeader2.Contains(relPositionPoint)) { var tabNext = 1; tabTimer = tabNext * TAB_SWITCHTIME; } else if (_rectHeader3.Contains(relPositionPoint)) { var tabNext = 2; tabTimer = tabNext * TAB_SWITCHTIME; } else if (_rectRow1.Contains(relPositionPoint)) { tabTimer = tab * TAB_SWITCHTIME; switch (tab) { case 0: if (node.LevelData.HasCompletedExact(FractionDifficulty.DIFF_0)) { Toast_1(L10N.TF(L10NImpl.STR_INFOTOAST_1, node.LevelData.GetTimeString(FractionDifficulty.DIFF_0, true))); } else { Toast_4(L10N.TF(L10NImpl.STR_INFOTOAST_4, FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_0))); } break; case 1: Toast_2(L10N.TF(L10NImpl.STR_INFOTOAST_2, TimeExtension.FormatMilliseconds(node.LevelData.Data[FractionDifficulty.DIFF_0].GlobalBestTime, true))); break; case 2: Toast_3(L10N.TF(L10NImpl.STR_INFOTOAST_3, PositiveOrZero(node.LevelData.Data[FractionDifficulty.DIFF_0].GlobalCompletionCount), FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_0))); break; default: SAMLog.Error("INFD::EnumSwitch_OPC1", "value: " + tab); break; } } else if (_rectRow2.Contains(relPositionPoint)) { tabTimer = tab * TAB_SWITCHTIME; switch (tab) { case 0: if (node.LevelData.HasCompletedExact(FractionDifficulty.DIFF_1)) { Toast_1(L10N.TF(L10NImpl.STR_INFOTOAST_1, node.LevelData.GetTimeString(FractionDifficulty.DIFF_1, true))); } else { Toast_4(L10N.TF(L10NImpl.STR_INFOTOAST_4, FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_1))); } break; case 1: Toast_2(L10N.TF(L10NImpl.STR_INFOTOAST_2, TimeExtension.FormatMilliseconds(node.LevelData.Data[FractionDifficulty.DIFF_1].GlobalBestTime, true))); break; case 2: Toast_3(L10N.TF(L10NImpl.STR_INFOTOAST_3, PositiveOrZero(node.LevelData.Data[FractionDifficulty.DIFF_1].GlobalCompletionCount), FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_1))); break; default: SAMLog.Error("INFD::EnumSwitch_OPC2", "value: " + tab); break; } } else if (_rectRow3.Contains(relPositionPoint)) { tabTimer = tab * TAB_SWITCHTIME; switch (tab) { case 0: if (node.LevelData.HasCompletedExact(FractionDifficulty.DIFF_2)) { Toast_1(L10N.TF(L10NImpl.STR_INFOTOAST_1, node.LevelData.GetTimeString(FractionDifficulty.DIFF_2, true))); } else { Toast_4(L10N.TF(L10NImpl.STR_INFOTOAST_4, FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_2))); } break; case 1: Toast_1(L10N.TF(L10NImpl.STR_INFOTOAST_2, TimeExtension.FormatMilliseconds(node.LevelData.Data[FractionDifficulty.DIFF_2].GlobalBestTime, true))); break; case 2: Toast_2(L10N.TF(L10NImpl.STR_INFOTOAST_3, PositiveOrZero(node.LevelData.Data[FractionDifficulty.DIFF_2].GlobalCompletionCount), FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_2))); break; default: SAMLog.Error("INFD::EnumSwitch_OPC3", "value: " + tab); break; } } else if (_rectRow4.Contains(relPositionPoint)) { tabTimer = tab * TAB_SWITCHTIME; switch (tab) { case 0: if (node.LevelData.HasCompletedExact(FractionDifficulty.DIFF_3)) { Toast_1(L10N.TF(L10NImpl.STR_INFOTOAST_1, node.LevelData.GetTimeString(FractionDifficulty.DIFF_3, true))); } else { Toast_4(L10N.TF(L10NImpl.STR_INFOTOAST_4, FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_3))); } break; case 1: Toast_2(L10N.TF(L10NImpl.STR_INFOTOAST_2, TimeExtension.FormatMilliseconds(node.LevelData.Data[FractionDifficulty.DIFF_3].GlobalBestTime, true))); break; case 2: Toast_3(L10N.TF(L10NImpl.STR_INFOTOAST_3, PositiveOrZero(node.LevelData.Data[FractionDifficulty.DIFF_3].GlobalCompletionCount), FractionDifficultyHelper.GetDescription(FractionDifficulty.DIFF_3))); break; default: SAMLog.Error("INFD::EnumSwitch_OPC4", "value: " + tab); break; } } else { var tabNext = (int)(tabTimer / TAB_SWITCHTIME + 1) % 3; tabTimer = tabNext * TAB_SWITCHTIME; } }
// ReSharper disable RedundantCheckBeforeAssignment protected override void DoUpdate(SAMTime gameTime, InputState istate) { if (!FloatMath.FloatEquals(Size.Width, HUD.Width)) { Size = new FSize(HUD.Width, Height); } var sel = ((GDWorldHUD)HUD).SelectedNode; if (sel == null && progressMove > 0) { // DISAPPEAR if (!(FloatMath.IsOne(progressMove) && istate.IsRealDown)) { FloatMath.ProgressDec(ref progressMove, gameTime.ElapsedSeconds * SPEED_MOVE); FloatMath.ProgressInc(ref progressBlend, gameTime.ElapsedSeconds * SPEED_BLEND); } if (FloatMath.IsZero(progressMove)) { displayNode = null; progressMove = 0; progressBlend = 1; } } else if (sel != null && displayNode == null) { // START APPEAR displayNode = sel; progressMove = 0; progressBlend = 1; text.Text = "Level " + displayNode.Blueprint.Name + " : " + displayNode.Blueprint.FullName; } else if (sel != null && sel != displayNode) { // BLEND AWAY FROM CURRENT FloatMath.ProgressInc(ref progressMove, gameTime.ElapsedSeconds * SPEED_MOVE); FloatMath.ProgressDec(ref progressBlend, gameTime.ElapsedSeconds * SPEED_BLEND); if (FloatMath.IsZero(progressBlend)) { displayNode = sel; text.Text = "Level " + displayNode.Blueprint.Name + " : " + displayNode.Blueprint.FullName; } } else if (sel != null && sel == displayNode && (progressBlend < 1 || progressMove < 1)) { // BLEND INTO OTHER | APPEAR FloatMath.ProgressInc(ref progressMove, gameTime.ElapsedSeconds * SPEED_MOVE); FloatMath.ProgressInc(ref progressBlend, gameTime.ElapsedSeconds * SPEED_BLEND); } var rp = new FPoint(0, (1 - progressMove) * -Height); if (rp != RelativePosition) { RelativePosition = rp; Revalidate(); } text.TextColor = FlatColors.TextHUD * progressBlend; IsVisible = FloatMath.IsNotZero(progressMove); }
private List <Tuple <List <Vector2>, ICannonBlueprint, float> > FindBulletPaths(LevelBlueprint lvl, World world, int sourceID, FPoint spawnPoint, Vector2 spawnVeloc, List <Vector2> fullpath, float scale, float lifetime) { var none = new List <Tuple <List <Vector2>, ICannonBlueprint, float> >(); // path, cannon, quality fullpath = fullpath.ToList(); object collisionUserObject = null; Contact collisionContact = null; var farseerBullet = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(scale * Bullet.BULLET_DIAMETER / 2), 1, ConvertUnits2.ToSimUnits(spawnPoint), BodyType.Dynamic, null); farseerBullet.LinearVelocity = ConvertUnits.ToSimUnits(spawnVeloc); farseerBullet.CollidesWith = Category.All; farseerBullet.Restitution = 1f; // Bouncability, 1=bounce always elastic farseerBullet.AngularDamping = 1f; // Practically no angular rotation farseerBullet.Friction = 0f; farseerBullet.LinearDamping = 0f; // no slowing down farseerBullet.OnCollision += (fa, fb, cobj) => { collisionUserObject = fb.UserData; collisionContact = cobj; if (fb.UserData is GlassBlockBlueprint) { return(true); } if (fb.UserData is MirrorBlockBlueprint) { return(true); } if (fb.UserData is MirrorCircleBlueprint) { return(true); } if (fb.UserData is MarkerCollisionBorder) { return(true); } return(false); }; farseerBullet.AngularVelocity = 0; fullpath.Add(spawnPoint.ToVec2D()); for (;;) { collisionUserObject = null; foreach (var bh in lvl.BlueprintBlackHoles) { var pp = ConvertUnits.ToDisplayUnits(farseerBullet.Position) - new Vector2(bh.X, bh.Y); var force = bh.Power / pp.LengthSquared(); var vecForce = pp.WithLength(force); farseerBullet.ApplyForce(ConvertUnits.ToSimUnits(vecForce)); } world.Step(1 / SIMULATION_UPS); // x UPS lifetime += 1 / SIMULATION_UPS; fullpath.Add(ConvertUnits2.ToDisplayUnitsPoint(farseerBullet.Position).ToVec2D()); if (collisionUserObject is PortalBlueprint) { var veloc = ConvertUnits.ToDisplayUnits(farseerBullet.LinearVelocity); world.RemoveBody(farseerBullet); var fPortal = (PortalBlueprint)collisionUserObject; Vector2 normal; FixedArray2 <Vector2> t; collisionContact.GetWorldManifold(out normal, out t); bool hit = FloatMath.DiffRadiansAbs(normal.ToAngle(), FloatMath.ToRadians(fPortal.Normal)) < FloatMath.RAD_POS_001; if (!hit) { return(none); } var dat = new List <Tuple <List <Vector2>, ICannonBlueprint, float> >(); foreach (var outportal in lvl.BlueprintPortals.Where(p => p.Side != fPortal.Side && p.Group == fPortal.Group)) { var stretch = outportal.Length / fPortal.Length; var cIn = new FPoint(fPortal.X, fPortal.Y); var cOut = new FPoint(outportal.X, outportal.Y); var cInVecNormal = Vector2.UnitX.RotateDeg(fPortal.Normal); var cInVecDirection = cInVecNormal.RotateWithLength(FloatMath.RAD_POS_090, fPortal.Length / 2f); var cOutVecNormal = Vector2.UnitX.RotateDeg(outportal.Normal); var cOutVecDirection = cOutVecNormal.RotateWithLength(FloatMath.RAD_POS_090, outportal.Length / 2f); var rot = FloatMath.ToRadians(outportal.Normal - fPortal.Normal) + FloatMath.RAD_POS_180; var projec = ConvertUnits.ToDisplayUnits(farseerBullet.Position).ProjectOntoLine(cIn, cInVecDirection); var newVelocity = ConvertUnits.ToDisplayUnits(farseerBullet.LinearVelocity).Rotate(rot); var newStart = cOut + cOutVecDirection * (-projec) + cOutVecNormal * (Portal.WIDTH / 2f) + newVelocity.WithLength(scale * Bullet.BULLET_DIAMETER / 2 + 4); var sub = FindBulletPaths(lvl, world, sourceID, newStart, newVelocity, fullpath, scale * stretch, lifetime); dat.AddRange(sub); } return(dat); } if (collisionUserObject is ICannonBlueprint) { world.RemoveBody(farseerBullet); var tgcannon = (ICannonBlueprint)collisionUserObject; if (tgcannon.CannonID == sourceID) { return(none); } var quality = Math2D.LinePointDistance(ConvertUnits2.ToDisplayUnitsPoint(farseerBullet.Position), ConvertUnits2.ToDisplayUnitsPoint(farseerBullet.Position) + ConvertUnits.ToDisplayUnits(farseerBullet.LinearVelocity), new FPoint(tgcannon.X, tgcannon.Y)); return(new List <Tuple <List <Vector2>, ICannonBlueprint, float> > { Tuple.Create(fullpath, tgcannon, quality) }); } bool oow = (farseerBullet.Position.X < 0 - 64) || (farseerBullet.Position.Y < 0 - 64) || (farseerBullet.Position.X > ConvertUnits.ToSimUnits(lvl.LevelWidth) + 64) || (farseerBullet.Position.Y > ConvertUnits.ToSimUnits(lvl.LevelHeight) + 64); bool ool = (lifetime >= Bullet.MAXIMUM_LIFETIME * LIFETIME_FAC); //if (collisionUserObject != null || oow || ool) //{ // world.RemoveBody(farseerBullet); // return new List<Tuple<List<Vector2>, CannonBlueprint, float>> { Tuple.Create(fullpath, new CannonBlueprint(farseerBullet.Position.X, farseerBullet.Position.Y, 64, 1, 0, FloatMath.GetRangedIntRandom(0, 9999999)), 1f) }; //} if (collisionUserObject is VoidWallBlueprint) { world.RemoveBody(farseerBullet); return(none); } if (collisionUserObject is VoidCircleBlueprint) { world.RemoveBody(farseerBullet); return(none); } if (collisionUserObject is BlackHoleBlueprint) { world.RemoveBody(farseerBullet); return(none); } if (oow || ool) { world.RemoveBody(farseerBullet); return(none); } if (lvl.WrapMode == LevelBlueprint.WRAPMODE_DONUT) { var pbullet = ConvertUnits.ToDisplayUnits(farseerBullet.Position); pbullet.X = (pbullet.X + lvl.LevelWidth) % lvl.LevelWidth; pbullet.Y = (pbullet.Y + lvl.LevelHeight) % lvl.LevelHeight; farseerBullet.Position = ConvertUnits.ToSimUnits(pbullet); } } }
public VectorPathBuilder FullEllipse(float rx, float ry, float cx, float cy) { var ell = new EllipsePieceSegment(new FPoint(cx * scale, cy * scale), rx * scale, ry * scale); segments.Add(ell); current = ell.GetEnd(); return this; }
public void RegisterBlockedLine(FPoint start, FPoint end) { // NOTHING }
/// <summary> /// retourne les coordonnées dans la grille où se trouve la souris /// </summary> /// <returns>Coordonnées de la grille</returns> private FPoint GetGridCoordOfMouse() { FPoint mouse = new FPoint(this.PointToClient(Cursor.Position)); mouse.X = (float)Math.Floor(mouse.X / GridRectWidth); mouse.Y = (float)Math.Floor(mouse.Y / GridRectHeight); //Limite la position au nombre max de la grille if (mouse.X >= GridNumber) mouse.X = GridNumber - 1; if (mouse.Y >= GridNumber) mouse.Y = GridNumber - 1; //MessageBox.Show(mouse.X + " " + mouse.Y); return mouse; }
protected override void DoUpdate(SAMTime gameTime, InputState istate) { switch (_mode) { case 0: _progress += gameTime.ElapsedSeconds / TIME_APPEAR; RelativeCenter = _start; if (_progress >= 1) { _progress = 0; _mode++; } break; case 1: _progress += gameTime.ElapsedSeconds / TIME_STARTWAIT; RelativeCenter = _start; if (_progress >= 1) { _progress = 0; _mode++; } break; case 2: _progress += gameTime.ElapsedSeconds / TIME_MOVE; RelativeCenter = FPoint.Lerp(_start, _end, FloatMath.FunctionEaseInOutCubic(_progress)); if (_progress >= 1) { _progress = 0; _mode++; } break; case 3: _progress += gameTime.ElapsedSeconds / TIME_ENDWAIT; RelativeCenter = _end; if (_progress >= 1) { _progress = 0; _mode++; } break; case 4: _progress += gameTime.ElapsedSeconds / TIME_DISAPPEAR; RelativeCenter = _end; if (_progress >= 1) { _progress = 0; _mode++; } break; case 5: _progress += gameTime.ElapsedSeconds / TIME_DEAD; if (_progress >= 1) { _progress = 0; _mode = 0; } break; default: SAMLog.Error("HTA::EnumSwitch_DU", "value: " + _mode); break; } }
protected override void OnPointerClick(FPoint relPositionPoint, InputState istate) { Remove(); }
/// <summary> /// retourne les coordonnées dans la grille où se trouve la souris /// </summary> /// <returns>Coordonnées de la grille</returns> private FPoint GetGridCoordOfMouse() { FPoint mouse = new FPoint(this.PointToClient(Cursor.Position)); mouse.X = (float)Math.Floor(mouse.X / GridRectWidth); mouse.Y = (float)Math.Floor(mouse.Y / GridRectHeight); //MessageBox.Show(mouse.X + " " + mouse.Y); return mouse; }
public HUDSpeedBaseButton() { RelativePosition = new FPoint(8, 8); Size = new FSize(62, 62); Alignment = HUDAlignment.BOTTOMLEFT; }
public void DrawString(SpriteFont spriteFont, string text, FPoint position, Color color, float rotation, FPoint origin, float scale, SpriteEffects effects, float layerDepth) { #if DEBUG IncRenderTextCount(text.Length); #endif internalBatch.DrawString(spriteFont, text, position.ToVec2D(), color, rotation, origin.ToVec2D(), scale, effects, layerDepth); }
public void DrawRectangle(FPoint location, FSize size, Color color, float thickness = 1f) { DrawRectangle(new FRectangle(location, size), color, thickness); }
public ZoomInOperation(FPoint pos) : base(DURATION) { centerPos = pos; }
public void DrawCircle(FPoint center, float radius, int sides, Color color, float thickness = 1f) { DrawPolygon(center, CreateCircle(radius, sides), color, true, thickness); }
private static float CalcDist(FPoint p1, FPoint p2) { return((float)Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y))); }
public void DrawCirclePiece(FPoint center, float radius, float angleMin, float angleMax, int sides, Color color, float thickness = 1f) { FPoint[] poly = CreateCirclePiece(radius, angleMin, angleMax, sides); DrawPolygon(center, poly, color, false, thickness); }
protected virtual void RecalculatePosition() { if (Owner == null) return; OnBeforeRecalculatePosition(); float px; float py; switch (Alignment) { case HUDAlignment.TOPLEFT: case HUDAlignment.BOTTOMLEFT: case HUDAlignment.CENTERLEFT: px = Owner.Left + RelativePosition.X; break; case HUDAlignment.TOPRIGHT: case HUDAlignment.BOTTOMRIGHT: case HUDAlignment.CENTERRIGHT: px = Owner.Right - Size.Width - RelativePosition.X; break; case HUDAlignment.TOPCENTER: case HUDAlignment.BOTTOMCENTER: case HUDAlignment.CENTER: px = Owner.CenterX - Size.Width / 2 + RelativePosition.X; break; case HUDAlignment.ABSOLUTE: px = RelativePosition.X; break; default: throw new ArgumentOutOfRangeException(); } switch (Alignment) { case HUDAlignment.TOPLEFT: case HUDAlignment.TOPRIGHT: case HUDAlignment.TOPCENTER: py = Owner.Top + RelativePosition.Y; break; case HUDAlignment.BOTTOMLEFT: case HUDAlignment.BOTTOMRIGHT: case HUDAlignment.BOTTOMCENTER: py = Owner.Bottom - Size.Height - RelativePosition.Y; break; case HUDAlignment.CENTERLEFT: case HUDAlignment.CENTERRIGHT: case HUDAlignment.CENTER: py = Owner.CenterY - Size.Height / 2 + RelativePosition.Y; break; case HUDAlignment.ABSOLUTE: py = RelativePosition.Y; break; default: throw new ArgumentOutOfRangeException(); } Position = new FPoint(px, py); BoundingRectangle = new FRectangle(Position, Size); PositionInvalidated = false; OnAfterRecalculatePosition(); }
protected override void OnPointerUp(FPoint relPositionPoint, InputState istate) { if (!IsPointerDownOnElement) return; if (!isHoldingDown) return; if (!IsCursorOnButton(istate)) return; var delta = MonoSAMGame.CurrentTime.GetTotalElapsedSeconds() - pointerDownTime; if (delta > LONG_PRESS_TIME && IsHoldClickMode) { suppressClick = true; pointerDownTime = -999; OnHold(istate, delta); } isHoldingDown = false; }
protected override void OnPointerDown(FPoint relPositionPoint, InputState istate) { if (!IsCursorOnButton(istate)) return; pointerDownTime = MonoSAMGame.CurrentTime.GetTotalElapsedSeconds(); isHoldingDown = true; }
private void CalcNewLocation(float x, float y, FPoint pos) { float fx = 0; float fy = 0; var isFarX = (X % .5f == 0 && x != X) || (int)(X / .5f) != (int)(x / .5f); var isFarY = (Y % .5f == 0 && y != Y) || (int)(Y / .5f) != (int)(y / .5f); if ((!isFarX && !isFarY) || RegionUnblocked(x, y)) { pos.X = x; pos.Y = y; return; } if (isFarX) { fx = (x > X) ? (int)(x * 2) / 2f : (int)(X * 2) / 2f; if ((int)fx > (int)X) { fx = fx - 0.01f; } } if (isFarY) { fy = (y > Y) ? (int)(y * 2) / 2f : (int)(Y * 2) / 2f; if ((int)fy > (int)Y) { fy = fy - 0.01f; } } if (!isFarX) { pos.X = x; pos.Y = fy; return; } if (!isFarY) { pos.X = fx; pos.Y = y; return; } var ax = (x > X) ? x - fx : fx - x; var ay = (y > Y) ? y - fy : fy - y; if (ax > ay) { if (RegionUnblocked(x, fy)) { pos.X = x; pos.Y = fy; return; } if (RegionUnblocked(fx, y)) { pos.X = fx; pos.Y = y; return; } } else { if (RegionUnblocked(fx, y)) { pos.X = fx; pos.Y = y; return; } if (RegionUnblocked(x, fy)) { pos.X = x; pos.Y = fy; return; } } pos.X = fx; pos.Y = fy; }
private VectorPathBuilder(float builderScale) { current = new FPoint(0, 0); scale = builderScale; }
public static Point ToPoint(FPoint f) { return(new Point(f.X.IntValue, f.Y.IntValue)); }
public VectorPathBuilder MoveTo(float x, float y) { current = new FPoint(x * scale, y * scale); return this; }
public GeoTopology(string fn) { using (FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs)) { while (br.ReadInt32() != 0x3150414d) { ; } br.BaseStream.Seek(7 * 4, SeekOrigin.Current); num_points = br.ReadInt32(); num_borders = br.ReadInt32(); num_polys = br.ReadInt32(); num_xpolys = br.ReadInt32(); //------------------------------------------------------------------------------ points = new FPoint[num_points]; maxx = maxy = float.NegativeInfinity; minx = miny = float.PositiveInfinity; for (int i = 0; i < num_points; i++) { FPoint dst = new FPoint(); //dst.idx = i; dst.x = br.ReadSingle(); dst.y = br.ReadSingle(); if (dst.x > maxx) { maxx = dst.x; } if (dst.x < minx) { minx = dst.x; } if (dst.y > maxy) { maxy = dst.y; } if (dst.y < miny) { miny = dst.y; } points[i] = dst; } //------------------------------------------------------------------------------ borders = new Border[num_borders]; for (int i = 0; i < num_borders; i++) { Border dst = new Border(); dst.from_idx = br.ReadInt32(); dst.to_idx = br.ReadInt32(); dst.from = points[dst.from_idx]; dst.to = points[dst.to_idx]; dst.belong_poly = br.ReadInt32(); dst.neighbor_poly = br.ReadInt32(); int not_sure = br.ReadInt32(); //未用 borders[i] = dst; } //------------------------------------------------------------------------------ polys = new Polygon[num_polys]; for (int i = 0; i < num_polys; i++) { Polygon dst = new Polygon(); dst.idx = i; dst.num_borders = br.ReadInt32(); dst.attributes = br.ReadBytes(8); dst.tanX = br.ReadSingle(); dst.tanY = br.ReadSingle(); dst.M = br.ReadSingle(); dst.not_sure = br.ReadBytes(24); dst.minx = br.ReadSingle(); dst.miny = br.ReadSingle(); dst.minz = br.ReadSingle(); dst.maxx = br.ReadSingle(); dst.maxy = br.ReadSingle(); dst.maxz = br.ReadSingle(); dst.border_idxs = new int[dst.num_borders]; dst.borders = new Border[dst.num_borders]; for (int j = 0; j < dst.num_borders; j++) { int idx = br.ReadInt32(); dst.border_idxs[j] = idx; dst.borders[j] = borders[idx]; } int att = dst.attributes[4]; if (att == 0x4 || att == 0x10 || att == 0x14 || att == 0x16) { dst.enterable = false; } else { dst.enterable = true; } if (dst.attributes[6] == 0x2) { dst.enterable = false; } polys[i] = dst; } //------------------------------------------------------------------------------ while (br.ReadInt32() != 0x48415332) { ; } br.ReadInt32(); //grids中polygon数量的总和,未用 br.ReadInt32(); //用途未知 num_X_grids = br.ReadInt32(); num_Y_grids = br.ReadInt32(); grids = new Grid[num_Y_grids, num_X_grids]; for (int y = 0; y < num_Y_grids; y++) { for (int x = 0; x < num_X_grids; x++) { Grid g = new Grid(); g.num_polys = br.ReadInt32(); g.poly_idxs = new int[g.num_polys]; g.polygons = new Polygon[g.num_polys]; for (int i = 0; i < g.num_polys; i++) { int idx = br.ReadInt32(); g.poly_idxs[i] = idx; g.polygons[i] = polys[idx]; } grids[y, x] = g; } } } } }
public void RegisterBlockedLine(FPoint start, FPoint end) { var delta = end - start; var angle = delta.ToAngle(); if ((angle + FloatMath.RAD_POS_045) % FloatMath.RAD_POS_180 < FloatMath.RAD_POS_090) { // HORZ if (start.X > end.X) { var tmp = start; start = end; end = tmp; } int firstX = FloatMath.Ceiling((start.X - 8f) / GDConstants.TILE_WIDTH); int lastX = FloatMath.Floor((end.X + 8f) / GDConstants.TILE_WIDTH); int lastoy = FloatMath.Round((start.Y + (end.Y - start.Y) * ((firstX * GDConstants.TILE_WIDTH - start.X) / (end.X - start.X))) / GDConstants.TILE_WIDTH); for (int ox = firstX + 1; ox <= lastX; ox++) { var oy = FloatMath.Round((start.Y + (end.Y - start.Y) * ((ox * GDConstants.TILE_WIDTH - start.X) / (end.X - start.X))) / GDConstants.TILE_WIDTH); if (oy != lastoy) { BlockSegmentVert(ox + MAX_EXTENSION - 1, lastoy + MAX_EXTENSION, oy + MAX_EXTENSION); } BlockSegmentHorz(oy + MAX_EXTENSION, ox - 1 + MAX_EXTENSION, ox + MAX_EXTENSION); lastoy = oy; } } else { // VERT if (start.Y > end.Y) { var tmp = start; start = end; end = tmp; } int firstY = FloatMath.Ceiling((start.Y - 8f) / GDConstants.TILE_WIDTH); int lastY = FloatMath.Floor((end.Y + 8f) / GDConstants.TILE_WIDTH); int lastox = FloatMath.Round((start.X + (end.X - start.X) * ((firstY * GDConstants.TILE_WIDTH - start.Y) / (end.Y - start.Y))) / GDConstants.TILE_WIDTH); for (int oy = firstY + 1; oy <= lastY; oy++) { var ox = FloatMath.Round((start.X + (end.X - start.X) * ((oy * GDConstants.TILE_WIDTH - start.Y) / (end.Y - start.Y))) / GDConstants.TILE_WIDTH); if (ox != lastox) { BlockSegmentHorz(oy + MAX_EXTENSION - 1, lastox + MAX_EXTENSION, ox + MAX_EXTENSION); } BlockSegmentVert(ox + MAX_EXTENSION, oy - 1 + MAX_EXTENSION, oy + MAX_EXTENSION); lastox = ox; } } }
//----------------------------------------------------------------------------------------------- public DisplayTopology(GeoTopology geo) { this.geo = geo; num_points = geo.num_points; num_borders = geo.num_borders; num_polys = geo.num_polys; num_xpolys = geo.num_xpolys; //------------------------------------------------------------------------------ points = new FPoint[num_points]; for (int i = 0; i < num_points; i++) { FPoint dst = new FPoint(); FPoint src = geo.points[i]; //dst.idx = src.idx; dst.x = src.x; dst.y = src.y; points[i] = dst; } //------------------------------------------------------------------------------ borders = new Border[num_borders]; for (int i = 0; i < num_borders; i++) { Border dst = new Border(); Border src = geo.borders[i]; dst.from_idx = src.from_idx; dst.to_idx = src.to_idx; dst.from = points[dst.from_idx]; dst.to = points[dst.to_idx]; dst.belong_poly = src.belong_poly; dst.neighbor_poly = src.neighbor_poly; borders[i] = dst; } //------------------------------------------------------------------------------ polys = new Polygon[num_polys]; for (int i = 0; i < num_polys; i++) { Polygon dst = new Polygon(); Polygon src = geo.polys[i]; dst.idx = src.idx; dst.num_borders = src.num_borders; dst.tanX = src.tanX; dst.tanY = src.tanY; dst.M = src.M; dst.attributes = (byte[])src.attributes.Clone(); dst.not_sure = (byte[])src.not_sure.Clone(); dst.minx = src.minx; dst.miny = src.miny; dst.minz = src.minz; dst.maxx = src.maxx; dst.maxy = src.maxy; dst.maxz = src.maxz; dst.border_idxs = new int[dst.num_borders]; dst.borders = new Border[dst.num_borders]; for (int j = 0; j < dst.num_borders; j++) { dst.border_idxs[j] = src.border_idxs[j]; dst.borders[j] = borders[dst.border_idxs[j]]; } dst.enterable = src.enterable; polys[i] = dst; } //------------------------------------------------------------------------------ num_X_grids = geo.num_X_grids; num_Y_grids = geo.num_Y_grids; grids = new Grid[num_Y_grids, num_X_grids]; for (int y = 0; y < num_Y_grids; y++) { for (int x = 0; x < num_X_grids; x++) { Grid src = geo.grids[y, x]; Grid dst = new Grid(); dst.num_polys = src.num_polys; dst.poly_idxs = (int[])src.poly_idxs.Clone(); dst.polygons = new Polygon[dst.num_polys]; for (int i = 0; i < dst.num_polys; i++) { dst.polygons[i] = polys[dst.poly_idxs[i]]; } grids[y, x] = dst; } } NormalizeAllPoints(); ValidateSecData(); }
public VectorPathBuilder EllipseCCW(float rx, float ry, float cx, float cy, float degStart, float deggEnd) { var ell = new EllipsePieceSegment(new FPoint(cx * scale, cy * scale), rx * scale, ry * scale, degStart * FloatMath.DegRad, deggEnd * FloatMath.DegRad, CircularDirection.CCW); segments.Add(ell); current = ell.GetEnd(); return this; }
public void DrawSketch(Graphics g, float zoom, bool show_idx, bool colored) //g: Bitmap坐标系 { int W = (int)Math.Ceiling(maxx * zoom); int H = (int)Math.Ceiling(maxy * zoom); using (Brush brush = new SolidBrush(Color.Black)) g.FillRectangle(brush, new Rectangle(0, 0, W + 1, H + 1)); //必须+1 //从显示拓扑坐标系(笛卡尔)->Bmp设备坐标系 Matrix2D trans = new Matrix2D(1, 0, 0, -1, 0, maxy); //Y翻转 trans.Scale(zoom, zoom, MatrixOrder.Append); //再缩放 g.Transform = trans; //绘制所有多边形,根据属性着色 if (colored) { for (int i = 0; i < num_polys; i++) { DrawColoredPolygon(g, polys[i]); } } using (Pen pen = new Pen(Color.FromArgb(150, Color.Red))) { for (int i = 0; i < num_borders; i++) { FPoint from = borders[i].from; FPoint to = borders[i].to; g.DrawLine(pen, from.x, from.y, to.x, to.y); } } using (Pen pen = new Pen(Color.White)) { for (int i = 0; i < num_polys; i++) { if (!polys[i].enterable) { Polygon p = polys[i]; for (int j = 0; j < p.num_borders; j++) { FPoint from = p.borders[j].from; FPoint to = p.borders[j].to; g.DrawLine(pen, from.x, from.y, to.x, to.y); } } } } //------------------------------------------------------------------------ if (show_idx) { g.ResetTransform(); using (Font font = new Font("Tahoma", 8.5F * zoom)) using (Brush brush = new SolidBrush(Color.White)) { PointF[] pos = { new PointF(0, 0) }; for (int i = 0; i < num_polys; i++) { FPoint fp = polys[i].GetCentroid(); pos[0].X = fp.x; pos[0].Y = fp.y; //从显示拓扑坐标系->Bmp设备坐标系 trans.TransformPoints(pos); SizeF size = g.MeasureString(i.ToString(), font); pos[0].X -= size.Width / 2; pos[0].Y -= size.Height / 2; g.DrawString(i.ToString(), font, brush, pos[0]); } } } }
public HUDSpeedBaseButton() { RelativePosition = new FPoint(8, 8); Size = new FSize(62, 62); Alignment = HUDAlignment.BOTTOMLEFT; }
//----------------------------------------------------------------------------------------------- public void DisplaySelectedPolygon(Graphics g, Matrix2D trans_D2C, int idx) //g: Client窗口设备坐标系 { if (idx == -1) { return; } g.ResetTransform(); g.SmoothingMode = SmoothingMode.HighQuality; using (Pen pen = new Pen(Color.Blue, 4F)) { //显示from->to顶点走向 pen.EndCap = LineCap.ArrowAnchor; PointF[] pos = { new PointF(), new PointF() }; Polygon p = polys[idx]; for (int i = 0; i < p.num_borders; i++) { FPoint from = p.borders[i].from; FPoint to = p.borders[i].to; pos[0].X = from.x; pos[0].Y = from.y; pos[1].X = to.x; pos[1].Y = to.y; //显示拓扑坐标系->窗口客户区坐标系 trans_D2C.TransformPoints(pos); g.DrawLine(pen, pos[0], pos[1]); } } //显示边序号 using (Font font = new Font("Tahoma", 9)) using (Brush brush = new SolidBrush(Color.Yellow)) { PointF[] pos = { new PointF() }; Polygon p = polys[idx]; for (int i = 0; i < p.num_borders; i++) { FPoint fp = p.borders[i].GetMid(); pos[0].X = fp.x; pos[0].Y = fp.y; //坐标系级调整 trans_D2C.TransformPoints(pos); //像素级调整 SizeF size = g.MeasureString(i.ToString(), font); pos[0].X -= size.Width / 2; pos[0].Y -= size.Height / 2; g.DrawString(i.ToString(), font, brush, pos[0]); } } using (Font font = new Font("Tahoma", 12)) using (Brush brush = new SolidBrush(Color.GreenYellow)) { FPoint fp = polys[idx].GetCentroid(); //坐标系级调整 PointF[] pos = { new PointF(fp.x, fp.y) }; trans_D2C.TransformPoints(pos); //像素级调整 SizeF size = g.MeasureString(idx.ToString(), font); pos[0].X -= size.Width / 2; pos[0].Y -= size.Height / 2; g.DrawString(idx.ToString(), font, brush, pos[0]); } g.SmoothingMode = SmoothingMode.Default; }
private void UpdateDrag(GameTime gameTime, InputState istate) { var delta = istate.PointerPosition - mouseStartPos; Screen.MapOffsetX = startOffset.X + delta.X; Screen.MapOffsetY = startOffset.Y + delta.Y; CalculateOOB(); lastMousePosTimer += gameTime.GetElapsedSeconds(); if (lastMousePosTimer > DRAGSPEED_RESOLUTION) { dragSpeed = (istate.PointerPosition - lastMousePos) / lastMousePosTimer; //Debug.WriteLine(dragSpeed); lastMousePosTimer = 0f; lastMousePos = istate.PointerPosition; } }
protected override bool OnPointerUp(FPoint relPositionPoint, InputState istate) { return(IsVisible); }
protected override void OnPointerClick(FPoint relPositionPoint, InputState istate) { HUD.ShowToast(null, L10N.T(L10NImpl.STR_SCOREMAN_INFO_SCORE), 32, FlatColors.Silver, FlatColors.Foreground, 2f); }
protected override void DoUpdate(SAMTime gameTime, InputState istate) { _progress += gameTime.ElapsedSeconds; RelativePosition = FPoint.Lerp(_p1, _p2, FloatMath.PercSin(_progress / 0.5f)); }