Exemplo n.º 1
0
Arquivo: Level.cs Projeto: mbos14/GTFO
        public void DrawPreDefinedLayer()
        {
            int startNr = TILEDINFO + BETWEENLAYERS * 2 + TILESY * 2;
            int endNr = startNr + TILESY;

            int[,] levelData = new int[TILESY, TILESX];
            //------------------------------------------READ FILE----------------------------------------------
            StreamReader reader1 = new StreamReader(_fileName);
            string fileData = reader1.ReadToEnd();
            reader1.Close();
            //--------------------------------------SPLIT AND CONVERT------------------------------------------
            string[] lines = fileData.Split('\n');
            for (int j = startNr; j < endNr; j++)
            {
                string[] columns = lines[j].Split(',');

                for (int i = 0; i < TILESX; i++)
                {
                    string column = columns[i];
                    levelData[j - startNr, i] = int.Parse(column);
                }
            }

            //-------------------------------------READ THE NUMBERS, PLACE IN GAME-----------------------------
            for (int i = 0; i < TILESY; i++)
            {
                for (int j = 0; j < TILESX; j++)
                {
                    int tile = levelData[i, j];

                    switch (tile)
                    {
                        case 1: //Reload
                            {
                                PickUpReload thisobject = new PickUpReload(this);
                                _midgroundLayer.AddChild(thisobject);
                                thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                reloadList.Add(thisobject);
                                break;
                            }
                        case 2: //Life
                            {
                                if (!_levelDrawed)
                                {
                                    PickUpLife thisobject = new PickUpLife(this);
                                    _midgroundLayer.AddChild(thisobject);
                                    thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                }
                                break;
                            }
                        case 3: //Coin
                            {
                                if (!_levelDrawed)
                                {
                                    PickUpCoin thisobject = new PickUpCoin(this);
                                    _midgroundLayer.AddChild(thisobject);
                                    thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                }
                                break;
                            }
                        case 4: //EnemySpider
                            {
                                if (!_levelDrawed)
                                {
                                    EnemySpider thisenemy = new EnemySpider(this);
                                    _midgroundLayer.AddChild(thisenemy);
                                    thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                    enemyList.Add(thisenemy);
                                }
                                break;
                            }
                        case 5: //Enemy bug Horizontal
                            {
                                if (!_levelDrawed)
                                {
                                    EnemyBugHorizontal thisenemy = new EnemyBugHorizontal(this, i * TILESIZE);
                                    _midgroundLayer.AddChild(thisenemy);
                                    thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                    enemyList.Add(thisenemy);
                                }
                                break;
                            }
                        case 6: //Enemy bug Vertical
                            {
                                if (!_levelDrawed)
                                {
                                    EnemyBugVertical thisenemy = new EnemyBugVertical(this, j * TILESIZE);
                                    _midgroundLayer.AddChild(thisenemy);
                                    thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                    enemyList.Add(thisenemy);
                                }
                                break;
                            }
                        case 7: //EnemyFloater
                            {
                                if (!_levelDrawed)
                                {
                                    EnemyFloater thisenemy = new EnemyFloater(this);
                                    _midgroundLayer.AddChild(thisenemy);
                                    thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                    enemyList.Add(thisenemy);
                                }
                                break;
                            }
                        case 8: //Weapon
                            {
                                if (!_levelDrawed)
                                {
                                    PickUpWeapon thisobject = new PickUpWeapon(this);
                                    _midgroundLayer.AddChild(thisobject);
                                    thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                }
                                break;
                            }

                        case 9: //Invisible block of doom
                            {
                                if (!_levelDrawed)
                                {
                                    InvisBlock thisobject = new InvisBlock(this);
                                    _midgroundLayer.AddChild(thisobject);
                                    thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                    thisobject.SetFrame(1270);
                                }
                                break;
                            }
                        case 10: //End of the levelpart
                            {
                                if (!_levelDrawed)
                                {
                                    Checkpoints thispoint = new Checkpoints(false, this);
                                    _midgroundLayer.AddChild(thispoint);
                                    thispoint.SetXY(j * TILESIZE, i * TILESIZE);
                                }
                                break;
                            }
                        case 11: //Checkpoint
                            {
                                if (!_levelDrawed)
                                {
                                    Checkpoints thispoint = new Checkpoints(true, this);
                                    _midgroundLayer.AddChild(thispoint);
                                    thispoint.SetXY(j * TILESIZE, i * TILESIZE);
                                }
                                break;
                            }
                    }

                }
            }
            _levelDrawed = true;
        }
Exemplo n.º 2
0
Arquivo: Level.cs Projeto: mbos14/GTFO
        private void drawPreDefinedLayer()
        {
            int[,] levelData = new int[TILESY, TILESX];
            //------------------------------------------READ FILE----------------------------------------------
            StreamReader reader1 = new StreamReader(_fileName);
            string fileData = reader1.ReadToEnd();
            reader1.Close();
            //--------------------------------------SPLIT AND CONVERT------------------------------------------
            string[] lines = fileData.Split('\n');
            for (int j = 74; j < 100; j++)
            {
                string[] columns = lines[j].Split(',');

                for (int i = 0; i < TILESX; i++)
                {
                    string column = columns[i];
                    levelData[j - 74, i] = int.Parse(column);
                }
            }

            //-------------------------------------READ THE NUMBERS, PLACE IN GAME-----------------------------
            for (int i = 0; i < TILESY; i++)
            {
                for (int j = 0; j < TILESX; j++)
                {
                    switch (levelData[i, j])
                    {
                        case 270: //Coin
                            {
                                PickUpCoin thisobject = new PickUpCoin(this);
                                _midgroundLayer.AddChild(thisobject);
                                thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                //pickUpList.Add(thisobject);
                                break;
                            }
                        case 269: //Reload
                            {
                                PickUpReload thisobject = new PickUpReload(this);
                                _midgroundLayer.AddChild(thisobject);
                                thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                //pickUpList.Add(thisobject);
                                break;
                            }
                        case 267: //Weapon
                            {
                                PickUpWeapon thisobject = new PickUpWeapon(this);
                                _midgroundLayer.AddChild(thisobject);
                                thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                //pickUpList.Add(thisobject);
                                break;
                            }
                        case 10: //Life
                            {
                                PickUpLife thisobject = new PickUpLife(this);
                                _midgroundLayer.AddChild(thisobject);
                                thisobject.SetXY(j * TILESIZE, i * TILESIZE);
                                //pickUpList.Add(thisobject);
                                break;
                            }
                        case 0: //Enemy bug Horizontal
                            {
                                EnemyBugHorizontal thisenemy = new EnemyBugHorizontal(this);
                                _midgroundLayer.AddChild(thisenemy);
                                thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                enemyList.Add(thisenemy);
                                break;
                            }
                        case 1: //Enemy bug Vertical
                            {
                                EnemyBugVertical thisenemy = new EnemyBugVertical(this);
                                _midgroundLayer.AddChild(thisenemy);
                                thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                enemyList.Add(thisenemy);
                                break;
                            }
                        case 2: //EnemyFloater
                            {
                                EnemyFloater thisenemy = new EnemyFloater(this);
                                _midgroundLayer.AddChild(thisenemy);
                                thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                enemyList.Add(thisenemy);
                                break;
                            }
                        case 3: //EnemySpider
                            {
                                EnemySpider thisenemy = new EnemySpider(this);
                                _midgroundLayer.AddChild(thisenemy);
                                thisenemy.SetXY(j * TILESIZE, i * TILESIZE);
                                enemyList.Add(thisenemy);
                                break;
                            }
                    }

                }
            }
        }