Beispiel #1
0
        //internal override XElement ToXML()
        //{
        //    XElement e = new XElement("Enemy");
        //    e.SetAttributeValue("Type", this.GetType().ToString());
        //    e.SetAttributeValue("Name", Name);
        //    e.SetAttributeValue("Speed", Speed);
        //    e.SetAttributeValue("Health", Health);
        //    e.SetAttributeValue("Pos", Pos);
        //    //add other data about this type of enemy here
        //    return e;
        //}
        internal static Wasp Parse(XElement e)
        {
            #if LEVELEDITOR
            Wasp g = new Wasp();
            foreach (XAttribute attr in e.Attributes())
            {
                if (attr.Name == "Name")
                {
                    g.Name = attr.Value;
                }
                else if (attr.Name == "Health")
                {
                    g.Health = int.Parse(attr.Value);
                }
                else if (attr.Name == "Speed")
                {
                    g.Speed = float.Parse(attr.Value);
                }
                else if (attr.Name == "Pos")
                {
                    g.Pos = Index2D.Parse(attr.Value);

                }
            }
            #else
            string name = e.Attribute("Name").Value;
            int health = int.Parse(e.Attribute("Health").Value);
            Index2D pos = Index2D.Parse(e.Attribute("Pos").Value);
            Microsoft.Xna.Framework.Vector2 initpos = new Microsoft.Xna.Framework.Vector2(pos.X, pos.Y);
            Wasp g = new Wasp(name, initpos);
            #endif
            return g;
        }
