Ejemplo n.º 1
0
        private void setObject(Point target)
        {
            Rectangle rect = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);

            if (rect.Intersects(panel))
            {
                if (InputManager.IsMouseLeftClick())
                {
                    if (rect.Intersects(upArrow))
                    {
                        if (blockNum-- == 1)
                        {
                            blockNum = 6;
                        }
                    }
                    else
                    if (rect.Intersects(downArrow))
                    {
                        if (blockNum++ == 6)
                        {
                            blockNum = 1;
                        }
                    }
                    else
                    if (rect.Intersects(save))
                    {
                        saveTheCurrentLevel();
                    }
                    else
                    if (rect.Intersects(load))
                    {
                        loadTheCurrentLevel();
                    }
                }
            }
            else
            {
                int shift = target.X / 50 - level[0].Count;
                while (shift-- > -1)
                {
                    foreach (List <char> list in level)
                    {
                        list.Add('0');
                    }
                }

                if (level[target.Y / 50][target.X / 50] == '0')
                {
                    Rectangle block;
                    switch (blockNum)
                    {
                    case 1:
                        block = new Rectangle(target.X, target.Y, 50, 50);
                        Block brick = new Block(block, blockTexture, this);
                        blocks.Add(brick);
                        level[target.Y / 50][target.X / 50] = 'X';
                        break;

                    case 2:
                        block = new Rectangle(target.X, target.Y, 50, 50);
                        brick = new Block(block, blockTexture2, this);
                        blocks.Add(brick);
                        level[target.Y / 50][target.X / 50] = 'Y';
                        break;

                    case 3:
                        block = new Rectangle(target.X + 10, target.Y + 10, 30, 30);
                        Gem gem = new Gem(block, gemTexture, this);
                        gems.Add(gem);
                        level[target.Y / 50][target.X / 50] = 'G';
                        break;

                    case 4:
                        if (enter == null)
                        {
                            block = new Rectangle(target.X - 50, target.Y, 150, 150);
                            enter = new Enter(block, this);
                            enter.LoadContent(Game.Content);
                            level[target.Y / 50][target.X / 50] = 'P';
                        }
                        break;

                    case 5:
                        if (quit == null)
                        {
                            block = new Rectangle(target.X - 50, target.Y, 150, 150);
                            quit  = new Quit(block, this);
                            quit.LoadContent(Game.Content);
                            level[target.Y / 50][target.X / 50] = 'Q';
                        }
                        break;

                    case 6:
                        block = new Rectangle(target.X - 20, target.Y - 41, 90, 90);
                        AnimatedSprite enemy = new Enemy_1(enemies.Count,
                                                           block,
                                                           enemyIdleTexture,
                                                           enemyRunTexture,
                                                           enemyRunTexture, 2, 9, this);
                        enemies.Add(enemy);
                        level[target.Y / 50][target.X / 50] = '★';
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void loadTheCurrentLevel()
        {
            System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog();
            open.Filter           = "Level Files (*.lvl)|*.lvl";
            open.InitialDirectory = Environment.CurrentDirectory + "\\Content\\Levels";
            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] structure = File.ReadAllLines(open.FileName);
                enemies.Clear();
                blocks.Clear();
                gems.Clear();
                Hero.ScrollX = 0;
                for (int i = 0; i < structure.Length; i++)
                {
                    for (int j = 0; j < structure[i].Length; j++)
                    {
                        if (j > level[i].Count - 1)
                        {
                            level[i].Add(structure[i][j]);
                        }
                        else
                        {
                            level[i][j] = structure[i][j];
                        }
                        Rectangle block;
                        switch (level[i][j])
                        {
                        case 'X':
                        {
                            block = new Rectangle(j * 50, i * 50, 50, 50);
                            Block brick = new Block(block, blockTexture, this);
                            blocks.Add(brick);
                        }
                        break;

                        case 'Y':
                        {
                            block = new Rectangle(j * 50, i * 50, 50, 50);
                            Block brick = new Block(block, blockTexture2, this);
                            blocks.Add(brick);
                        }
                        break;

                        case 'G':
                        {
                            block = new Rectangle(j * 50 + 10, i * 50 + 10, 30, 30);
                            Gem gem = new Gem(block, gemTexture, this);
                            gems.Add(gem);
                        }
                        break;

                        case 'P':
                        {
                            if (enter == null)
                            {
                                block = new Rectangle(j * 50 - 50, i * 50, 150, 150);
                                enter = new Enter(block, this);
                                enter.LoadContent(Game.Content);
                            }
                        }
                        break;

                        case 'Q':
                        {
                            if (quit == null)
                            {
                                block = new Rectangle(j * 50 - 50, i * 50, 150, 150);
                                quit  = new Quit(block, this);
                                quit.LoadContent(Game.Content);
                            }
                        }
                        break;

                        case '★':
                        {
                            block = new Rectangle(j * 50 - 20, i * 50 - 41, 90, 90);
                            AnimatedSprite enemy = new Enemy_1(enemies.Count,
                                                               block,
                                                               enemyIdleTexture,
                                                               enemyRunTexture,
                                                               enemyRunTexture, 2, 9, this);
                            enemies.Add(enemy);
                        }
                        break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void CreateLevel(byte state)
        {
            LevelGenerator generator = new LevelGenerator(this);

            enemies.Clear();
            blocks.Clear();
            gems.Clear();
            background.xBack = 0;

            switch (state)
            {
            case 1:
                currentLevel++;
                level = generator.Generate();
                break;

            default:
                Score = 0;
                break;

            case 2:
                level = generator.Generate();
                break;
            }

            levelMap    = new byte[level[0].Length, level.Length];
            levelLength = 50 * level[0].Length;

            int x = 0;
            int y = 0;

            int i = 0;
            int j = 0;

            foreach (string str in level)
            {
                foreach (char c in str)
                {
                    if (c != '0')
                    {
                        switch (c)
                        {
                        case 'G':
                        {
                            Rectangle gemRect = new Rectangle(x + 10, y + 10, 30, 30);
                            Gem       gem     = new Gem(gemRect, gemTexture, this);
                            gems.Add(gem);
                        }
                        break;

                        case 'X':
                        {
                            Rectangle rect  = new Rectangle(x, y, 50, 50);
                            Block     block = new Block(rect, blockTexture, this);
                            blocks.Add(block);
                            levelMap[i, j] = 1;
                        }
                        break;

                        case 'Y':
                        {
                            Rectangle rect  = new Rectangle(x, y, 50, 50);
                            Block     block = new Block(rect, blockTexture2, this);
                            blocks.Add(block);
                            levelMap[i, j] = 1;
                        }
                        break;

                        default:
                        {
                            Rectangle      enemyRect = new Rectangle(x - 20, y - 41, 90, 90);
                            AnimatedSprite enemy     = null;
                            switch (c)
                            {
                            case '★':
                                enemy = new Enemy_1(enemies.Count,
                                                    enemyRect,
                                                    enemyIdleTexture,
                                                    enemyRunTexture,
                                                    enemyRunTexture, 2, 9, this);
                                break;
                            }
                            enemies.Add(enemy);
                            enemy.Run(true);
                        }
                        break;

                        case 'P':
                        {
                            hero = new Hero(new Rectangle(x - 20, y - 41, 90, 90), 3, 8.2f, 100, this);
                            Rectangle enterRect = new Rectangle(x - 50, y, 150, 150);
                            enter = new Enter(enterRect, this);
                            enter.LoadContent(Game.Content);
                            hero.LoadContent(Game.Content);
                        }
                        break;

                        case 'Q':
                        {
                            Rectangle quitRect = new Rectangle(x - 50, y, 150, 150);
                            quit = new Quit(quitRect, this);
                            quit.LoadContent(Game.Content);
                        }
                        break;
                        }
                    }
                    x += 50;
                    i++;
                }
                x = 0;
                i = 0;
                j++;
                y += 50;
            }
            //Game.Components.Add(new Preview(Game, this));
            levelState = LevelState.Active;
        }