Пример #1
0
        public static bool isPlayerCollidingBottomRightPlus() // TODO
        {
            Vector2_Double gravityCollisionBottomRight = new Vector2_Double((sprite.position_wp.X + sprite.size.X) / World.BLOCK_SIZE, (sprite.position_wp.Y + sprite.size.Y + 5) / World.BLOCK_SIZE);

            return(World.blocks[(int)gravityCollisionBottomRight.X + (int)gravityCollisionBottomRight.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #2
0
        public static bool isPlayerCollidingTopRight()
        {
            Vector2_Double collisionTopRight = new Vector2_Double((sprite.position_wp.X + sprite.size.X) / World.BLOCK_SIZE, (sprite.position_wp.Y - 1) / World.BLOCK_SIZE);

            return(World.blocks[(int)collisionTopRight.X + (int)collisionTopRight.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #3
0
        public static bool isPlayerCollidingBottomLeftSide()
        {
            Vector2_Double sideCollisionBottomLeft = new Vector2_Double((sprite.position_wp.X - 1) / World.BLOCK_SIZE, (sprite.position_wp.Y + sprite.size.Y - (sprite.size.Y / 4)) / World.BLOCK_SIZE);

            return(World.blocks[(int)sideCollisionBottomLeft.X + (int)sideCollisionBottomLeft.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #4
0
        public static bool isPlayerCollidingMiddleRightSide()
        {
            Vector2_Double sideCollisionMiddleRight = new Vector2_Double((sprite.position_wp.X + sprite.size.X + 1) / World.BLOCK_SIZE, (sprite.position_wp.Y + (sprite.size.Y / 2)) / World.BLOCK_SIZE);

            return(World.blocks[(int)sideCollisionMiddleRight.X + (int)sideCollisionMiddleRight.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #5
0
 public static Vector2_Double worldPixelsToScreenPixelsPosition(Vector2_Double position)
 {
     return(new Vector2_Double(position.X - (World.offset_b.X * World.BLOCK_SIZE), position.Y - (World.offset_b.Y * World.BLOCK_SIZE)));
 }
Пример #6
0
 // Note: Only works for sprites of same size as BLOCK_SIZE
 public static Vector2_Double worldBlocksToScreenPixelsPosition(Vector2_Double position)
 {
     return(new Vector2_Double((position.X * BLOCK_SIZE) - (offset_b.X * World.BLOCK_SIZE), (position.Y * BLOCK_SIZE) - (offset_b.Y * World.BLOCK_SIZE)));
 }
Пример #7
0
        public static void Init(string file)
        {
            fileName = file;
            int worldHeight = 50;// ((Game1.screenRectangle.Height / 2) / BLOCK_SIZE) + 2;

            WORLD_SIZE = new Vector2(200, worldHeight);
            offset_b   = new Vector2_Double(0, 28);
            blocks     = new Block[(int)WORLD_SIZE.X * (int)WORLD_SIZE.Y];
            Console.WriteLine(worldHeight);


            Game1.gameState = Game1.GameStates.MAIN_MENU;
            if (Game1.gameState == Game1.GameStates.MAIN_MENU)
            {
                //BLOCK_SIZE = 15;
            }


            char[]   map   = new char[(int)(World.WORLD_SIZE.Y * World.WORLD_SIZE.X)];
            string[] lines = System.IO.File.ReadAllLines(@fileName);
            Console.WriteLine(lines.Length);
            Console.WriteLine(lines);
            for (int y = 0; y < World.WORLD_SIZE.Y; y++)
            {
                if (y >= lines.Length)
                {
                    Console.WriteLine("Error!"); break;
                }
                char[] mapLine = lines[y].ToString().ToCharArray();
                Console.WriteLine(mapLine.Length);
                for (int x = 0; x < 200; x++) // Width
                {
                    if (x >= mapLine.Length)
                    {
                        Console.WriteLine("Error!"); break;
                    }
                    map[x + y * 200] = mapLine[x];
                }
            }
            Console.WriteLine();
            for (int y = 0; y < World.WORLD_SIZE.Y; y++)
            {
                for (int x = 0; x < World.WORLD_SIZE.X; x++)
                {
                    int index = (int)(x + y * World.WORLD_SIZE.X);
                    if (map[index] == 's')
                    {
                        blocks[index].type  = BlockType.STONE;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == '1')
                    {
                        blocks[index].type  = BlockType.ROSE;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == '2')
                    {
                        blocks[index].type  = BlockType.SUNFLOWER;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == '3')
                    {
                        blocks[index].type  = BlockType.WILDGRASS;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'g')
                    {
                        blocks[index].type  = BlockType.GRASS;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'd')
                    {
                        blocks[index].type  = BlockType.DIRT;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'o')
                    {
                        blocks[index].type  = BlockType.SHALLOW_OCEAN;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'O')
                    {
                        blocks[index].type  = BlockType.DEEP_OCEAN;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'p')
                    {
                        blocks[index].type  = BlockType.PLATFORM;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'c')
                    {
                        blocks[index].type  = BlockType.CAVE;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'C')
                    {
                        blocks[index].type  = BlockType.DARK_CAVE;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'E')
                    {
                        blocks[index].type  = BlockType.CAVE_ENTRANCE;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'i')
                    {
                        blocks[index].type  = BlockType.TOWER;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'w')
                    {
                        blocks[index].type  = BlockType.SNOW;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'S')
                    {
                        blocks[index].type  = BlockType.COBBLE;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'L')
                    {
                        blocks[index].type  = BlockType.COBBLE_LEFT;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == 'R')
                    {
                        blocks[index].type  = BlockType.COBBLE_RIGHT;
                        blocks[index].solid = true;
                    }
                    else if (map[index] == '4')
                    {
                        blocks[index].type  = BlockType.SHORT_GRASS;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == 'a')
                    {
                        blocks[index].type  = BlockType.AIR;
                        blocks[index].solid = false;
                    }
                    else if (map[index] == '0')
                    {
                        blocks[index].type  = BlockType.WALL;
                        blocks[index].solid = true;
                    }
                }
            }
        }
Пример #8
0
        public static bool isCollidingTopLeft(SpriteStruct sprite)
        {
            Vector2_Double collisionTopLeft = new Vector2_Double((sprite.position_wp.X) / World.BLOCK_SIZE, (sprite.position_wp.Y - 1) / World.BLOCK_SIZE);

            return(World.blocks[(int)collisionTopLeft.X + (int)collisionTopLeft.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #9
0
        public static bool isCollidingBottomLeft(SpriteStruct sprite) // TODO
        {
            Vector2_Double gravityCollisionBottomLeft = new Vector2_Double((sprite.position_wp.X) / World.BLOCK_SIZE, (sprite.position_wp.Y + sprite.size.Y + 2) / World.BLOCK_SIZE);

            return(World.blocks[(int)gravityCollisionBottomLeft.X + (int)gravityCollisionBottomLeft.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #10
0
        public static bool isCollidingMiddleLeftSide(SpriteStruct sprite)
        {
            Vector2_Double sideCollisionMiddleLeft = new Vector2_Double((sprite.position_wp.X - 1) / World.BLOCK_SIZE, (sprite.position_wp.Y + (sprite.size.Y / 2)) / World.BLOCK_SIZE);

            return(World.blocks[(int)sideCollisionMiddleLeft.X + (int)sideCollisionMiddleLeft.Y * (int)World.WORLD_SIZE.X].solid);
        }
Пример #11
0
        public static bool isCollidingBottomRightSide(SpriteStruct sprite)
        {
            Vector2_Double sideCollisionBottomRight = new Vector2_Double((sprite.position_wp.X + sprite.size.X + 1) / World.BLOCK_SIZE, (sprite.position_wp.Y + sprite.size.Y - (sprite.size.Y / 4)) / World.BLOCK_SIZE);

            return(World.blocks[(int)sideCollisionBottomRight.X + (int)sideCollisionBottomRight.Y * (int)World.WORLD_SIZE.X].solid);
        }