Beispiel #2
0
 public LayerDefinition()
 {
     Image = "";
     Name = "";
     ScrollFactor = Microsoft.Xna.Framework.Vector2.One;
     Visible = true;
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new door object
 /// </summary>
 /// <param name="world">The file name of the door that the door links to</param>
 public Door(string world, int x, int y)
     : base(true, "door.png")
 {
     this.world = world;
     destination = new Microsoft.Xna.Framework.Vector2(x, y);
     this.Texture = Game1.Instance.Content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>("./Tiles/door.png");
 }
Beispiel #4
0
        public void GenGraph()
        {
            Random r = new Random(seed);
            List<BenTools.Mathematics.Vector> lv = new List<BenTools.Mathematics.Vector>();
            for (int i = 0; i < 10000; i++)
            {
                BenTools.Mathematics.Vector v = new BenTools.Mathematics.Vector(new double[2] { r.Next(1, 99) / 100f, r.Next(1, 99) / 100f });
                if (!lv.Contains(v))
                    lv.Add(v);
            }
            cells.GenVoronoi(lv);

            for (int i = 0; i < 3; i++)
            {
                //Print(String.Format("Iter{0}", x));
                minPos = new Vector2(1f, 1f);
                lv.Clear();
                foreach (Voronoi.Center c in cells.Centers.Values)
                {
                    Vector2[] points = c.corners.Keys.ToArray();
                    Vector2 cent = CalculateCentroid(points, c.corners.Count - 1);

                    if (cent.X > 0 && cent.X < 1 && cent.Y > 0 && cent.Y < 1 && !lv.Contains(Tools.Functions.Vector2ToVector(cent)))
                    {
                        if (cent.X <= minPos.X && cent.Y <= minPos.Y)
                            minPos = cent;
                        lv.Add(Tools.Functions.Vector2ToVector(cent));
                    }
                }

                cells.Clear();
                cells.GenVoronoi(lv);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InputSettings"/> class.
        /// </summary>
        public InputSettings()
        {
            DoubleClickTime = new TimeSpan(0, 0, 0, 0, 500);    // 500 ms
              if (GlobalSettings.PlatformID == PlatformID.WindowsPhone7
              || GlobalSettings.PlatformID == PlatformID.WindowsPhone8
              || GlobalSettings.PlatformID == PlatformID.WindowsStore
              || GlobalSettings.PlatformID == PlatformID.Android
              || GlobalSettings.PlatformID == PlatformID.iOS)
              {
            // No mouse on phone. Mouse is always used for touch input.
            // Use 100 pixels for big fingers.
            DoubleClickSize = new Vector2F(100);
              }
              else
              {
            DoubleClickSize = new Vector2F(4);
              }

              MouseCenter = new Vector2F(300, 300);
              RepetitionDelay = new TimeSpan(0, 0, 0, 0, 500);    // 500 ms
              RepetitionInterval = new TimeSpan(0, 0, 0, 0, 100); // 100 ms
              ThumbstickThreshold = 0.5f;
              TriggerThreshold = 0.2f;
            #if !SILVERLIGHT
              GamePadDeadZone = GamePadDeadZone.IndependentAxes;
            #endif
        }
Beispiel #6
0
        public static Utilities.Math.Shape.Shape GetRingShape(V2 pos, float zoomScale)
        {
            return new Utilities.Math.Shape.Polygon(CullMode.CullClockwiseFace, new List<V2>()
            {
                new V2(35, 128),
                new V2(33, 181),
                new V2(31, 214),
                new V2(26, 240),
                new V2(18, 253.5f),

                new V2(9, 240),
                new V2(4, 214),
                new V2(1, 181),
                new V2(0, 128),

                new V2(1, 58),
                new V2(4, 41),
                new V2(9, 16),
                new V2(18, 0),

                new V2(26, 16),
                new V2(31, 41),
                new V2(33, 58),
            }.Select(v => (zoomScale * v) + pos).ToArray());
        }
// ReSharper restore NotAccessedField.Global
// ReSharper restore MemberCanBePrivate.Global

        public VertexPositionTextureNormalBinormalTangent(Vector3 position, Vector2 textureCoordinate, Vector3 normal, Vector3 binormal, Vector3 tangent)
        {
            Position = position.ToXNA();
            TextureCoordinate = textureCoordinate.ToXNA();
            Normal = normal.ToXNA();
            Binormal = binormal.ToXNA();
            Tangent = tangent.ToXNA();
        }
Beispiel #8
0
 public Jouster(Jousters thisJouster, V2 pos, ZoomLevels zoom)
     : base(ArtAssets.GetJousterShape(KarmaWorld.World.CurrentZoom, WorldData.ZoomScaleAmount[zoom]),
            (zoom == ZoomLevels.Five ? Single.PositiveInfinity : PhysData.Acceleration), PhysData.MaxSpeed)
 {
     Pos = pos;
     ThisJouster = thisJouster;
     Mass = PhysicsData.JousterStartingMass[zoom];
 }
Beispiel #9
0
 public Firework(int Frames, float Time, Microsoft.Xna.Framework.Vector2 Position, Microsoft.Xna.Framework.Color Color)
 {
     CurFrame = 0;
     MaxFrame = Frames;
     TimeForFrame = Time;
     TimeLastChange = 0;
     this.Position = Position;
     this.Color = Color;
 }
        private int width, height; // Width and Height of the screen

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="width">Screen width</param>
        /// <param name="height">Screen height</param>
        public ViewGamePlayMenu(int width, int height, SpriteSheet sheet)
        {
            this.width = width;
            this.height = height;
            location = Microsoft.Xna.Framework.Vector2.Zero;
            loadGamePlaySprite(sheet);
            location.X = width - gamePlaySprite.frameDimX;
            location.Y = height - gamePlaySprite.frameDimY;
        }
Beispiel #11
0
 void BG_MouseClick(object sender, MouseEventArgs e)
 {
     Microsoft.Xna.Framework.Vector2 clickPosition = new Microsoft.Xna.Framework.Vector2(e.X, e.Y)*2;
     if (clickPosition.X < 800 && clickPosition.Y < 480)
     {
         foreach (Planet p in planets)
         {
             if (Microsoft.Xna.Framework.Vector2.Distance(clickPosition, p.Position) < p.PlanetSize/2 * 64)
             {
                 PlanetProperty.SelectedObject = p;
                 break;
             }
         }
     }
 }
Beispiel #12
0
 public static Utilities.Math.Shape.Shape GetDoghouseShape(float zoomScale, V2 pos)
 {
     Utilities.Math.Shape.Shape s = new Utilities.Math.Shape.Polygon(Microsoft.Xna.Framework.Graphics.CullMode.CullClockwiseFace,
                                                                     new List<V2>()
                                                                     {
                                                                         new V2(64, 18),
                                                                         new V2(112, 25.5f),
                                                                         new V2(112, 99.5f),
                                                                         new V2(64, 106),
                                                                         new V2(15, 99.5f),
                                                                         new V2(15, 25.5f),
                                                                     }.Select(v => (v * zoomScale * 2f) + (pos * 2f)).ToArray());
     s.Center = pos;
     return s;
 }
        public VisionView(GraphicsEngine _graphicEngine, SpriteBatch sb, GraphicsDeviceManager _gman, Vector2 _cameraOffset, Point _origin, float rotation, List<Line> _visionBlockingLines)
        {
            graphicEngine = _graphicEngine;
            gman = _gman;
            origin = _origin;
            visionBlockingLines = _visionBlockingLines;
            cameraOffset = _cameraOffset;

            //List<Point> lightPolygon
            //lightPolygon = new Vision().GetLightPolygons();
            vision = new Vision(origin, rotation, _visionBlockingLines);

            //Console.WriteLine(origin);

            displayLight(sb, cameraOffset, vision.lightTriangles);
        }
Beispiel #14
0
        private Microsoft.Xna.Framework.Vector2[] GenerateRandomSamplePositions(int numSamples, Random rand)
        {
            Microsoft.Xna.Framework.Vector2[] samples = new Microsoft.Xna.Framework.Vector2[numSamples];

            for (int i = 0; i < numSamples; i++)
            {
                var angle = rand.NextDouble() * MathHelper.TwoPi;
                var vector = new Vector2((float)Math.Sin(angle), (float)Math.Cos(angle));

                var length = i / (float)numSamples;
                length = MathHelper.Lerp(0.1f, 1.0f, length * length);
                samples[i] = (vector * length).ToXNA();
            }

            return samples;
        }
Beispiel #15
0
        /// <summary>
        /// Create an input handler
        /// </summary>
        public InputHandler()
        {
            this.currentMousePosition = new Microsoft.Xna.Framework.Vector2(0, 0);
            this.mouseMovement = new Microsoft.Xna.Framework.Vector2(0, 0);
            this.boundingBox = new Microsoft.Xna.Framework.Rectangle(0, 0, 10, 10);

            this.leftClick = false;
            this.leftDrag = false;
            this.rightClick = false;
            this.rightDrag = false;
            this.releaseLeft = false;
            this.releaseRight = false;

            Microsoft.Xna.Framework.Input.Mouse.SetPosition(0, 0);
            this.currentMousePosition = new Microsoft.Xna.Framework.Vector2(0, 0);
        }
Beispiel #16
0
        public static void GetEnclosingAABB(this Body body, out AABB aabb_enclosing)
        {
            AABB aabb_fixture;
            Microsoft.Xna.Framework.Vector2 lo = new Microsoft.Xna.Framework.Vector2(float.PositiveInfinity);
            Microsoft.Xna.Framework.Vector2 hi = new Microsoft.Xna.Framework.Vector2(float.NegativeInfinity);
            for (int i = 0; i < body.FixtureList.Count; i++) {
                if(body.FixtureList[i].CollisionCategories == Category.None)
                    continue;
                body.FixtureList[i].GetAABB (out aabb_fixture, 0); // Should just be first proxy (0)
                lo.X = Math.Min (lo.X, aabb_fixture.LowerBound.X);
                lo.Y = Math.Min (lo.Y, aabb_fixture.LowerBound.Y);
                hi.X = Math.Max (hi.X, aabb_fixture.UpperBound.X);
                hi.Y = Math.Max (hi.Y, aabb_fixture.UpperBound.Y);
            }

            aabb_enclosing = new AABB(lo, hi);
        }
Beispiel #17
0
 public override void Update(double time)
 {
     // Basic movement behavior:
     Player p = Program.MainGame.Player1;
     if (p != null)
     {
         if(JumpTimer.Elapsed.TotalSeconds >= JumpIntervalVaried)
         {
             float randy = 1.0f + JumpVeloVariance * (float)R.NextDouble();
             float dx = (float)p.PositionWorldX - (float)PositionWorldX;
             dx = 0.5f * dx / Math.Max(1.0f, dx);
             var velocity = new Microsoft.Xna.Framework.Vector2(dx, 3.0f) * Body.Mass * randy;
             Body.ApplyLinearImpulse(velocity);
             JumpIntervalVaried = JumpInterval + R.NextDouble() * JumpIntervalVariance;
             JumpTimer.Restart();
         }
     }
 }
Beispiel #18
0
        public void LaunchRing(V2 pos, V2 dir)
        {
            Jousting.Blocker ring = new Jousting.Blocker(new Utilities.Graphics.AnimatedSprite(ArtAssets5.Ring),
                                                         ArtAssets5.GetRingShape(pos, WorldData.ZoomScaleAmount[CurrentZoom]),
                                                         true, PhysicsData5.GetRingSpeed(WorldData.ZoomScaleAmount[CurrentZoom]));
            ring.Rotation = UsefulMath.FindRotation(dir);
            ring.Velocity = ring.MaxVelocity * dir;
            //ring

            ring.OnHitByJouster += (s, e) =>
                {
                    if (e.Enemy.ThisJouster == Jousting.Jousters.Dischord) return;

                    e.Enemy.Health -= PhysicsData5.RingDamage;
                    KillBlocker((Jousting.Blocker)s);
                };

            Blockers.Add(ring);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="x">X location</param>
        /// <param name="y">Y location</param>
        /// <param name="rotate">Rotational value radian</param>
        public Bullet(float x, float y, float rotate, EntityType owner,int a,float s,int h,int st)
            : base((float)(x + 10f * Math.Cos(rotate)),
            (float)(y + Math.Sin(rotate) * 10f),
            (float)(rotate),
            EntityType.BULLET)
        {
            spawnLoc = new Microsoft.Xna.Framework.Vector2(Location.X, Location.Y);
            //bulletType = bullet_type;
            ownerOfBulletType = owner;
            allowFriendFired = false;
            stateEntityOffset = GameConfig.IMG_BULLET_ENTITY;

            attackValue = a;
            speedValue = s;
            health = h;
            state = st;

            calculateDestination();
            rangeRadius = GameConfig.DEFAULT_RANGE_RADIUS_BULLET;
        }
Beispiel #20
0
 private Vector2 CircleCenter(Vector2 A, Vector2 B, Vector2 C)
 {
     // finds the point of a circle from three points on it's edges
     float yDelta_a = B.Y - A.Y;
     float xDelta_a = B.X - A.X;
     float yDelta_b = C.Y - B.Y;
     float xDelta_b = C.X - B.X;
     Vector2 center = new Vector2();
     if (xDelta_a == 0)
     {
         xDelta_a = 0.00001f;
     }
     if (xDelta_b == 0)
     {
         xDelta_b = 0.00001f;
     }
     float aSlope = yDelta_a / xDelta_a;
     float bSlope = yDelta_b / xDelta_b;
     center.X = (aSlope * bSlope * (A.Y - C.Y) + bSlope * (A.X + B.X) - aSlope * (B.X + C.X)) / (2 * (bSlope - aSlope));
     center.Y = -1 * (center.X - (A.X + B.X) / 2) / aSlope + (A.Y + B.Y) / 2;
     return center;
 }
Beispiel #21
0
        public static void DrawHillTimeBar(V2 playerPos, float playerTimeInHill, SpriteBatch sb)
        {
            float lerp = playerTimeInHill / PhysicsData3.TimeInHillToWin;

            V2 offset = new V2(-50.0f, -50.0f);

            Col backgroundCol = Col.Black;
            const int width = 20, height = 100;
            TexturePrimitiveDrawer.DrawRect(new Microsoft.Xna.Framework.Rectangle((int)(playerPos.X + offset.X) - width,
                                                                                  (int)(playerPos.Y + offset.Y) - height,
                                                                                  width, height),
                                            sb, backgroundCol, 1);

            Col foregroundCol = Col.White;
            foregroundCol.A = (byte)(255.0f * lerp);
            const int border = 5;
            int height2 = (byte)((height - (border * 2)) * lerp);
            TexturePrimitiveDrawer.DrawRect(new Microsoft.Xna.Framework.Rectangle((int)(playerPos.X + offset.X) - width + border,
                                                                                  (int)(playerPos.Y + offset.Y) - height2,
                                                                                  width - (2 * border),
                                                                                  height2 - border),
                                            sb, foregroundCol, 1);
        }
Beispiel #22
0
 public Constants()
 {
     //initialize all settings with default values
     ColorSelectionFirst = new Color(255, 255, 0, 255);
     ColorSelectionRest = new Color(255, 128, 0, 255);
     EnableHighlightOnMouseOver = true;
     ColorHighlight = new Color(255, 0, 0, 228);
     ColorBackground = new Color(100, 149, 237, 255);
     ColorSelectionBox = new Color(255, 255, 255, 109);
     ColorPrimitives = new Color(192, 0, 192, 145);
     ColorTextureTransparent = new Color(255, 0, 255, 255);
     DefaultPathItemLineWidth = 4;
     DefaultContentRootFolder = "C:\\";
     CameraSpeed = 500;
     CameraFastSpeed = 2000;
     DefaultTextureOriginMethod = TextureOriginMethodEnum.TextureCenter;
     WorldOriginColor = new Color(255, 255, 255, 255);
     WorldOriginLineThickness = 2;
     GridColor = new Color(192, 192, 192, 120);
     GridLineThickness = 1;
     GridNumberOfGridLines = 500;
     GridSpacing = new Microsoft.Xna.Framework.Vector2(64, 64);
 }
Beispiel #23
0
        protected override void fadeIn()
        {
            while (Main.curState == "GUIGlobalLoad")
                System.Threading.Thread.Sleep(2);

            var a = Scene as GUI.Scene.MainMenu;
            if (a == null || a.currentFrame == null)
            {
                base.fadeIn();
                return;
            }
            GUI.Scene.MainMenu.FrameOffset = -a.currentFrame.Size.X;
            a.currentFrame.isVisible = true;

            Microsoft.Xna.Framework.Vector2 lp2 = new Microsoft.Xna.Framework.Vector2(501f * Main.WindowWidth / 1920f, 126 * Main.WindowHeight / 1080);

            a.line3p1 = lp2;
            a.line3p2 = lp2;
            a.line4p1 = lp2;
            a.line4p2 = lp2;

            for (int i = 0; i <= 30; i++)
            {
                if (ForceStop)
                {
                    ForceStop = false;
                    return;
                }
                a.line3p2.X = a.line3p1.X + 1263f * Main.WindowWidth / 1920f * i / 30f;
                a.line4p2.Y = a.line4p1.Y + 863 * Main.WindowHeight / 1080 * i / 30f;
                GUI.Scene.MainMenu.FrameOffset = -a.currentFrame.Size.X * (float)(30 - i) / 30f;
                System.Threading.Thread.Sleep(10);
            }

            base.fadeIn();
        }
Beispiel #24
0
 public static OpenTK.Vector2d ConvertVector2d(Microsoft.Xna.Framework.Vector2 vec)
 {
     return(new OpenTK.Vector2d((double)vec.X, (double)vec.Y));
 }
Beispiel #25
0
 private void humanBtn_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     StartNewCampaign(Race.Humans);
 }
Beispiel #26
0
 void cancelBtn_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     new MainMenuWindow();
     Close();
 }
Beispiel #27
0
        /// <summary> Loads the current level </summary>
        public void LoadLevel()
        {
            DisposeElements();
            String[] data = LevelController.Instance.CurrentLevel.Data;

            Vector2 playerStart = Vector2.Zero;

            foreach (String element in data)
            {
                if (String.IsNullOrEmpty(element) || element.Equals("\r"))
                {
                    continue;
                }
                String[] elementData = element.Split(',');
                switch (elementData[0])
                {
                case "Sprite":
                    _LevelDrawables.Add(new Sprite(ZippyGame.MainCanvas, elementData));
                    break;

                case "TextDisplay":
                    _LevelDrawables.Add(new TextDisplay(ZippyGame.MainCanvas, elementData));
                    break;

                case "AnimatedSprite":
                    _LevelDrawables.Add(new AnimatedSprite(ZippyGame.MainCanvas, elementData));
                    break;

                case "PlayerStart":
                    String[] position = elementData[1].Split('|');
                    XVector2 pos      = new XVector2(Single.Parse(position[0], CultureInfo.InvariantCulture), Single.Parse(position[1], CultureInfo.InvariantCulture));
                    _Zippy.SetStartPosition(pos);
                    break;

                case "CameraLimits":
                    ZippyGame.Camera.SetLimits(elementData);
                    _LeftCollider.Position  = ConvertUnits.ToSimUnits(new XVector2(ZippyGame.Camera.TopLeft.X - (Renderer.Instance.TargetDimensions.X / 2 - 10), ZippyGame.Camera.TopLeft.Y));
                    _RightCollider.Position = ConvertUnits.ToSimUnits(new XVector2(ZippyGame.Camera.BottomRight.X + (Renderer.Instance.TargetDimensions.X / 2 + 10), ZippyGame.Camera.BottomRight.Y));
                    break;

                default:
                    if (!SceneTypeMap.TypeExists(elementData[0]))
                    {
                        throw new KeyNotFoundException($"The given type {elementData[0]} is not in the type map");
                    }
                    Object obj = Activator.CreateInstance(SceneTypeMap.GetType(elementData[0]), new Object[] { elementData });
                    if (obj is Enemy)
                    {
                        _Enemies.Add((Enemy)obj);
                    }
                    else if (obj is Collectible)
                    {
                        _Collectibles.Add((Collectible)obj);
                    }
                    else if (obj is Platform)
                    {
                        _Platforms.Add((Platform)obj);
                    }
                    break;
                }
            }
        }
Beispiel #28
0
 public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     position.Y -= (item.scale * 30) - 30;
     return(base.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack));
 }
