예제 #1
0
파일: Me.cs 프로젝트: EvgeniyProtas/studies
        bool IsCollideWithBonus()                   //проверка на бонусы
        {
            bonusElements findspr = null;

            qualityofbonus = 0;
            foreach (bonusElements spr in bonuses)
            {
                if (this.sprPosition.X + this.sprRectangle.Width > spr.Position.X &&
                    this.sprPosition.X < spr.Position.X + spr.Rectangle.Width &&
                    this.sprPosition.Y + this.sprRectangle.Height > spr.Position.Y &&
                    this.sprPosition.Y < spr.Position.Y + this.sprRectangle.Height)
                {
                    bonuses.Remove(spr);
                    findspr = spr;
                    if (spr.Rectangle.Width < 60)
                    {
                        qualityofbonus = 2;
                    }
                    else if (spr.Rectangle.Width == 63)
                    {
                        qualityofbonus = 3;
                    }
                    else
                    {
                        qualityofbonus = 1;
                    }
                    return(true);
                }
            }
            if (findspr != null)
            {
                findspr.Dispose();
            }
            return(false);
        }
예제 #2
0
 public void Scroll(float dy)
 {
     for (int i = 0; i < boxs.Count; i++)
     {
         Box box = boxs[i];
         box.Position.Y += dy;
         if (box.Position.Y > game.Window.ClientBounds.Height)
         {
             box.Dispose();
             boxs.Remove(box);
         }
     }
     for (int i = 0; i < enemies.Count; i++)
     {
         EnemyCollection en = enemies[i];
         en.Position.Y += dy;
         if (en.Position.Y > game.Window.ClientBounds.Height)
         {
             en.Dispose();
             enemies.Remove(en);
         }
     }
     for (int i = 0; i < bonuses.Count; i++)
     {
         bonusElements bon = bonuses[i];
         bon.Position.Y += dy;
         if (bon.Position.Y > game.Window.ClientBounds.Height)
         {
             bon.Dispose();
             bonuses.Remove(bon);
         }
     }
 }
예제 #3
0
         void createMaps()
        {
            boxs = new List<Box>();
            bonuses = new List<bonusElements>();
            enemies = new List<EnemyCollection>();
            string[] lines = File.ReadAllLines(@"D:/Layer.txt");
            int en=0, bon = 0;

            levelLength = 100 * lines.Count();
            int x = 0;
            int y = 0;
            int i=lines.Count()-1, j = 0;

            for(;i >= 0;i--)
            {
                for(;j < lines[i].Length;j++)
                {
                    char c = lines[i][j];
                    switch(c)
                    {
                        case '1':
                        {
                            Rectangle boxrect = new Rectangle(0, 0, 100, 20);
                            Vector2 boxposition = GetScreenRect(new Vector2(x, y));
                            Box box = new Box(ref txtWall, boxposition, boxrect, game);
                            boxs.Add(box);
                            break;
                        }
                        case '2':
                        {

                            bon = (int)new Random().Next(0, 2);
                            switch(en)
                            {
                                case 0:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 100, 65);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 1:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 173, 95);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 2:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 120, 100);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 3:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 50, 100);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 4:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 80, 105);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 5:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 60, 100);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en = 0;
                                    break;
                                }

                            }


                            break;
                        }
                        case '3':
                        {
                            bon = (int) new Random().Next(0,2);
                            switch(bon)
                            {
                                case 2:
                                {
                                    Rectangle bonrect = new Rectangle(0, 0, 63, 110);                                //max
                                    Vector2 bonposition = GetScreenRect(new Vector2(x, y));
                                    txtBonus = boncollection[0];
                                    bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                                    bonuses.Add(bonus);
                                    bon=0;
                                    break;
                                }
                                case 1:
                                {
                                    Rectangle bonrect = new Rectangle(0, 0, 21, 80);                                     //midle
                                    Vector2 bonposition = GetScreenRect(new Vector2(x, y));
                                    txtBonus = boncollection[bon];
                                    bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                                    bonuses.Add(bonus);
                                    bon++;
                                    break;
                                }
                                case 0:
                                {
                                    Rectangle bonrect = new Rectangle(0, 0, 80, 60);                                    //min
                                    Vector2 bonposition = GetScreenRect(new Vector2(x, y));
                                    txtBonus = boncollection[2];
                                    bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                                    bonuses.Add(bonus);
                                    bon ++;
                                    break;
                                }
                            }

                            break;
                        }
                    }
                    x += 100;
                }
                j = 0;
                x = 0;
                y += 100;
            }
            recSprite = new Rectangle ( 0, 0, 80, 80 ) ;

            mine=new Me(game, this, ref txtMeleft, ref txtMeright, GetScreenRect(new Vector2(0, 100)), 
                recSprite, boxs, bonuses, enemies);
            game.Components.Add(mine);
        }
예제 #4
0
        void createMaps()
        {
            boxs    = new List <Box>();
            bonuses = new List <bonusElements>();
            enemies = new List <EnemyCollection>();
            string[] lines = File.ReadAllLines(@"D:/Layer.txt");
            int      en = 0, bon = 0;

            levelLength = 100 * lines.Count();
            int x = 0;
            int y = 0;
            int i = lines.Count() - 1, j = 0;

            for (; i >= 0; i--)
            {
                for (; j < lines[i].Length; j++)
                {
                    char c = lines[i][j];
                    switch (c)
                    {
                    case '1':
                    {
                        Rectangle boxrect     = new Rectangle(0, 0, 100, 20);
                        Vector2   boxposition = GetScreenRect(new Vector2(x, y));
                        Box       box         = new Box(ref txtWall, boxposition, boxrect, game);
                        boxs.Add(box);
                        break;
                    }

                    case '2':
                    {
                        bon = (int)new Random().Next(0, 2);
                        switch (en)
                        {
                        case 0:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 100, 65);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 1:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 173, 95);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 2:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 120, 100);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 3:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 50, 100);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 4:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 80, 105);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 5:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 60, 100);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en = 0;
                            break;
                        }
                        }


                        break;
                    }

                    case '3':
                    {
                        bon = (int)new Random().Next(0, 2);
                        switch (bon)
                        {
                        case 2:
                        {
                            Rectangle bonrect     = new Rectangle(0, 0, 63, 110);                                    //max
                            Vector2   bonposition = GetScreenRect(new Vector2(x, y));
                            txtBonus = boncollection[0];
                            bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                            bonuses.Add(bonus);
                            bon = 0;
                            break;
                        }

                        case 1:
                        {
                            Rectangle bonrect     = new Rectangle(0, 0, 21, 80);                                         //midle
                            Vector2   bonposition = GetScreenRect(new Vector2(x, y));
                            txtBonus = boncollection[bon];
                            bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                            bonuses.Add(bonus);
                            bon++;
                            break;
                        }

                        case 0:
                        {
                            Rectangle bonrect     = new Rectangle(0, 0, 80, 60);                                        //min
                            Vector2   bonposition = GetScreenRect(new Vector2(x, y));
                            txtBonus = boncollection[2];
                            bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                            bonuses.Add(bonus);
                            bon++;
                            break;
                        }
                        }

                        break;
                    }
                    }
                    x += 100;
                }
                j  = 0;
                x  = 0;
                y += 100;
            }
            recSprite = new Rectangle(0, 0, 80, 80);

            mine = new Me(game, this, ref txtMeleft, ref txtMeright, GetScreenRect(new Vector2(0, 100)),
                          recSprite, boxs, bonuses, enemies);
            game.Components.Add(mine);
        }