Blink.Classes.Map.blockInfo C# (CSharp) Метод

blockInfo() публичный Метод

public blockInfo ( Vector2 pos ) : int
pos Vector2
Результат int
        public int blockInfo(Vector2 pos)
        {
            float xTile = (float)(Math.Floor(pos.X / tileSize) % mapSize.X);
            xTile = loopCorrection(xTile, mapSize.X);
            float yTile = (float)(Math.Floor(pos.Y / tileSize) % mapSize.Y);
            yTile = loopCorrection(yTile, mapSize.Y);
            return (collisionMap[(int)xTile, (int) yTile]);
        }

Usage Example

Пример #1
0
        private void mapCollision()
        {
            Rectangle correctedBox = new Rectangle(spear.Location, spear.Size);

            correctedBox.X -= 27;

            Vector2[] verts = VectorMath.rectVerts(correctedBox, orientation);

            HashSet<int> xVals = new HashSet<int>();
            HashSet<int> yVals = new HashSet<int>();
            //gather values the spear might be passing through
            foreach(Vector2 vertex in verts)
        {
                xVals.Add((int)Math.Floor(vertex.X));
                yVals.Add((int)Math.Floor(vertex.Y));

            }

            //Using the dot product, find collidable rectangles and test.
            bool colliding = false;
            foreach(int x in xVals)
            {
                foreach(int y in yVals)
                {
                    int squareData = m.blockInfo(new Vector2(x, y));
                    if(thrownBy == null && squareData >= 10)
                    {
                        Rectangle r = new Rectangle(x, y, 32, 32);
                        if (VectorMath.rectCollision(correctedBox, orientation, r, 0))
                        {
                velocity.X = 0;
                velocity.Y = 0;
                atRest = true;
                throwing = false;
                Hit_Wall_Sound.Play();
                            colliding = true;
                            break;
                if(bomb)
                {
                    bombExplosion();
                    bomb = false;
                }
        }
                    }//This is messy, I know.
                    else if((squareData >= 10 && !thrownBy.blinked) || (squareData >= 10 && squareData < 20 && thrownBy.blinked))
                    {
                        Rectangle r = new Rectangle(x, y, 32, 32);
                        if (VectorMath.rectCollision(correctedBox, orientation, r, 0))
                        {
                            velocity.X = 0;
                            velocity.Y = 0;
                            atRest = true;
                            throwing = false;
                            Hit_Wall_Sound.Play();
                            colliding = true;
                            break;
        }
All Usage Examples Of Blink.Classes.Map::blockInfo