Beispiel #29
0
 void quitButton_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     new IngameQuitMenuWindow(curRace);
 }
Beispiel #30
0
        internal override bool PointerMoved(Microsoft.Xna.Framework.Vector2 position)
        {
            MouseCursor.State = MouseCursorState.Pointer;

            return(base.PointerMoved(position));
        }
Beispiel #31
0
 public override bool OnTileCollide(Microsoft.Xna.Framework.Vector2 oldVelocity)
 {
     return(ProjectileAI.BoomerangTileCollide(projectile.whoAmI, oldVelocity));
 }
Beispiel #32
0
 public static OpenTK.Vector2 ConvertVector2(Microsoft.Xna.Framework.Vector2 vec)
 {
     return(new OpenTK.Vector2(vec.X, vec.Y));
 }
Beispiel #33
0
 public static NumVector2 ToNumericVector2(this XnaVector2 value)
 {
     return(new NumVector2(value.X, value.Y));
 }
        public override void DrawUI()
        {
            base.DrawUI();
            //Game.DataTextDrawer.Draw("Time per DH:    ", DHtime * 1e6f, new Vector2(50, 80));

            var origin = new Microsoft.Xna.Framework.Vector2(100, 50);
            var spacing = new Microsoft.Xna.Framework.Vector2(80, 50);
            //Draw the horizontal core counts.
            for (int i = 0; i < testResults.GetLength(0); i++)
            {
                Game.DataTextDrawer.Draw(i + 1, origin + new Microsoft.Xna.Framework.Vector2(spacing.X * i, -30));
            }
            for (int i = 0; i < testResults.GetLength(1); i++)
            {
                Game.DataTextDrawer.Draw(i, origin + new Microsoft.Xna.Framework.Vector2(-30, spacing.Y * i));
            }

            for (int i = 0; i < testResults.GetLength(0); i++)
            {
                int lowestTime = 0;
                for (int j = 0; j < testResults.GetLength(1); j++)
                {
                    Game.DataTextDrawer.Draw(testResults[i, j] * 1e6, 0, origin + new Microsoft.Xna.Framework.Vector2(spacing.X * i, spacing.Y * j));
                    if (testResults[i, j] < testResults[i, lowestTime])
                        lowestTime = j;
                }

                Game.DataTextDrawer.Draw(testResults[i, lowestTime] * 1e6, 0, origin + new Microsoft.Xna.Framework.Vector2(spacing.X * i, spacing.Y * (testResults.GetLength(1))));
                Game.DataTextDrawer.Draw(lowestTime, 0, origin + new Microsoft.Xna.Framework.Vector2(spacing.X * i, spacing.Y * (testResults.GetLength(1) + 1)));
            }


        }
