Example #1
0
 public void PointToVector2()
 {
     var pt = new Point(-3, 5);
     var actual = pt.ToVector2();
     var expected = new System.Numerics.Vector2(-3, 5);
     Assert.AreEqual(expected, actual);
 }
Example #2
0
 void UpdateGridPosition(Point position, bool warp)
 {
   _targetPos = position;
   if (warp)
   {
     FinishMove();
     transform.position = _targetPos.ToVector2() * gridCellSize;
   }
   else
   {
     StartMove();
   }
 }
        public override void Draw(SpriteBatch sb)
        {
            if (tiles == null || tiles.Length != BrushSize || tiles[0][0] != BaseTile) {
                tiles = UtilityFramework.Util.GetInitialized2DArray<Tile>(BrushSize, BrushSize, BaseTile);
            }

            for (int x = 0; x < BrushSize; x++) {
                for (int y = 0; y < BrushSize; y++) {
                    Point p = new Point(Origin.X + x - BrushSize / 2, Origin.Y + y - BrushSize / 2);
                    if (p.X >= 0 && p.Y >= 0 && p.X < Map.Settings.Dimensions.XCount && p.Y < Map.Settings.Dimensions.YCount && Map.GetTileAt(p.X, p.Y) != BaseTile) {
                        tiles[x][y].Draw(sb, p.ToVector2() * Map.Settings.TileSize + Map.Settings.TileSize / 2.0f, Color.White);
                    }
                }
            }
        }
        public AnimatedBackground(string texture, Point worldDimensions, int segmentSeed)
        {
            _texture = "anim-" + texture;
            _worldDimensions = worldDimensions.ToVector2();

            _generatorSeed = segmentSeed;
            _generatorLastValue = 0;
            _generatorIteration = 0;
            _segmentSequenceIndex = 0;

            CalculateBackgroundTargetArea();
            RenderLayer = Render_Layer;
            Visible = true;
            Wrap = false;

            SetCloudMetrics(texture);
        }
        public GameplayScreen()
        {
            Viewport            = new Rectangle(0, 0, 1920, 1080);
            centerScreen        = Viewport.Center;
            CenterScreenVector2 = centerScreen.ToVector2();

            world = new ClientWorldState();
            world.CharacterAdded += World_CharacterAdded;
            network            = NetworkEngine.Instance; //networkEngine;
            network.WorldState = world;
            worldPump          = new WorldPump();
            worldPump.State    = world;

            effectManager = new EffectManager();
            effectManager.UseDayNightCycle = true;
            effectManager.DayColor         = Color.White;
            effectManager.NightColor       = new Color(.2f, .2f, .4f);//Color.DarkBlue;

            //inventoryScreen = new InventoryScreen();
            //inventoryScreen.ItemUsed += InventoryScreen_ItemUsed;
            //inventoryScreen.Player = world.PlayerCharacter;
        }