Beispiel #35
0
        public KeysUpdateEventArgs KeysUpdate(object sender, KeysUpdateEventArgs e)
        {
            float fx =
                (e.KeysPressedWhen.Contains (Configuration.KeyLeft) ? -1.0f : 0.0f) +
                (e.KeysPressedWhen.Contains (Configuration.KeyRight) ? 1.0f : 0.0f);
            if (_WieldingGun) {
                _AimAngle =  Math.PI * (
                    (e.KeysPressedWhen.Contains (Configuration.KeyDown) ? -0.25 : 0.0f) +
                    (e.KeysPressedWhen.Contains (Configuration.KeyUp) ? 0.25f : 0.0f));
                if (fx != 0.0f) {
                    _TileX = fx;
                    fx = 0.0f;
                }
            }
            fx *= 5f;
            //vy *= 10f;
            //this.Body.ApplyForce(new Microsoft.Xna.Framework.Vector2(vx * _SpriteBody.Mass, vy * _SpriteBody.Mass));
            var v = new Microsoft.Xna.Framework.Vector2 (fx * 0.5f, Body.LinearVelocity.Y);
            Body.LinearVelocity = Microsoft.Xna.Framework.Vector2.Lerp (Body.LinearVelocity, v, _MovementDamping * (float)e.Time);
            if (Body.LinearVelocity.LengthSquared () > 0.1f) {
                _DampVeloNormal = new Vector3d (Body.LinearVelocity.X, Body.LinearVelocity.Y, 0.0);
                _DampVeloNormal /= Math.Max (5.0, _DampVeloNormal.Length);
            }

            float v__x_mag = Math.Abs (v.X);
            if (!Jumping) {
               if (v__x_mag > VelocityMovementThreshold) {
                    _TileX = v.X > 0.0 ? 1.0 : -1.0;
                    PlayAnimation (AnimationMove);
                } else {
             					if (_WieldingGun) {
                        if(Crouching)
                            PlayAnimation (AnimationAimGunFwdCrouch);
                        else if (e.KeysPressedWhen.Contains (Configuration.KeyUp))
                            PlayAnimation (AnimationAimGunFwdUp);
                        else if (e.KeysPressedWhen.Contains (Configuration.KeyDown))
                            PlayAnimation (AnimationAimGunFwdDown);
                        else
                            PlayAnimation (AnimationAimGunFwd);
                    }
                    else
                        PlayAnimation (AnimationStationary);
                }
                //else
                //	PlayAnimation (AnimationStationary);
                _AnimationNext = null;
            }
            else if(_WieldingGun)
                PlayAnimation(AnimationAimGunFwdJump);

            //Console.WriteLine("On Platform == {0}", OnPlatform);

            // Time tolerance for input controls!
            //OrderedDictionary keytime = new OrderedDictionary();
            foreach(DictionaryEntry de in e.KeysPressedWhen)
            {
                Key k = (Key)de.Key;
                if(k == Configuration.KeyJump)
                {
                    if(Helper.KeyPressedInTime((DateTime)de.Value, DateTime.Now))
                    {
                        Jump ();
                    }
            //					else
            //					{
            //						keytime.Add(de.Key, de.Value);
            //					}
                }
            }
            //e.KeysPressedWhen = keytime;
            return e;
        }
Beispiel #36
0
        public static Entity Create(
            Comps.Projectile.Kind kind,
            Entity owner,
            Ecs.Registry registry
            )
        {
            // Assume that `owner` has position and orientation
            // components

            var playerPositionComp = registry
                                     .GetComponentUnsafe <Comps.Position>(owner);

            var playerRectangleComp = registry
                                      .GetComponentUnsafe <Comps.Shapes.Rectangle>(owner);

            var playerOrientationComp = registry
                                        .GetComponentUnsafe <Comps.Orientations.Cardinal>(owner);

            var playerPosRectangle = new Physical.PosRectangle(
                playerPositionComp.data,
                playerRectangleComp.data
                );

            // Create projectile

            Physical.Rectangle rectangle = new Physical.Rectangle(
                16.0f * 4,
                16.0f * 4
                );

            PhysicalVector2 position = GetStartingPosition(
                playerPosRectangle,
                playerOrientationComp.data,
                rectangle
                );

            var projectileEntity = registry.CreateEntity();

            registry.AssignComponent(
                projectileEntity,
                new Comps.Shapes.Rectangle {
                data = rectangle
            }
                );

            registry.AssignComponent(
                projectileEntity,
                new Comps.Position {
                data = position
            }
                );

            registry.AssignComponent(
                projectileEntity,
                (Comps.Orientations.Cardinal)playerOrientationComp.Clone()
                );

            PhysicalVector2 velocity =
                playerOrientationComp.data.GetPhysicalVector2() *
                GetStartingSpeed(kind);

            registry.AssignComponent(
                projectileEntity,
                new Comps.Velocity {
                data  = velocity,
                decay = 1.0f
            }
                );

            registry.AssignComponent(
                projectileEntity,
                new Comps.Projectile {
                kind    = kind,
                ownerId = owner.id
            }
                );

            if (IsDamaging(kind))
            {
                registry.AssignComponent(
                    projectileEntity,
                    new Comps.Damaging {
                    damage     = 1,
                    attackerId = owner.id
                }
                    );
            }

            registry.AssignComponent(
                projectileEntity,
                new Comps.Lifetime {
                ticks = GetLifetime(kind)
            }
                );

            registry.AssignComponent(
                projectileEntity,
                new Comps.Solid {
                ephemeral = true
            }
                );

            return(projectileEntity);
        }
 public static Microsoft.Xna.Framework.Vector2 ToVector2(this System.Drawing.Point p)
 {
     Microsoft.Xna.Framework.Vector2 v2 = new Microsoft.Xna.Framework.Vector2(p.X, p.Y);
     return(v2);
 }
Beispiel #38
0
//		public static Microsoft.Xna.Framework.Vector2 ContactNormalAbsolute(this Contact contact)
//		{
//			FarseerPhysics.Collision.Manifold manifold = new Manifold();
//			FixedArray2<Microsoft.Xna.Framework.Vector2> points = new FixedArray2<Microsoft.Xna.Framework.Vector2 >();
//			contact.GetWorldManifold(out manifold.LocalNormal, out points); // Oh God why
//			return manifold.LocalNormal;
//		}
        public static float ConactNormalError(this Contact contact, Microsoft.Xna.Framework.Vector2 v2)
        {
            return(Microsoft.Xna.Framework.Vector2.Distance(contact.Manifold.LocalNormal, v2));
        }
Beispiel #39
0
 public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     type = mod.ProjectileType("DesertHead");
     return(base.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack));
 }
        public override int CreateProjectile(Player player, ref Microsoft.Xna.Framework.Vector2 dir)
        {
            int proj = base.CreateProjectile(player, ref dir);
            int dmg  = 1 + Main.rand.Next(30);

            if (NPC.downedBoss1 == true)
            {
                dmg *= 3;
            }
            if (Main.hardMode == true)
            {
                dmg *= 3;
            }
            if (NPC.downedMechBossAny == true)
            {
                dmg *= 2;
            }
            if (NPC.downedAncientCultist == true)
            {
                dmg *= 2;
            }
            if (NPC.downedMoonlord == true)
            {
                dmg *= 10;
            }
            int shot  = 1 + Main.rand.Next(661);
            int shot2 = 1 + Main.rand.Next(661);

            if (shot2 == 72 || shot2 == 86 || shot2 == 87 || shot2 == 111 || shot2 == 112 || shot2 == 127 || shot2 == 155 || shot2 == 175 || shot2 == 191 ||
                shot2 == 192 || shot2 == 193 || shot2 == 194 || shot2 == 197 || shot2 == 198 || shot2 == 199 || shot2 == 200 || shot2 == 209 || shot2 == 210 ||
                shot2 == 211 || shot2 == 208 || shot2 == 236 || shot2 == 266 || shot2 == 268 || shot2 == 269 || shot2 == 308 || shot2 == 312 || shot2 == 314 ||
                shot2 == 313 || shot2 == 317 || shot2 == 319 || shot2 == 324 || shot2 == 334 || shot2 == 353 || shot2 == 373 || shot2 == 375 || shot2 == 377 ||
                shot2 == 379 || shot2 == 380 || shot2 == 387 || shot2 == 388 || shot2 == 390 || shot2 == 395 || shot2 == 394 || shot2 == 393 || shot2 == 392 ||
                shot2 == 391 || shot2 == 398 || shot2 == 323 || shot2 == 499 || shot2 == 500 || shot2 == 525 || shot2 == 533 || shot2 == 565 || shot2 == 623 ||
                shot2 == 624 || shot2 == 625 || shot2 == 626 || shot2 == 627 || shot2 == 628 || shot2 == 643 || shot2 == 650 || shot2 == 653 || shot2 == 28 ||
                shot2 == 29 || shot2 == 37 || shot2 == 46 || shot2 == 47 || shot2 == 49 || shot2 == 57 || shot2 == 58 || shot2 == 59 || shot2 == 60 ||
                shot2 == 62 || shot2 == 61 || shot2 == 64 || shot2 == 66 || shot2 == 97 || shot2 == 105 || shot2 == 153 || shot2 == 212 || shot2 == 220 ||
                shot2 == 213 || shot2 == 214 || shot2 == 215 || shot2 == 216 || shot2 == 217 || shot2 == 218 || shot2 == 219 || shot2 == 223 || shot2 == 222 ||
                shot2 == 107 || shot2 == 130 || shot2 == 171 || shot2 == 224 || shot2 == 252 || shot2 == 360 || shot2 == 369 || shot2 == 361 || shot2 == 362 ||
                shot2 == 363 || shot2 == 364 || shot2 == 365 || shot2 == 366 || shot2 == 367 || shot2 == 368 || shot2 == 381 || shot2 == 382 || shot2 == 427 ||
                shot2 == 432 || shot2 == 428 || shot2 == 429 || shot2 == 430 || shot2 == 431 || shot2 == 439 || shot2 == 470 || shot2 == 475 || shot2 == 492 ||
                shot2 == 509 || shot2 == 534 || shot2 == 541 || shot2 == 564 || shot2 == 600 || shot2 == 603 || shot2 == 609 || shot2 == 610 || shot2 == 637 ||
                shot2 == 542 || shot2 == 543 || shot2 == 544 || shot2 == 545 || shot2 == 547 || shot2 == 546 || shot2 == 548 || shot2 == 549 || shot2 == 560 ||
                shot2 == 550 || shot2 == 551 || shot2 == 552 || shot2 == 553 || shot2 == 554 || shot2 == 555 || shot2 == 556 || shot2 == 557 || shot2 == 558 ||
                shot2 == 559 || shot2 == 561 || shot2 == 562 || shot2 == 563 || shot2 == 578 || shot2 == 579 || shot2 == 580 || shot2 == 581 || shot2 == 18 ||
                shot2 == 516 || shot2 == 143 || shot2 == 144 || shot2 == 108)
            {
                shot2 = 1;
            }
            if (shot == 72 || shot == 86 || shot == 87 || shot == 111 || shot == 112 || shot == 127 || shot == 155 || shot == 175 || shot == 191 ||
                shot == 192 || shot == 193 || shot == 194 || shot == 197 || shot == 198 || shot == 199 || shot == 200 || shot == 209 || shot == 210 ||
                shot == 211 || shot == 208 || shot == 236 || shot == 266 || shot == 268 || shot == 269 || shot == 308 || shot == 312 || shot == 314 ||
                shot == 313 || shot == 317 || shot == 319 || shot == 324 || shot == 334 || shot == 353 || shot == 373 || shot == 375 || shot == 377 ||
                shot == 379 || shot == 380 || shot == 387 || shot == 388 || shot == 390 || shot == 395 || shot == 394 || shot == 393 || shot == 392 ||
                shot == 391 || shot == 398 || shot == 323 || shot == 499 || shot == 500 || shot == 525 || shot == 533 || shot == 565 || shot == 623 ||
                shot == 624 || shot == 625 || shot == 626 || shot == 627 || shot == 628 || shot == 643 || shot == 650 || shot == 653 || shot == 28 ||
                shot == 29 || shot == 37 || shot == 46 || shot == 47 || shot == 49 || shot == 57 || shot == 58 || shot == 59 || shot == 60 ||
                shot == 62 || shot == 61 || shot == 64 || shot == 66 || shot == 97 || shot == 105 || shot == 153 || shot == 212 || shot == 220 ||
                shot == 213 || shot == 214 || shot == 215 || shot == 216 || shot == 217 || shot == 218 || shot == 219 || shot == 223 || shot == 222 ||
                shot == 107 || shot == 130 || shot == 171 || shot == 224 || shot == 252 || shot == 360 || shot == 369 || shot == 361 || shot == 362 ||
                shot == 363 || shot == 364 || shot == 365 || shot == 366 || shot == 367 || shot == 368 || shot == 381 || shot == 382 || shot == 427 ||
                shot == 432 || shot == 428 || shot == 429 || shot == 430 || shot == 431 || shot == 439 || shot == 470 || shot == 475 || shot == 492 ||
                shot == 509 || shot == 534 || shot == 541 || shot == 564 || shot == 600 || shot == 603 || shot == 609 || shot == 610 || shot == 637 ||
                shot == 542 || shot == 543 || shot == 544 || shot == 545 || shot == 547 || shot == 546 || shot == 548 || shot == 549 || shot == 560 ||
                shot == 550 || shot == 551 || shot == 552 || shot == 553 || shot == 554 || shot == 555 || shot == 556 || shot == 557 || shot == 558 ||
                shot == 559 || shot == 561 || shot == 562 || shot == 563 || shot == 578 || shot == 579 || shot == 580 || shot == 581 || shot == 18 ||
                shot == 516 || shot == 143 || shot == 144 || shot == 108)
            {
                shot = shot2;
            }
            int pro = Projectile.NewProjectile(player.Center.X, player.Center.Y, Main.projectile[proj].velocity.X, Main.projectile[proj].velocity.Y, shot, dmg, 0, player.whoAmI);

            Main.projectile[pro].friendly  = true;
            Main.projectile[pro].hostile   = false;
            Main.projectile[pro].timeLeft  = 300;
            Main.projectile[pro].damage   *= 1 + (((player.magicCrit) + (player.thrownCrit) + (player.meleeCrit) + (player.rangedCrit)) / 100);
            Main.projectile[proj].friendly = true;
            Main.projectile[proj].hostile  = false;
            //Main.projectile[proj].penetrate = 1;
            //Main.projectile[proj].tileCollide = false;
            //Main.projectile[proj].timeLeft = 1;
            Main.projectile[proj].damage *= 1 + (((player.magicCrit) + (player.thrownCrit) + (player.meleeCrit) + (player.rangedCrit)) / 100);

            return(proj);
        }
Beispiel #41
0
 public static Vector2 ToNum(this Microsoft.Xna.Framework.Vector2 v)
 {
     return(new Vector2(v.X, v.Y));
 }
        internal static ControllerInputBinding createStickCursorMoveBinding(ControllerStick stick, Microsoft.Xna.Framework.Vector2 comparisonVector, StickState comparisonState, StickState oldState, MouseMoveType moveType, Types.UIntVector moveScale, CommandTarget commandTarget, InputMode applicableMode)
        {
            ControllerInputBinding newBinding = new ControllerInputBinding();

            newBinding.stick = new ControllerStickBinding(stick, comparisonVector, comparisonState, oldState);

            CursorMoveCommand newCommand = new CursorMoveCommand();

            newCommand.mouseMove = new MouseMove();
            newCommand.mouseMove.commandTarget = commandTarget;
            newCommand.mouseMove.moveType      = moveType;
            newCommand.mouseMove.moveScale     = moveScale;

            newCommand.applicableMode = applicableMode;
            newBinding.commands.Add(newCommand);
            //bindings.Add(newBinding);

            return(newBinding);
        }