Example #6
0
        public static void DrawFancyBar(
            SpriteBatch spriteBatch,
            float lifePercent,
            Texture2D barIconTexture,
            Rectangle barIconFrame)
        {
            Texture2D texture2D      = ((Asset <Texture2D>)Main.Assets.Request <Texture2D>("Images/UI/UI_BossBar", (AssetRequestMode)1)).Value;
            Point     p1             = new Point(456, 22);
            Point     p2             = new Point(32, 24);
            int       verticalFrames = 6;
            Rectangle rectangle1     = texture2D.Frame(1, verticalFrames, 0, 3, 0, 0);
            Color     color          = Color.White * 0.2f;
            int       num1           = (int)((double)p1.X * (double)lifePercent);
            int       num2           = num1 - num1 % 2;
            Rectangle rectangle2     = texture2D.Frame(1, verticalFrames, 0, 2, 0, 0);

            rectangle2.X     += p2.X;
            rectangle2.Y     += p2.Y;
            rectangle2.Width  = 2;
            rectangle2.Height = p1.Y;
            Rectangle rectangle3 = texture2D.Frame(1, verticalFrames, 0, 1, 0, 0);

            rectangle3.X     += p2.X;
            rectangle3.Y     += p2.Y;
            rectangle3.Width  = 2;
            rectangle3.Height = p1.Y;
            Rectangle r        = Utils.CenteredRectangle(Main.ScreenSize.ToVector2() * new Vector2(0.5f, 1f) + new Vector2(0.0f, -50f), p1.ToVector2());
            Vector2   position = r.TopLeft() - p2.ToVector2();

            spriteBatch.Draw(texture2D, position, new Rectangle?(rectangle1), color, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
            spriteBatch.Draw(texture2D, r.TopLeft(), new Rectangle?(rectangle2), Color.White, 0.0f, Vector2.Zero, new Vector2((float)(num2 / rectangle2.Width), 1f), SpriteEffects.None, 0.0f);
            spriteBatch.Draw(texture2D, r.TopLeft() + new Vector2((float)(num2 - 2), 0.0f), new Rectangle?(rectangle3), Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
            Rectangle rectangle4 = texture2D.Frame(1, verticalFrames, 0, 0, 0, 0);

            spriteBatch.Draw(texture2D, position, new Rectangle?(rectangle4), Color.White, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
            Vector2 vector2 = new Vector2(4f, 20f) + new Vector2(26f, 28f) / 2f;

            spriteBatch.Draw(barIconTexture, position + vector2, new Rectangle?(barIconFrame), Color.White, 0.0f, barIconFrame.Size() / 2f, 1f, SpriteEffects.None, 0.0f);
        }
Example #7
0
        private static void PlaceCurvedLine(
            Point startPoint,
            Point endPoint,
            Point anchorOffset,
            DunesBiome.DunesDescription description)
        {
            Point p = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);

            p.X += anchorOffset.X;
            p.Y += anchorOffset.Y;
            Vector2 vector2_1 = startPoint.ToVector2();
            Vector2 vector2_2 = endPoint.ToVector2();
            Vector2 vector2_3 = p.ToVector2();
            float   num1      = (float)(0.5 / ((double)vector2_2.X - (double)vector2_1.X));
            Point   point1    = new Point(-1, -1);

            for (float amount = 0.0f; (double)amount <= 1.0; amount += num1)
            {
                Point point2 = Vector2.Lerp(Vector2.Lerp(vector2_1, vector2_3, amount), Vector2.Lerp(vector2_3, vector2_2, amount), amount).ToPoint();
                if (!(point2 == point1))
                {
                    point1 = point2;
                    int num2 = description.Area.Width / 2 - Math.Abs(point2.X - description.Area.Center.X);
                    int num3 = (int)description.Surface[point2.X] + (int)(Math.Sqrt((double)num2) * 3.0);
                    for (int index = point2.Y - 10; index < point2.Y; ++index)
                    {
                        if (GenBase._tiles[point2.X, index].active() && GenBase._tiles[point2.X, index].type != (ushort)53)
                        {
                            GenBase._tiles[point2.X, index].ClearEverything();
                        }
                    }
                    for (int y = point2.Y; y < num3; ++y)
                    {
                        GenBase._tiles[point2.X, y].ResetToType((ushort)53);
                        Tile.SmoothSlope(point2.X, y, true, false);
                    }
                }
            }
        }
        public void MouseEvents(UIMouseEventType type, UpdateState state)
        {
            switch (type)
            {
            case UIMouseEventType.MouseDown:
                MouseDownID    = state.CurrentMouseID;
                MouseDownTime  = 0;
                MouseDownAt    = state.MouseState.Position;
                InScroll       = false;
                ScrollVelocity = 0;
                break;

            case UIMouseEventType.MouseUp:
                if (!InScroll)
                {
                    Select(GlobalPoint(MouseDownAt.ToVector2()).ToPoint());
                }
                else
                {
                    //calculate scroll velocity
                    if (ScrollVelocityHistory.Count > 1)
                    {
                        int total = 0;
                        ScrollVelocity = 0f;
                        for (int i = 1; i < ScrollVelocityHistory.Count; i++)
                        {
                            total++;
                            ScrollVelocity += ScrollVelocityHistory[i];
                        }
                        ScrollVelocity /= total;
                    }
                    ScrollVelocityHistory.Clear();
                }

                InScroll    = false;
                MouseDownID = -1;
                break;
            }
        }
Example #9
0
        public Point[] FindPath()
        {
            Tile startTile = map.GetTile(start);
            Tile endTile   = map.GetTile(end);

            if (startTile == null || endTile == null || startTile.blocked || endTile.blocked)
            {
                return(null);
            }

            Node startingNode = new Node(null, start, 0, (int)Vector2.Distance(start.ToVector2(), end.ToVector2()) * 10);

            openList.Add(startingNode);

            if (ProcessNextNode())
            {
                List <Point> points = new List <Point>();

                Node endNode = closedList.Find(node => node.position == end);

                if (endNode != null)
                {
                    points.Add(endNode.position);

                    Node next = endNode.parent;
                    while (next != null)
                    {
                        points.Add(next.position);
                        next = next.parent;
                    }

                    points.Reverse();

                    return(points.ToArray());
                }
            }

            return(null);
        }
Example #10
0
        /// <summary>
        /// Translate Layers into GameObject tiles.
        /// </summary>
        /// <param name="layer">The Layer object to translate.</param>
        /// <param name="spriteSheet">The spritesheet that connects the Layer data to a tile with different looks.</param>
        /// <param name="tileSize">The width and hight of one tile.</param>
        /// <param name="sortingLayer">The sorting layer of the sprite.</param>
        /// <param name="sortingOrder">The sorting order of the sprite within the sorting layer.</param>
        /// <param name="isSolid">Indicates whether the GameObject tiles in this Layer should have a RigidBody or not.</param>
        /// <param name="worldOffset">The world offset of the top left corner of the layer.</param>
        /// <returns></returns>
        public static IEnumerable <GameObject> LoadLayer(Layer layer, Texture2D spriteSheet, Point tileSize, SortingLayer sortingLayer, int sortingOrder, bool isSolid, Vector2 worldOffset)
        {
            for (int y = 0; y < layer.Height; y++)
            {
                for (int x = 0; x < layer.Width; x++)
                {
                    int i  = y * layer.Width + x;
                    int id = layer.Data[i];
                    if (id != 0)
                    {
                        Vector2    position   = new Vector2(worldOffset.X + x * tileSize.X, worldOffset.Y + y * tileSize.Y);
                        GameObject gameObject = new GameObject(new Transform(position));

                        Point tilePos = new Point(
                            (id - 1) % (spriteSheet.Width / tileSize.X),
                            (id - 1) / (spriteSheet.Width / tileSize.X));
                        Sprite         sprite   = new Sprite(spriteSheet, new Rectangle(tilePos * tileSize, tileSize));
                        SpriteRenderer renderer = new SpriteRenderer(sprite)
                        {
                            SortingLayer = sortingLayer,
                            SortingOrder = sortingOrder
                        };
                        gameObject.AddComponent(renderer);

                        if (isSolid)
                        {
                            Collider collider = new Collider(tileSize.ToVector2());
                            gameObject.AddComponent(collider);
                        }

                        yield return(gameObject);
                    }
                    else
                    {
                        yield return(null);
                    }
                }
            }
        }
Example #11
0
        public static void Draw(
            this SpriteBatch batch,
            Tileset tileset,
            Point location,
            int index,
            float layer = 0,
            Color?color = null)
        {
            color ??= Color.White;
            var tile = tileset.GetTile(index);

            batch.Draw(
                tile.Texture,
                location.ToVector2(),
                tile.Source,
                color.Value,
                0,
                Vector2.Zero,
                Vector2.One,
                SpriteEffects.None,
                layer);
        }
Example #12
0
 public override void Draw(SpriteBatch spriteBatch)
 {
     //spriteBatch.Begin();
     spriteBatch.Draw(Texture, Boundary, Color.White);
     if (!Enemy)
     {
         Skin = Game1.self.ShipsSkins.SingleOrDefault(p => p.ship == ship.Name).skin;
     }
     else
     {
         Skin = Game1.self.EnemyShipsSkins.SingleOrDefault(p => p.ship == ship.Name).skin;
     }
     if (Skin != null)
     {
         skinScale   = new Vector2();
         skinScale.X = (float)((Width - 2 * borderSize)) / (float)(Skin.Width);
         skinScale.Y = (float)((Height - 4 * borderSize)) / (float)(Skin.Height);
         spriteBatch.Draw(Skin, skinPosition.ToVector2(), scale: skinScale);
     }
     //spriteBatch.End();
     overlay.Draw(spriteBatch);
 }
Example #13
0
        public Snake(int start_delay, Point position)
        {
            this.InitialWaitDelay        = start_delay;
            this.CurrentLocation         = position;
            this.DirectionChangeLocation = this.CurrentLocation;
            this.InternalLocation        = position.ToVector2();
            this.Position  = this.InternalLocation;
            this.Direction = Directions.Right;
            this.State     = (this.InitialWaitDelay == 0) ? States.Alive : States.Waiting;

            var texture = ContentHolder.Get(Settings.CurrentSnake);
            var region  = new Region(texture, 0, 0, Snake.Size, Snake.Size, Snake.Size / 2, Snake.Size / 2);
            var sprite  = new Sprite(region);

            this.AddSprite("main", sprite);

            this.AddColliderRectangle(Directions.Up.ToString(), -Snake.Size / 2, -Snake.Size / 2, Snake.Size, 1, false);
            this.AddColliderRectangle(Directions.Down.ToString(), -Snake.Size / 2, Snake.Size / 2 - 1, Snake.Size, 1, false);
            this.AddColliderRectangle(Directions.Left.ToString(), -Snake.Size / 2, -Snake.Size / 2, 1, Snake.Size, false);
            this.AddColliderRectangle(Directions.Right.ToString(), Snake.Size / 2 - 1, -Snake.Size / 2, 1, Snake.Size, true);
            this.AddColliderRectangle(this.MouthColliderName, -Snake.Size / 2, -Snake.Size / 2, Snake.Size, Snake.Size, true);

            for (int i = 0; i < 2; i++)
            {
                var tail = new SnakeTail {
                    Position = new Vector2(this.Position.X - (i + 1) * Snake.Size, this.Position.Y),
                    Depth    = this.Depth + 1 + i
                };
                Engine.SpawnInstance(tail);
                this.Tail.Add(tail);
            }

            for (int i = 0; i < this.Tail.Count * Snake.Size; i++)
            {
                this.SnakeLocations["x"].Add(this.CurrentLocation.X - i);
                this.SnakeLocations["y"].Add(this.CurrentLocation.Y);
            }
        }
        private static void PlaceCurvedLine(Point startPoint, Point endPoint, Point anchorOffset, DunesDescription description)
        {
            Point p = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);

            p.X += anchorOffset.X;
            p.Y += anchorOffset.Y;
            Vector2 value  = startPoint.ToVector2();
            Vector2 value2 = endPoint.ToVector2();
            Vector2 vector = p.ToVector2();
            float   num    = 0.5f / (value2.X - value.X);
            Point   b      = new Point(-1, -1);

            for (float num2 = 0f; num2 <= 1f; num2 += num)
            {
                Vector2 value3 = Vector2.Lerp(value, vector, num2);
                Vector2 value4 = Vector2.Lerp(vector, value2, num2);
                Point   point  = Vector2.Lerp(value3, value4, num2).ToPoint();
                if (point == b)
                {
                    continue;
                }
                b = point;
                int num3 = description.Area.Width / 2 - Math.Abs(point.X - description.Area.Center.X);
                int num4 = description.Surface[point.X] + (int)(Math.Sqrt(num3) * 3.0);
                for (int i = point.Y - 10; i < point.Y; i++)
                {
                    if (GenBase._tiles[point.X, i].active() && GenBase._tiles[point.X, i].type != 53)
                    {
                        GenBase._tiles[point.X, i].ClearEverything();
                    }
                }
                for (int j = point.Y; j < num4; j++)
                {
                    GenBase._tiles[point.X, j].ResetToType(53);
                    Tile.SmoothSlope(point.X, j);
                }
            }
        }
Example #15
0
        private void PokeExits(int numExits)
        {
            int buffersmoller    = height - 10;
            int distanceToCenter = (buffersmoller * buffersmoller);

            Vector2 center = new Vector2(width / 2, height / 2);

            roomsize = 5;

            foreach (MazeRoom outermostRooms in mazeRooms.Where(testby => testby.gen > maxGen * 0.75f).OrderBy(testby => 0 - (new Vector2(testby.loc.X, testby.loc.Y) - new Vector2(width / 2, height / 2)).LengthSquared()).Take(numExits))
            {
                Point check1   = outermostRooms.loc.ToPoint();
                Point pointvec = (Vector2.Normalize(check1.ToVector2() - center) * 32).ToPoint();
                Point check2   = new Point(check1.X + pointvec.X, check1.Y + pointvec.Y);



                for (int xx = -roomsize; xx <= roomsize; xx += 1)
                {
                    for (int yy = -roomsize; yy <= roomsize; yy += 1)
                    {
                        foreach (Point there in IDGWorldGen.GetLine(check1, check2))
                        {
                            Point16 there2 = new Point16(there.X + xx, there.Y + yy);
                            if (InsideMap(there2.X, there2.Y))
                            {
                                Tile tileline = Main.tile[there2.X, there2.Y];
                                if (tileline.active())
                                {
                                    tileline.active(false);
                                    tileline.type = 0;// TileID.AmberGemspark;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #16
0
        internal PickUpEntity(List <BaseItem> lbi, Point loc)
        {
            location = loc.ToVector2() * 64;

            itemList = new List <BaseItem>(lbi);

            for (int i = 0; i < lbi.Count; i++)
            {
                itemIDs.Add(lbi[i].itemID);
                sprites.Add(new BaseSprite());
                sprites[i].bHasCollision = false;
                sprites[i].bHasShadow    = false;
                sprites[i].baseAnimations.Add(lbi[i].itemTexAndAnimation);
            }

            if (lbi.Count > 3)
            {
                sprites[0].spriteGameSize = new Rectangle((int)location.X, (int)location.Y, 32, 32);
                sprites[1].spriteGameSize = new Rectangle((int)location.X + 32, (int)location.Y, 32, 32);
                sprites[2].spriteGameSize = new Rectangle((int)location.X, (int)location.Y + 32, 32, 32);
                sprites[3].spriteGameSize = new Rectangle((int)location.X + 32, (int)location.Y + 32, 32, 32);
            }
            else if (lbi.Count == 3)
            {
                sprites[0].spriteGameSize = new Rectangle((int)location.X, (int)location.Y, 32, 32);
                sprites[1].spriteGameSize = new Rectangle((int)location.X + 32, (int)location.Y, 32, 32);
                sprites[2].spriteGameSize = new Rectangle((int)location.X + 16, (int)location.Y + 32, 32, 32);
            }
            else if (lbi.Count == 2)
            {
                sprites[0].spriteGameSize = new Rectangle((int)location.X, (int)location.Y + 16, 32, 32);
                sprites[1].spriteGameSize = new Rectangle((int)location.X + 32, (int)location.Y + 16, 32, 32);
            }
            else if (lbi.Count == 1)
            {
                sprites[0].spriteGameSize = new Rectangle((int)location.X + 6, (int)location.Y + 6, 48, 48);
            }
        }
Example #17
0
        /// <summary>
        /// determines what direction the player is swinging in and if the player is allowed to swing the tool.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="state"></param>
        internal void Player_SwingInDirection(GameObject sender, MouseState state)
        {
            Vector2 playerPos = player.globalPosition;
            Point   mousePos  = state.Position;
            Vector2 offset    = -(playerPos - mousePos.ToVector2());

            //change to cardinal direction
            if (Math.Abs(offset.X) > Math.Abs(offset.Y))
            {
                offset.X = Math.Sign(offset.X);
                offset.Y = 0;
            }
            else
            {
                offset.X = 0;
                offset.Y = Math.Sign(offset.Y);
            }

            if (player.tool.ready)
            {
                player.tool.Swing(offset);
            }
        }
Example #18
0
        public bool Intersects(Point other)
        {
            if (Active)
            {
                Circle  a = this;
                Vector2 b = other.ToVector2();
                float   r = 1 + a._radius;
                r *= r;
                float valueToCheck = ((other.X - a.Particle.Position.X) *
                                      (other.X - a.Particle.Position.X)) +
                                     ((other.Y - a.Particle.Position.Y)) *
                                     ((other.Y - a.Particle.Position.Y));

                bool result = r >= valueToCheck;

                Colliding = result;


                return(result);
            }

            return(false);
        }
Example #19
0
        public static bool IntersectsLine(Rectangle Box, Point s, Point e)
        {
            for (int i = 0; i < 4; i++)
            {
                int a = 0, b = 0;
                int x = 0, y = 0;
                switch (i)
                {
                case (0): a = Box.Left + 1; x = Box.Left + 1; b = Box.Top + 1; y = Box.Bottom - 1; break;                       //left side

                case (1): a = Box.Right - 1; x = Box.Right - 1; b = Box.Top + 1; y = Box.Bottom - 1; break;                     //right side

                case (2): a = Box.Left + 1; x = Box.Right - 1; b = Box.Top + 1; y = Box.Top + 1; break;                         //top side

                case (3): a = Box.Left + 1; x = Box.Right - 1; b = Box.Bottom - 1; y = Box.Bottom - 1; break;                   //bottom side
                }
                if (Intersects(s.ToVector2(), e.ToVector2(), new Vector2(a, b), new Vector2(x, y)))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #20
0
    Vector2 CreateRandomPosition()
    {
        // keep trying random positions until a valid one is found
        while (true)
        {
            // draw a random position within the target rectangle
            Point randomPos = new Point(
                ExtendedGame.Random.Next(targetRectangle.Width),
                ExtendedGame.Random.Next(targetRectangle.Height)
                ) + targetRectangle.Location;

            // get the pixel data at that position
            Rectangle rect           = new Rectangle(randomPos, new Point(1, 1));
            Color[]   retrievedColor = new Color[1];
            target.GetData(0, rect, retrievedColor, 0, 1);

            // if the pixel is fully opaque, accept it as the answer
            if (retrievedColor[0].A == 255)
            {
                return(randomPos.ToVector2());
            }
        }
    }
Example #21
0
        public void Generate(Level level, LocationType locationType, Point position, bool mirror = false)
        {
            Submarine           = OutpostGenerator.Generate(generationParams, locationType, onlyEntrance: false);
            Submarine.Info.Name = $"Ruin ({level.Seed})";
            Submarine.Info.Type = SubmarineType.Ruin;
            Submarine.TeamID    = CharacterTeamType.None;
            Submarine.SetPosition(position.ToVector2());

            if (mirror)
            {
                Submarine.FlipX();
            }

            Rectangle worldBorders = Submarine.Borders;

            worldBorders.Location += Submarine.WorldPosition.ToPoint();
            Area = new Rectangle(worldBorders.X, worldBorders.Y - worldBorders.Height, worldBorders.Width, worldBorders.Height);

            List <WayPoint> subWaypoints        = WayPoint.WayPointList.FindAll(wp => wp.Submarine == Submarine);
            int             interestingPosCount = 0;

            foreach (WayPoint wp in subWaypoints)
            {
                if (wp.SpawnType != SpawnType.Enemy)
                {
                    continue;
                }
                level.PositionsOfInterest.Add(new Level.InterestingPosition(wp.WorldPosition.ToPoint(), Level.PositionType.Ruin, this));
                interestingPosCount++;
            }

            if (interestingPosCount == 0)
            {
                //make sure there's at least on PositionsOfInterest in the ruins
                level.PositionsOfInterest.Add(new Level.InterestingPosition(subWaypoints.GetRandom(Rand.RandSync.Server).WorldPosition.ToPoint(), Level.PositionType.Ruin, this));
            }
        }
Example #22
0
        public void DrawRectangle(Point position, int width, int height, Color color)
        {
            this.TestStarted();
            const int shapeVertexCount = 4;
            const int shapeIndexCount  = 6;

            this.TestSpace(shapeVertexCount, shapeIndexCount);

            int x = position.X;
            int y = position.Y;

            y = (int)origin.Y - y;

            int left   = x;
            int right  = x + width;
            int bottom = y - height;
            int top    = y;

            Point a = new Point(left, top);
            Point b = new Point(right, top);
            Point c = new Point(right, bottom);
            Point d = new Point(left, bottom);

            this.indeces[this.indexCount++] = 0 + this.vertexCount;
            this.indeces[this.indexCount++] = 1 + this.vertexCount;
            this.indeces[this.indexCount++] = 2 + this.vertexCount;

            this.indeces[this.indexCount++] = 0 + this.vertexCount;
            this.indeces[this.indexCount++] = 2 + this.vertexCount;
            this.indeces[this.indexCount++] = 3 + this.vertexCount;

            this.vertices[this.vertexCount++] = new VertexPositionColor(new Vector3(a.ToVector2(), 0f), color);
            this.vertices[this.vertexCount++] = new VertexPositionColor(new Vector3(b.ToVector2(), 0f), color);
            this.vertices[this.vertexCount++] = new VertexPositionColor(new Vector3(c.ToVector2(), 0f), color);
            this.vertices[this.vertexCount++] = new VertexPositionColor(new Vector3(d.ToVector2(), 0f), color);
            this.shapeCount++;
        }
Example #23
0
 /// <summary>
 /// Solves collision with specified object.
 /// </summary>
 /// <param name="something">The collision object</param>
 /// <param name="gameLogicOnly">Simple mode indicator</param>
 /// <param name="gameTime">Game time</param>
 public override void Hit(Quadrangle something, bool gameLogicOnly, GameTime gameTime)
 {
     if (something is ToolBox)
     {
         Hit(something as ToolBox);
     }
     else if (something is HealBox)
     {
         Hit(something as HealBox);
     }
     else
     {
         if (!gameLogicOnly)
         {
             if (something == lastHitObject && gameTime.TotalGameTime - firstTimeHitObject > StuckTimeout)
             {
                 Point newPoint = Position.Quarter.GetRandomSquare(mft => mft == MapFillType.Road);
                 MoveTo(newPoint.ToVector2() * TownQuarter.SquareWidth + Vector2.One * TownQuarter.SquareWidth * 0.5f, azimuth);
                 lastHitObject = null;
                 if (tasks.Count != 0)
                 {
                     tasks.First.Value.ClearWaypoints();
                 }
             }
             else
             {
                 if (something != lastHitObject)
                 {
                     firstTimeHitObject = gameTime.TotalGameTime;
                 }
                 lastHitObject = something;
                 MoveTo(lastPosition, Azimuth);
                 GoBack((float)gameTime.ElapsedGameTime.TotalSeconds);
             }
         }
     }
 }
Example #24
0
        public static void BezierLine(Point Start, Point Control, Point End, Color color, float Layer, int Quality = 10)
        {
            Point Auxilary  = Point.Zero;
            Point PrevPoint = Point.Zero;

            // The Green Line
            int xa = getPt(Start.X, Control.X, 0);
            int ya = getPt(Start.Y, Control.Y, 0);
            int xb = getPt(Control.X, End.X, 0);
            int yb = getPt(Control.Y, End.Y, 0);

            PrevPoint = Auxilary;

            // The Black Dot
            Auxilary.X = getPt(xa, xb, 0);
            Auxilary.Y = getPt(ya, yb, 0);

            for (float i = 1.0f / Quality; i <= 1.01f; i += 1.0f / Quality)
            {
                // The Green Line
                xa = getPt(Start.X, Control.X, i);
                ya = getPt(Start.Y, Control.Y, i);
                xb = getPt(Control.X, End.X, i);
                yb = getPt(Control.Y, End.Y, i);

                PrevPoint = Auxilary;

                // The Black Dot
                Auxilary.X = getPt(xa, xb, i);
                Auxilary.Y = getPt(ya, yb, i);

                Rectangle Rect = Rectangle.Empty;
                Rect.Location = PrevPoint;
                Rect.Size     = new Point((int)Math.Ceiling((Auxilary - PrevPoint).ToVector2().Length()), 3);
                DrawLine(Rect, color, MathCompanion.GetAngle(PrevPoint.ToVector2(), Auxilary.ToVector2()), Layer, Vector2.Zero);
            }
        }
Example #25
0
        private void ShowCurrentTexture()
        {
            //Debug.Log("_animator.Animation: " + _animator.Animation);
            //Debug.Log("_animator.Animation.CurrentFrame: " + _animator.Animation.CurrentFrame);
            if (null == _animator.Animation || null == _animator.Animation.CurrentFrame)
            {
                return;
            }

            var texture = _animator.Animation.CurrentFrame.Texture;
            var mode    = CursorManager.RenderingMode;

            switch (mode)
            {
            case CursorRenderingMode.Auto:
            case CursorRenderingMode.ForceSoftware:
                Point offset = (Point)_offset.Clone();
                offset.Invert();
                //Debug.Log("ShowCurrentTexture: " + texture + "; " + offset);
                UnityEngine.Cursor.SetCursor((Texture2D)texture, offset.ToVector2(),
                                             mode == CursorRenderingMode.Auto ? CursorMode.Auto : CursorMode.ForceSoftware);
                break;

            case CursorRenderingMode.Stage:
                Screen.showCursor = false;
                if (null == _stage)
                {
                    InitStage();
                }
// ReSharper disable PossibleNullReferenceException
                _stage.Visible = true;
// ReSharper restore PossibleNullReferenceException
                _cursorImage.Texture = texture;
                _cursorImage.Move(SystemManager.Instance.MousePosition.Add(_offset));
                break;
            }
        }
Example #26
0
        /// <summary>
        /// Loads all GameObjects and UIElements in this Scene.
        /// </summary>
        public override void Load()
        {
            Debug = false;

            // Load content.
            MapData   mapData     = MapLoader.XmlMapReader(@"..\..\..\..\Content\Maps\Map_02.xml");
            Texture2D spriteSheet = ContentManager.Load <Texture2D>(@"..\..\..\..\Content\Sprites\Tiles\" + Path.GetFileNameWithoutExtension(mapData.TileSets[0].Source));

            // Load map.
            Point   tileSize   = new Point(mapData.TileWidth, mapData.TileHeight);
            Vector2 mapOffset  = new Vector2(-2020, -300);
            Vector2 maxMapSize = new Vector2(mapData.Width, mapData.Height);

            for (int i = 0; i < mapData.Layers.Length; i++)
            {
                int  soringOrder = i;
                bool solid       = (i == 2);
                foreach (GameObject tile in MapLoader.LoadLayer(mapData.Layers[i], spriteSheet, tileSize, SortingLayer.Map, soringOrder, solid, mapOffset))
                {
                    AddObject(tile);
                }
            }

            CameraMin = mapOffset;
            CameraMax = maxMapSize * tileSize.ToVector2() + mapOffset;

            objectHandler.WorldSize = new RectangleF((Vector2)CameraMin, maxMapSize * tileSize.ToVector2());

            AddObject(p);
            CameraFollow = p;

            for (int i = 0; i < 6; i++)
            {
                Enemy e = new Enemy(new Vector2(-700 + 100 * i, 250));
                AddObject(e);
            }
        }
Example #27
0
        public void Interact(Point interactTarget)
        {
            var validInteraction = FourWayPossibleMovement.FourWayAdjacentLocations(PlayerEntity.Instance.Position.ToPoint()).Contains(interactTarget);

            if (validInteraction)
            {
                PlayerEntity.Instance.FacingDirection = interactTarget.ToVector2() - PlayerEntity.Instance.Position;
                var interactWith = _expiringSpatialHash.ValueAt(interactTarget);
                if (interactWith != null)
                {
                    var story = interactWith.Interact();
                    story.Continue();
                    var entityDialogBox = DialogBox as EntityStoryBoxDialog;
                    entityDialogBox?.StartStory(story, interactWith);
                }
                else if (Flags.AcquireRod)
                {
                    if (WaterCollision(interactTarget))
                    {
                        var random       = new Random();
                        var fishComplete = random.Next(3) == 0;
                        var scriptName   = fishComplete ? "fish_success.ink" : "fish_fail.ink";
                        var fishScript   = StoryImporter.ReadStory(scriptName);
                        var story        = new GameFrameStory(fishScript);
                        if (fishComplete)
                        {
                            Flags.FishCount++;
                            story.ChoosePathString("dialog");
                            story.SetVariableState("fish_count", Flags.FishCount);
                        }
                        story.Continue();
                        DialogBox.StartStory(story);
                    }
                }
            }
        }
Example #28
0
        public Streak(Point start, int maxLength, int speed)
        {
            Start      = start;
            Top        = start.ToVector2();
            _maxLength = maxLength;
            _speed     = Vector2.UnitY * speed;
            _size      = new Point(_weight, maxLength);

            if (_speed.Y <= 4)
            {
                Color   = new Color(65, 125, 150);
                _weight = 1;
            }
            else if (_speed.Y <= 10)
            {
                Color   = new Color(88, 157, 205);
                _weight = 2;
            }
            else
            {
                Color   = new Color(161, 225, 255);
                _weight = 4;
            }
        }
        /// <summary>
        /// Finds the nearest point and its normal.
        /// </summary>
        /// <param name="viewport">
        /// The viewport.
        /// </param>
        /// <param name="position">
        /// The position.
        /// </param>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="normal">
        /// The normal.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="node"></param>
        /// <returns>
        /// The find nearest.
        /// </returns>
        public static bool FindNearest(this Viewport3DX viewport, Point position,
                                       out Point3D point, out Vector3D normal, out Element3D model, out SceneNode node)
        {
            var succ = viewport.FindNearest(position.ToVector2(), out var p, out var n, out var m);

            point  = p.ToPoint3D();
            normal = n.ToVector3D();
            if (m is Element3D ele)
            {
                model = ele;
                node  = ele.SceneNode;
            }
            else if (m is SceneNode nd)
            {
                node  = nd;
                model = null;
            }
            else
            {
                model = null;
                node  = null;
            }
            return(succ);
        }
Example #30
0
        public static Map GenerateHouse(string name, Point townPosition)
        {
            var map = new Map(name, 11, 13, true, true, new Vector2(5.5F, 11.5F));

            for (var x = 0; x < map.WidthInTiles; x++)
            {
                for (var y = 0; y < map.HeightInTiles; y++)
                {
                    var tile = Registry.TileFloor;
                    if ((x == 0 || y == 0 || x == map.WidthInTiles - 1 || y >= map.HeightInTiles - 2) && (x != 5 || y != 11))
                    {
                        tile = Registry.TileWallTrim;
                    }
                    else if (y >= 1 && y <= 3)
                    {
                        tile = Registry.TileWall;
                    }
                    map.SetTile(new Point(x, y), tile);
                }
            }

            map.AddObject(new Teleporter(map, new Vector2(5, 12.75F), "Town", townPosition.ToVector2() + new Vector2(2.5F, 1.15F), Direction.Down));
            return(map);
        }
Example #31
0
        public override void WorldDraw()
        {
            if (Visible)
            {
                if (EyedropperActive)
                {
                    Point   tileCoords   = Main.MouseWorld.ToTileCoordinates();
                    Vector2 worldCoords  = tileCoords.ToVector2() * 16;
                    Vector2 screenCoords = worldCoords - Main.screenPosition;

                    DrawBorderedRect(Main.spriteBatch, Color.LightBlue * 0.1f, Color.Blue * 0.3f, screenCoords, new Vector2(16, 16), 5);

                    if (!Main.LocalPlayer.mouseInterface && Main.mouseLeft)
                    {
                        EyedropperActive = false;

                        Tools.REPL.REPLTool.moddersToolkitUI.codeTextBox.Write($"Main.tile[{tileCoords.X},{tileCoords.Y}]");
                        // can't get this to work. Tools.REPL.REPLTool.moddersToolkitUI.codeTextBox.Focus();
                    }

                    Main.LocalPlayer.mouseInterface = true;
                }
            }
        }
Example #32
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (!IsVisible)
            {
                return;
            }

            if (!IsInHitTest && lastBarNum > 0)
            {
                // start point is 10 bars back and 5 ticks up from 2nd to last bar and price
                startPoint = new Point(ChartControl.GetXByBarIndex(ChartBars, (lastBarNum - 10)), chartScale.GetYByValue(lastPrice + 5 * TickSize));
                // end point is 2nd to last bar and 5 ticks down from price
                endPoint = new Point(ChartControl.GetXByBarIndex(ChartBars, (lastBarNum)), chartScale.GetYByValue(lastPrice - 5 * TickSize));

                SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;

                RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
                RenderTarget.DrawLine(startPoint.ToVector2(), endPoint.ToVector2(), brushDx, 15);

                RenderTarget.AntialiasMode = oldAntialiasMode;
            }

            base.OnRender(chartControl, chartScale);
        }
        public static void DrawFancyBar(SpriteBatch spriteBatch, float lifePercent, Texture2D barIconTexture, Rectangle barIconFrame)
        {
            Texture2D value          = Main.Assets.Request <Texture2D>("Images/UI/UI_BossBar", Main.content, (AssetRequestMode)1).Value;
            Point     p              = new Point(456, 22);
            Point     p2             = new Point(32, 24);
            int       verticalFrames = 6;
            Rectangle value2         = value.Frame(1, verticalFrames, 0, 3);
            Color     color          = Color.White * 0.2f;
            int       num            = (int)((float)p.X * lifePercent);

            num -= num % 2;
            Rectangle value3 = value.Frame(1, verticalFrames, 0, 2);

            value3.X     += p2.X;
            value3.Y     += p2.Y;
            value3.Width  = 2;
            value3.Height = p.Y;
            Rectangle value4 = value.Frame(1, verticalFrames, 0, 1);

            value4.X     += p2.X;
            value4.Y     += p2.Y;
            value4.Width  = 2;
            value4.Height = p.Y;
            Rectangle r      = Utils.CenteredRectangle(Main.ScreenSize.ToVector2() * new Vector2(0.5f, 1f) + new Vector2(0f, -50f), p.ToVector2());
            Vector2   vector = r.TopLeft() - p2.ToVector2();

            spriteBatch.Draw(value, vector, value2, color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            spriteBatch.Draw(value, r.TopLeft(), value3, Color.White, 0f, Vector2.Zero, new Vector2(num / value3.Width, 1f), SpriteEffects.None, 0f);
            spriteBatch.Draw(value, r.TopLeft() + new Vector2(num - 2, 0f), value4, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            Rectangle value5 = value.Frame(1, verticalFrames);

            spriteBatch.Draw(value, vector, value5, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            Vector2 value6 = new Vector2(4f, 20f) + new Vector2(26f, 28f) / 2f;

            spriteBatch.Draw(barIconTexture, vector + value6, barIconFrame, Color.White, 0f, barIconFrame.Size() / 2f, 1f, SpriteEffects.None, 0f);
        }
Example #34
0
    public ChargedBolt(Point Center, int Radius, int TailsCount, float Speed, Color RenderColor, Color LightColor)
    {
        count = TailsCount;
        speed = Speed;

        tails            = new DotTail[count];
        positions        = new Vector2[count];
        initialPositions = new Vector2[count];
        targets          = new Vector2[count];
        lerptimes        = new float[count];
        initialLerptimes = new float[count];

        center   = Center;
        position = Center.ToVector2();
        radius   = Radius;

        for (int i = 0; i < count; i++)
        {
            tails[i]            = new DotTail(Irbis.Irbis.RandomPoint(radius).ToPoint(), (int)(5 * Irbis.Irbis.screenScale), RenderColor, LightColor, 0.8f);
            initialPositions[i] = positions[i] = tails[i].Position.ToVector2();
            targets[i]          = Irbis.Irbis.RandomPoint(radius);
            initialLerptimes[i] = lerptimes[i] = Vector2.Distance(positions[i], targets[i]) / speed;
        }
    }
Example #35
0
 /// <summary>
 /// Un-projects the specified 2D screen point to a ray.
 /// </summary>
 /// <param name="viewport">The viewport.</param>
 /// <param name="point2d">The point.</param>
 /// <returns>The ray.</returns>
 public static Ray3D UnProjectToRay(this Viewport3DX viewport, Point point2d)
 {
     var r = viewport.UnProject(point2d.ToVector2());            
     return new Ray3D(r.Position.ToPoint3D(), r.Direction.ToVector3D());
 }
Example #36
0
        /// <summary>
        /// Return the third point of a triangle
        /// </summary>
        /// <param name="firstPoint">First point of the triangle</param>
        /// <param name="secondPoint">Second point of the triangle</param>
        /// <param name="distanceToFirstPoint">Distance to the first point</param>
        /// <param name="distanceToSecondPoint">Distance to the second point</param>
        /// <returns></returns>
        public static Tuple<Point, Point> GetThirdPointOfTriangle(Point firstPoint, Point secondPoint, double distanceToFirstPoint, double distanceToSecondPoint)
        {
            Vector2 pA = firstPoint.ToVector2();
            Vector2 pB = secondPoint.ToVector2();
            Vector2 vAB = pB - pA; // The vector AB;

            double r0 = distanceToFirstPoint; // The length of the first side AC
            double r1 = distanceToSecondPoint; // The length of the second side BC
            double d = vAB.Length(); // The length of the third side AB

            double d_square = d * d; // The square of d
            double r1_square = r1 * r1;
            double r0_square = r0 * r0;

            double a = (r0_square - (r1_square) + d_square) / (2 * d); // The length of AH, where CH is the perpendicular to AB
            double b = (d_square - r0 + (r1_square)) / (2 * d); // The length of BH
            double h = Math.Sqrt((r0_square) - (a * a)); // The length of CH

            Vector2 uAB = Vector2.Normalize(vAB); // The unit vector of AB;
            Vector2 vAH = pA + (uAB * (float)a); // The vector AH
            Vector2 uCH = uAB.Swap(); // The perpendicular unit vector of CH;

            Vector2 c1 = vAH + (uCH * (float)h); // The first solution of C
            Vector2 c2 = vAH - (uCH * (float)h); // The second solution of C

            return new Tuple<Point, Point>(c1.ToPoint(), c2.ToPoint());
        }
Example #37
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos)
 {
     return Play(entry, tilePos.ToVector2() * 16f, -1, null);
 }
Example #38
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, PlaySoundEvent onPlay)
 {
     return Play(entry, tilePos.ToVector2() * 16f, variant, onPlay);
 }
Example #39
0
 public bool Contains(Point point)
 {
     return BoundingRectangle.Contains(point.ToVector2());
 }
        private void HandlePointerPressed(Point position, bool isLeft, bool isRight)
        {

            var pointerPos = position.ToVector2();
            if (isLeft)
            {
                bool newSelection = false;
                Tank tempTank = null;
                //check if something get selected
                foreach (var tank in Tanks)
                {

                    if (tank.selected)
                    {
                        tempTank = tank;
                    }
                    if (!newSelection && Vector2.Distance(pointerPos, tank.CurrentPosition) < tank.size)
                    {
                        tank.selected = true;
                        isTankSelected = true;
                        newSelection = true;

                    }
                    else
                    {
                        tank.selected = false;
                    }

                }
                if (!newSelection && tempTank != null)
                {
                    tempTank.TargetPosition = pointerPos;
                    tempTank.selected = true;
                }
            }
            else if (isRight)
            {
                this.FiringTargetPos = pointerPos;
                this.FireCommand = true;
            }

        }
Example #41
0
 public void AddTrampolineObject(Point groundPoint, Point assetSize, Texture2D texture, bool isVisible, float jumpMagnifier)
 {
     TrampolineComponent trampComp = new TrampolineComponent(texture.Width, texture.Height, jumpMagnifier);
     GameObject tempObject = new GameObject(groundPoint.ToVector2(), texture, isVisible, trampComp);
     tempObject.Size = assetSize;
     LevelObjects.Add(tempObject);
 }
Example #42
0
 public ContainmentType Contains(Point point)
 {
     return Contains(point.ToVector2());
 }
Example #43
0
 public void AddObject(Point groundPoint, Texture2D texture, bool isVisible)
 {
     GameObject tempGameObject = new GameObject(groundPoint.ToVector2(), texture, isVisible, PhysicsType.StaticObject);
     LevelObjects.Add(tempGameObject);
 }
Example #44
0
 public void AddTeleportObject(Point groundPoint, Point assetSize, Texture2D texture, bool isVisible, Point destination)
 {
     TeleportComponent teleComp = new TeleportComponent(texture.Width, texture.Height, destination);
     GameObject tempObject = new GameObject(groundPoint.ToVector2(), texture, isVisible, teleComp);
     tempObject.Size = assetSize;
     LevelObjects.Add(tempObject);
 }
Example #45
0
 public void SetPosition(Point pos)
 {
     this.Position = pos.ToVector2();
     //this.SetPosition(pos.X, pos.Y);
 }
		public static Dust QuickDust(Point tileCoords, Color color)
		{
			Dust dust = Main.dust[Dust.NewDust(tileCoords.ToVector2() * 16f, 0, 0, 267, 0f, 0f, 0, default(Color), 1f)];
			dust.position = tileCoords.ToVector2() * 16f + new Vector2(8f);
			dust.velocity = Vector2.Zero;
			dust.fadeIn = 1f;
			dust.noLight = true;
			dust.noGravity = true;
			dust.color = color;
			return dust;
		}
Example #47
0
		/// <summary>
		/// converts a point from screen coordinates to world
		/// </summary>
		/// <returns>The to world point.</returns>
		/// <param name="screenPosition">Screen position.</param>
		public Vector2 screenToWorldPoint( Point screenPosition )
		{
			return screenToWorldPoint( screenPosition.ToVector2() );
		}
Example #48
0
 /// <summary>
 /// Convert screen coordinates in grid ones
 /// </summary>
 /// <param name="absolutePoint"></param>
 /// <returns></returns>
 public static Vector2 WorldToGrid(Point absolutePoint, Vector2 tileSize)
 {
     return WorldToGrid(absolutePoint.ToVector2(), tileSize);
 }
Example #49
0
		/// <summary>
		/// Revisa si esta forma contiene un punto dado.
		/// </summary>
		/// <param name="p">Punto</param>
		public bool Contains (Point p)
		{
			var vect = Center - p.ToVector2 ();
			return vect.LengthSquared () < Radius * Radius;
		}
Example #50
0
        /// <summary>
        /// Remembers the location of the level's exit.
        /// </summary>
        private Tile LoadExitTile(int x, int y)
        {
            if (exit != InvalidPosition)
                throw new NotSupportedException("A level may only have one exit.");

            exit = GetBounds(x, y).Center;
            Game.Penumbra.Lights.Add(new PointLight
            {
                Position = exit.ToVector2(),
                Scale = new Vector2(100),
                Color = Color.Red,
                CastsShadows = false
            });

            return LoadTile("Exit", TileCollision.Passable);
        }
Example #51
0
        public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, float volMod = Single.NaN, float pitch = Single.NaN, float panMod = Single.NaN)
        {
            return Play(entry, tilePos.ToVector2() * 16f, variant, (SfxEntry e, Vector2 p, ref int v, ref float vol, ref float pi, ref float pan) =>
            {
                if (!Single.IsNaN(vol))
                    vol *= volMod;
                if (!Single.IsNaN(pi))
                    pi = pitch;
                if (!Single.IsNaN(pan))
                    pan *= panMod;

                return true;
            });
        }
Example #52
0
 public bool Contains(Point point)
 {
     return Shape.Contains(point.ToVector2());
 }
Example #53
0
 public static SoundEffectInstance Play(int type, Point tilePos, int style = -1)
 {
     return Play(type, tilePos.ToVector2() * 16f, style);
 }
Example #54
0
 public static Point getTileFromPos(Point chunk, Vector2 pos)
 {
     pos = (pos * TILEMULT) - chunk.ToVector2() * CHUNK_SIZE;
     return new Point(MathHelper.Clamp((int)pos.X, 0, CHUNK_SIZE - 1), MathHelper.Clamp((int)pos.Y, 0, CHUNK_SIZE - 1));
 }
 public void Teleport(Point position)
 {
     this.Location = position.ToVector2();
 }
Example #56
0
        ///// <summary>
        ///// Un-projects a 2D screen point.
        ///// </summary>
        ///// <param name="viewport">The viewport.</param>
        ///// <param name="pointIn">The input point.</param>
        ///// <returns>The ray.</returns>
        //public static Ray UnProject(this Viewport3DX viewport, Vector2 point2d)
        //{
        //    Vector3 p0,p1;
        //    return UnProject(viewport, point2d);, out p0, out p1);
        //}

        /// <summary>
        /// Un-projects a 2D screen point.
        /// </summary>
        /// <param name="viewport">The viewport.</param>
        /// <param name="pointIn">The input point.</param>
        /// <returns>The ray.</returns>
        public static Ray3D UnProject(this Viewport3DX viewport, Point point2d)
        {
            //Vector3 p0, p1;
            var r = UnProject(viewport, point2d.ToVector2());//, out p0, out p1);
            return new Ray3D(r.Position.ToPoint3D(), r.Direction.ToVector3D());
        }
Example #57
0
		/// <summary>
		/// Convierte de ventana a universo
		/// </summary>
		public Point VentanaAUniverso (Point p)
		{
			return VentanaAUniverso (p.ToVector2 ()).ToPoint ();
		}
Example #58
0
		/// <summary>
		/// Convierte de universo a ventana
		/// </summary>
		public Point UniversoAVentana (Point p)
		{
			return UniversoAVentana (p.ToVector2 ()).ToPoint ();
		}
Example #59
0
 public static Matrix AffineTransformation2D(double scaling, Point rotationCenter, double rotation, Point translation)
 {
   return
     new Matrix(Microsoft.DirectX.Matrix.AffineTransformation2D((float)scaling, rotationCenter.ToVector2(),
                                                                (float)rotation, translation.ToVector2()));
 }
Example #60
0
 public void drawTrees(Point coords)
 {
     List<Tree> chunk = getChunk(coords).trees;
     /*if (chunk == null)
     {
         return;
     }*/
     foreach (var tree in chunk)
     {
         Main.spriteBatch.Draw(treeTex, tree.pos + (coords.ToVector2() * CHUNK_SIZE * TILESIZE) - Tree.treeOrigin, Tree.treeRect.XShift(tree.id * Tree.treeRect.Width), Color.White);
     }
 }