Beispiel #43
0
        public UIDebugMenu() : base(UIDialogStyle.Tall, true)
        {
            SetSize(500, 300);
            Caption = "Debug Tools";

            Position = new Microsoft.Xna.Framework.Vector2(
                (GlobalSettings.Default.GraphicsWidth / 2.0f) - 250,
                (GlobalSettings.Default.GraphicsHeight / 2.0f) - 150
                );

            Add(new UIImage()
            {
                Texture  = GetTexture(0x00000Cbfb00000001),
                Position = new Microsoft.Xna.Framework.Vector2(40, 95)
            });

            ContentBrowserBtn                = new UIButton();
            ContentBrowserBtn.Caption        = "Nhood Global Cycle";
            ContentBrowserBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 50);
            ContentBrowserBtn.Width          = 300;
            ContentBrowserBtn.OnButtonClick += x =>
            {
                UIAlert.Prompt("Force Cycle", "How many days in the future do you want neighbourhoods to process?", true, (response) =>
                {
                    uint result;
                    if (!uint.TryParse(response, out result))
                    {
                        return;
                    }

                    FindController <CoreGameScreenController>()?.NeighborhoodProtocol.PretendDate(ClientEpoch.Now + 60 * 60 * 24 * result, (code) => { });
                });
            };
            Add(ContentBrowserBtn);

            var connectLocalBtn = new UIButton();

            connectLocalBtn.Caption        = (GlobalSettings.Default.UseCustomServer) ? "Use default server (TSO)" : "Use custom defined server";
            connectLocalBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 90);
            connectLocalBtn.Width          = 300;
            connectLocalBtn.OnButtonClick += x =>
            {
                GlobalSettings.Default.UseCustomServer = !GlobalSettings.Default.UseCustomServer;
                connectLocalBtn.Caption = (GlobalSettings.Default.UseCustomServer) ? "Use default server (TSO)" : "Use custom defined server";
                GlobalSettings.Default.Save();
            };
            Add(connectLocalBtn);

            var cityPainterBtn = new UIButton();

            cityPainterBtn.Caption        = "City Painter";
            cityPainterBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 130);
            cityPainterBtn.Width          = 150;
            cityPainterBtn.OnButtonClick += x =>
            {
                var core = (GameFacade.Screens.CurrentUIScreen as CoreGameScreen);
                if (core == null)
                {
                    return;
                }
                if (core.CityRenderer.Plugin == null)
                {
                    core.CityRenderer.Plugin = new Rendering.City.Plugins.MapPainterPlugin(core.CityRenderer);
                    cityPainterBtn.Caption   = "Disable Painter";
                }
                else
                {
                    core.CityRenderer.Plugin = null;
                    cityPainterBtn.Caption   = "City Painter";
                }
            };
            Add(cityPainterBtn);

            var ngbhBtn = new UIButton();

            ngbhBtn.Caption        = "Ngbh Editor";
            ngbhBtn.Position       = new Microsoft.Xna.Framework.Vector2(160 + 150, 130);
            ngbhBtn.Width          = 150;
            ngbhBtn.OnButtonClick += x =>
            {
                var core = (GameFacade.Screens.CurrentUIScreen as CoreGameScreen);
                if (core == null)
                {
                    return;
                }
                if (core.CityRenderer.Plugin == null)
                {
                    core.CityRenderer.Plugin = new Rendering.City.Plugins.NeighbourhoodEditPlugin(core.CityRenderer);
                    ngbhBtn.Caption          = "Disable Editor";
                }
                else
                {
                    core.CityRenderer.Plugin = null;
                    ngbhBtn.Caption          = "Ngbh Editor";
                }
            };
            Add(ngbhBtn);

            var benchmarkBtn = new UIButton();

            benchmarkBtn.Caption        = "VM Performance Benchmark (100k ticks)";
            benchmarkBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 170);
            benchmarkBtn.Width          = 300;
            benchmarkBtn.OnButtonClick += x =>
            {
                var core = (GameFacade.Screens.CurrentUIScreen as IGameScreen);
                if (core == null || core.vm == null)
                {
                    UIScreen.GlobalShowAlert(new UIAlertOptions()
                    {
                        Message = "A VM must be running to benchmark performance."
                    }, true);
                    return;
                }
                var watch = new Stopwatch();
                watch.Start();

                var vm   = core.vm;
                var tick = vm.Scheduler.CurrentTickID + 1;
                for (int i = 0; i < 100000; i++)
                {
                    vm.InternalTick(tick++);
                }

                watch.Stop();

                UIScreen.GlobalShowAlert(new UIAlertOptions()
                {
                    Message = "Ran 100k ticks in " + watch.ElapsedMilliseconds + "ms."
                }, true);
            };
            Add(benchmarkBtn);

            var resyncBtn = new UIButton();

            resyncBtn.Caption        = "Lot Disconnect";
            resyncBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 210);
            resyncBtn.Width          = 150;
            resyncBtn.OnButtonClick += x =>
            {
                var kernel = FSOFacade.Kernel;
                if (kernel != null)
                {
                    var reg = kernel.Get <Regulators.LotConnectionRegulator>();
                    reg.Client.Disconnect();
                }

                /*
                 * var core = (GameFacade.Screens.CurrentUIScreen as IGameScreen);
                 * if (core == null || core.vm == null)
                 * {
                 *  UIScreen.GlobalShowAlert(new UIAlertOptions()
                 *  {
                 *      Message = "A VM must be running to force a resync."
                 *  }, true);
                 *  return;
                 * }
                 * core.vm.SendCommand(new VMRequestResyncCmd());
                 */
            };
            Add(resyncBtn);

            var cityDCBtn = new UIButton();

            cityDCBtn.Caption        = "City Disconnect";
            cityDCBtn.Position       = new Microsoft.Xna.Framework.Vector2(160 + 150, 210);
            cityDCBtn.Width          = 150;
            cityDCBtn.OnButtonClick += x =>
            {
                var kernel = FSOFacade.Kernel;
                if (kernel != null)
                {
                    var reg = kernel.Get <Regulators.CityConnectionRegulator>();
                    reg.Client.Disconnect();
                }
            };
            Add(cityDCBtn);

            serverNameBox   = new UITextBox();
            serverNameBox.X = 50;
            serverNameBox.Y = 300 - 54;
            serverNameBox.SetSize(500 - 100, 25);
            serverNameBox.CurrentText = GlobalSettings.Default.GameEntryUrl;

            Add(serverNameBox);
        }
        internal static ControllerInputBinding[] createStickKeyBinding(ControllerStick stick, Microsoft.Xna.Framework.Vector2 comparisonVector, System.Windows.Forms.Keys key, InputMode applicableMode = InputMode.All, CommandTarget target = CommandTarget.None)
        {
            ControllerInputBinding downResult = new ControllerInputBinding();

            downResult.stick = new ControllerStickBinding(stick, comparisonVector, StickState.NotEqual);
            KeyboardCommand newCommand = new KeyboardCommand();

            newCommand.key            = key;
            newCommand.commandState   = ButtonState.Down;
            newCommand.applicableMode = applicableMode;
            newCommand.target         = target;
            downResult.commands.Add(newCommand);

            ControllerInputBinding upResult = new ControllerInputBinding();

            upResult                  = new ControllerInputBinding();
            upResult.stick            = new ControllerStickBinding(stick, comparisonVector, StickState.Equal);
            newCommand                = new KeyboardCommand();
            newCommand.key            = key;
            newCommand.commandState   = ButtonState.Up;
            newCommand.applicableMode = applicableMode;
            newCommand.target         = target;
            upResult.commands.Add(newCommand);

            return(new ControllerInputBinding[2] {
                downResult, upResult
            });
        }
Beispiel #45
0
        /// <summary>
        /// Ray-cast against the proxies in the tree. This relies on the callback
        /// to perform a exact ray-cast in the case were the proxy contains a Shape.
        /// The callback also performs the any collision filtering. This has performance
        /// roughly equal to k * log(n), where k is the number of collisions and n is the
        /// number of proxies in the tree.
        /// </summary>
        /// <param name="callback">A callback class that is called for each proxy that is hit by the ray.</param>
        /// <param name="input">The ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).</param>
        public void RayCast(BroadPhaseRayCastCallback callback, ref RayCastInput input)
        {
            Vector2 p1 = input.Point1;
            Vector2 p2 = input.Point2;
            Vector2 r  = p2 - p1;

            Debug.Assert(r.LengthSquared() > 0.0f);
            r.Normalize();

            // v is perpendicular to the segment.
            Vector2 absV = MathUtils.Abs(new Vector2(-r.Y, r.X)); //FPE: Inlined the 'v' variable

            // Separating axis for segment (Gino, p80).
            // |dot(v, p1 - c)| > dot(|v|, h)

            float maxFraction = input.MaxFraction;

            // Build a bounding box for the segment.
            AABB segmentAABB = new AABB();

            {
                Vector2 t = p1 + maxFraction * (p2 - p1);
                Vector2.Min(ref p1, ref t, out segmentAABB.LowerBound);
                Vector2.Max(ref p1, ref t, out segmentAABB.UpperBound);
            }

            _raycastStack.Clear();
            _raycastStack.Push(_root);

            while (_raycastStack.Count > 0)
            {
                int nodeId = _raycastStack.Pop();
                if (nodeId == NullNode)
                {
                    continue;
                }

                //TreeNode<T>* node = &_nodes[nodeId];

                if (AABB.TestOverlap(ref _nodes[nodeId].AABB, ref segmentAABB) == false)
                {
                    continue;
                }

                // Separating axis for segment (Gino, p80).
                // |dot(v, p1 - c)| > dot(|v|, h)
                Vector2 c          = _nodes[nodeId].AABB.Center;
                Vector2 h          = _nodes[nodeId].AABB.Extents;
                float   separation = Math.Abs(Vector2.Dot(new Vector2(-r.Y, r.X), p1 - c)) - Vector2.Dot(absV, h);
                if (separation > 0.0f)
                {
                    continue;
                }

                if (_nodes[nodeId].IsLeaf())
                {
                    RayCastInput subInput;
                    subInput.Point1      = input.Point1;
                    subInput.Point2      = input.Point2;
                    subInput.MaxFraction = maxFraction;

                    float value = callback(ref subInput, nodeId);

                    if (value == 0.0f)
                    {
                        // the client has terminated the raycast.
                        return;
                    }

                    if (value > 0.0f)
                    {
                        // Update segment bounding box.
                        maxFraction = value;
                        Vector2 t = p1 + maxFraction * (p2 - p1);
                        Vector2.Min(ref p1, ref t, out segmentAABB.LowerBound);
                        Vector2.Max(ref p1, ref t, out segmentAABB.UpperBound);
                    }
                }
                else
                {
                    _raycastStack.Push(_nodes[nodeId].Child1);
                    _raycastStack.Push(_nodes[nodeId].Child2);
                }
            }
        }
Beispiel #46
0
 private void cancelBtn_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     new NewGameWindow();
     Close();
 }
Beispiel #47
0
 void singlePlayerBtn_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     new ChooseCampaignWindow();
     Close();
 }
Beispiel #48
0
 private async void customGameBtn_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     await WinWarCS.Platform.UI.ShowMessageDialog("Not implemented yet");
 }
Beispiel #49
0
        public void receiveMoveMouseJoint(NetIncomingMessage im)
        {
            Vector2 worldAnchorB = new Vector2(im.ReadFloat(), im.ReadFloat());

            _game.physicsManager.moveRemoteMouseJoint(worldAnchorB);
        }
Beispiel #50
0
 public static System.Drawing.Point ToSysPoint(this Microsoft.Xna.Framework.Vector2 v2)
 {
     return(new System.Drawing.Point((int)v2.X, (int)v2.Y));
 }
Beispiel #51
0
 public override bool Shoot(Terraria.Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     return(true);
 }
Beispiel #52
0
 void closeButton_OnMouseUpInside(Microsoft.Xna.Framework.Vector2 position)
 {
     Close();
 }
Beispiel #53
0
        protected override void InitPhysics()
        {
            float pixel = (float)(1.0 / Configuration.MeterInPixels);

            float fixture_scale_y = 0.75f;

            float corner_clip_x = 7.0f * pixel;
            float corner_clip_y = 2.0f * pixel;
            float y_shift = 2.0f * pixel;

            float w, h, half_h, qtr_h, scl_h;
            if (Texture.Regions != null && Texture.Regions.Length > 0)
            {
                var size = Texture.DefaultRegion.Size;
                w = (float)(_Scale.X * size.X) * pixel;
                h = (float)(_Scale.Y * size.Y) * pixel;
            }
            else
            {
                w = (float)(_Scale.X * Texture.Width) * pixel;
                h = (float)(_Scale.Y * Texture.Height) * pixel;
            }
            scl_h = fixture_scale_y * h;
            half_h = 0.5f * h;
            var half_w_h = new Microsoft.Xna.Framework.Vector2(w * 0.5f, half_h);
            var msv2 = new Microsoft.Xna.Framework.Vector2(
                (float)(_Position.X) * pixel,
                (float)(_Position.Y) * pixel);
            _SpriteBody = BodyFactory.CreateBody(_RenderSet.Scene.World, Microsoft.Xna.Framework.Vector2.Zero, this);

            Microsoft.Xna.Framework.Vector2 a, b, c, d, e00, e01, e10, e11;

            var verts = new Vertices(new Microsoft.Xna.Framework.Vector2[] {
                e00 = new Microsoft.Xna.Framework.Vector2(corner_clip_x, 0.0f),
                e10 = new Microsoft.Xna.Framework.Vector2(w - corner_clip_x, 0.0f),
                b = new Microsoft.Xna.Framework.Vector2(w, corner_clip_y),
                c = new Microsoft.Xna.Framework.Vector2(w, scl_h - corner_clip_y),
                e11 = new Microsoft.Xna.Framework.Vector2(w - corner_clip_x, scl_h),
                e01 = new Microsoft.Xna.Framework.Vector2(corner_clip_x, scl_h),
                d = new Microsoft.Xna.Framework.Vector2(0.0f, scl_h - corner_clip_y),
                a = new Microsoft.Xna.Framework.Vector2(0.0f, corner_clip_y),
            });

            var verts_upper = new Vertices();
            verts.ForEach(v => {
                v.X -= half_w_h.X;
                v.Y = y_shift + v.Y * fixture_scale_y + half_h * (0.5f - fixture_scale_y);
                verts_upper.Add(v);
                //Console.Write("{0}, ", v.ToString());
            });
            var verts_lower = new Vertices();
            verts.ForEach(v => {
                v.X -= half_w_h.X;
                v.Y = y_shift + v.Y * fixture_scale_y - half_h;
                verts_lower.Add(v);
                //Console.Write("{0}, ", v.ToString());
            });

            FixtureUpper = FixtureFactory.AttachPolygon(verts_upper, 100.0f, _SpriteBody);
            FixtureLower = FixtureFactory.AttachPolygon(verts_lower, 100.0f, _SpriteBody);

            _SpriteBody.BodyType = BodyType.Dynamic;
            _SpriteBody.FixedRotation = true;
            //_SpriteFixture = FarseerPhysics.Factories.FixtureFactory.AttachEdge
            _SpriteBody.Mass = 100.0f;
            Body.OnCollision += HandleOnCollision;
            Body.OnSeparation += HandleOnSeparation;
            Preserve = true;

            Body.SleepingAllowed = false; // Avoid dumb shit

            // HACK: Only enable bodies for which the object is in the current scene
            Body.Enabled = this.RenderSet.Scene == Program.MainGame.CurrentScene;

            InitBlueprints();
        }
Beispiel #54
0
 public static void Convert(ref BEPUutilities.Vector2 bepuVector, out Vector2 xnaVector)
 {
     xnaVector.X = bepuVector.X;
     xnaVector.Y = bepuVector.Y;
 }
        public override void DrawUI()
        {
            base.DrawUI();
            //Game.DataTextDrawer.Draw("Time steps elapsed: ", timeStepsElapsed, new Vector2(600, 600));
            //return;
            Microsoft.Xna.Framework.Vector2 origin = new Microsoft.Xna.Framework.Vector2(100, 50);
            Microsoft.Xna.Framework.Vector2 spacing = new Microsoft.Xna.Framework.Vector2(80, 50);
            //Draw the horizontal core counts.
            for (int i = 0; i < testResults.GetLength(0); i++)
            {
                Game.DataTextDrawer.Draw(i + 1, origin + new Microsoft.Xna.Framework.Vector2(spacing.X * i, -30));
            }
            for (int i = 0; i < testResults.GetLength(1); i++)
            {
                Game.DataTextDrawer.Draw(i, origin + new Microsoft.Xna.Framework.Vector2(-30, spacing.Y * i));
            }

            for (int i = 0; i < testResults.GetLength(0); i++)
            {
                int lowestTime = 0;
                for (int j = 0; j < testResults.GetLength(1); j++)
                {
                    Game.DataTextDrawer.Draw(testResults[i, j] * 1e3, 0, origin + new Microsoft.Xna.Framework.Vector2(spacing.X * i, spacing.Y * j));
                    if (testResults[i, j] < testResults[i, lowestTime])
                        lowestTime = j;
                }
            }



        }
Beispiel #56
0
 public static void Convert(ref Vector2 xnaVector, out BEPUutilities.Vector2 bepuVector)
 {
     bepuVector.X = xnaVector.X;
     bepuVector.Y = xnaVector.Y;
 }
Beispiel #57
0
 private bool IsClockwise(Vector2 a, Vector2 b, Vector2 c)
 {
     // this is a cross product / shoelace formula math thing
     // just google it, it's what I did
     return a.X * b.Y - b.X * a.Y + b.X * c.Y - c.X * b.Y + c.X * a.Y - a.X * c.Y > 0;
 }
Beispiel #58
0
        internal override void InitVelocityConstraints(ref SolverData data)
        {
            _indexA       = BodyA.IslandIndex;
            _indexB       = BodyB.IslandIndex;
            _localCenterA = BodyA._sweep.LocalCenter;
            _localCenterB = BodyB._sweep.LocalCenter;
            _invMassA     = BodyA._invMass;
            _invMassB     = BodyB._invMass;
            _invIA        = BodyA._invI;
            _invIB        = BodyB._invI;

            float mA = _invMassA, mB = _invMassB;
            float iA = _invIA, iB = _invIB;

            Vector2 cA = data.positions[_indexA].c;
            float   aA = data.positions[_indexA].a;
            Vector2 vA = data.velocities[_indexA].v;
            float   wA = data.velocities[_indexA].w;

            Vector2 cB = data.positions[_indexB].c;
            float   aB = data.positions[_indexB].a;
            Vector2 vB = data.velocities[_indexB].v;
            float   wB = data.velocities[_indexB].w;

            Complex qA = Complex.FromAngle(aA);
            Complex qB = Complex.FromAngle(aB);

            // Compute the effective masses.
            Vector2 rA = Complex.Multiply(LocalAnchorA - _localCenterA, ref qA);
            Vector2 rB = Complex.Multiply(LocalAnchorB - _localCenterB, ref qB);
            Vector2 d1 = cB + rB - cA - rA;

            // Point to line constraint
            {
                _ay  = Complex.Multiply(ref _localYAxis, ref qA);
                _sAy = MathUtils.Cross(d1 + rA, _ay);
                _sBy = MathUtils.Cross(ref rB, ref _ay);

                _mass = mA + mB + iA * _sAy * _sAy + iB * _sBy * _sBy;

                if (_mass > 0.0f)
                {
                    _mass = 1.0f / _mass;
                }
            }

            // Spring constraint
            _springMass = 0.0f;
            _bias       = 0.0f;
            _gamma      = 0.0f;
            if (Frequency > 0.0f)
            {
                _ax  = Complex.Multiply(ref _localXAxis, ref qA);
                _sAx = MathUtils.Cross(d1 + rA, _ax);
                _sBx = MathUtils.Cross(ref rB, ref _ax);

                float invMass = mA + mB + iA * _sAx * _sAx + iB * _sBx * _sBx;

                if (invMass > 0.0f)
                {
                    _springMass = 1.0f / invMass;

                    float C = Vector2.Dot(d1, _ax);

                    // Frequency
                    float omega = Constant.Tau * Frequency;

                    // Damping coefficient
                    float d = 2.0f * _springMass * DampingRatio * omega;

                    // Spring stiffness
                    float k = _springMass * omega * omega;

                    // magic formulas
                    float h = data.step.dt;
                    _gamma = h * (d + h * k);
                    if (_gamma > 0.0f)
                    {
                        _gamma = 1.0f / _gamma;
                    }

                    _bias = C * h * k * _gamma;

                    _springMass = invMass + _gamma;
                    if (_springMass > 0.0f)
                    {
                        _springMass = 1.0f / _springMass;
                    }
                }
            }
            else
            {
                _springImpulse = 0.0f;
            }

            // Rotational motor
            if (_enableMotor)
            {
                _motorMass = iA + iB;
                if (_motorMass > 0.0f)
                {
                    _motorMass = 1.0f / _motorMass;
                }
            }
            else
            {
                _motorMass    = 0.0f;
                _motorImpulse = 0.0f;
            }

            if (data.step.warmStarting)
            {
                // Account for variable time step.
                _impulse       *= data.step.dtRatio;
                _springImpulse *= data.step.dtRatio;
                _motorImpulse  *= data.step.dtRatio;

                Vector2 P  = _impulse * _ay + _springImpulse * _ax;
                float   LA = _impulse * _sAy + _springImpulse * _sAx + _motorImpulse;
                float   LB = _impulse * _sBy + _springImpulse * _sBx + _motorImpulse;

                vA -= _invMassA * P;
                wA -= _invIA * LA;

                vB += _invMassB * P;
                wB += _invIB * LB;
            }
            else
            {
                _impulse       = 0.0f;
                _springImpulse = 0.0f;
                _motorImpulse  = 0.0f;
            }

            data.velocities[_indexA].v = vA;
            data.velocities[_indexA].w = wA;
            data.velocities[_indexB].v = vB;
            data.velocities[_indexB].w = wB;
        }
Beispiel #59
0
        private void receiveCreateMouseJoint(NetIncomingMessage im)
        {
            int entityId = im.ReadInt32();
            Body body = _game.entityManager.getEntity(entityId);
            Vector2 localAnchorA = new Vector2(im.ReadFloat(), im.ReadFloat());
            Vector2 point = new Vector2(im.ReadFloat(), im.ReadFloat());

            if (body != null)
            {
                _game.physicsManager.createRemoteMouseJoint(body, body.GetWorldVector(ref localAnchorA), point);
            }
        }
Beispiel #60
0
        internal override void SolveVelocityConstraints(ref SolverData data)
        {
            float mA = _invMassA, mB = _invMassB;
            float iA = _invIA, iB = _invIB;

            Vector2 vA = data.velocities[_indexA].v;
            float   wA = data.velocities[_indexA].w;
            Vector2 vB = data.velocities[_indexB].v;
            float   wB = data.velocities[_indexB].w;

            // Solve spring constraint
            {
                float Cdot    = Vector2.Dot(_ax, vB - vA) + _sBx * wB - _sAx * wA;
                float impulse = -_springMass * (Cdot + _bias + _gamma * _springImpulse);
                _springImpulse += impulse;

                Vector2 P  = impulse * _ax;
                float   LA = impulse * _sAx;
                float   LB = impulse * _sBx;

                vA -= mA * P;
                wA -= iA * LA;

                vB += mB * P;
                wB += iB * LB;
            }

            // Solve rotational motor constraint
            {
                float Cdot    = wB - wA - _motorSpeed;
                float impulse = -_motorMass * Cdot;

                float oldImpulse = _motorImpulse;
                float maxImpulse = data.step.dt * _maxMotorTorque;
                _motorImpulse = MathUtils.Clamp(_motorImpulse + impulse, -maxImpulse, maxImpulse);
                impulse       = _motorImpulse - oldImpulse;

                wA -= iA * impulse;
                wB += iB * impulse;
            }

            // Solve point to line constraint
            {
                float Cdot    = Vector2.Dot(_ay, vB - vA) + _sBy * wB - _sAy * wA;
                float impulse = -_mass * Cdot;
                _impulse += impulse;

                Vector2 P  = impulse * _ay;
                float   LA = impulse * _sAy;
                float   LB = impulse * _sBy;

                vA -= mA * P;
                wA -= iA * LA;

                vB += mB * P;
                wB += iB * LB;
            }

            data.velocities[_indexA].v = vA;
            data.velocities[_indexA].w = wA;
            data.velocities[_indexB].v = vB;
            data.velocities[_indexB].w = wB;
        }