Example #1
0
 public virtual void Create(CharData charData, ViewMap viewMap)
 {
     _viewMap = viewMap;
     gameObj = new GameObj();
     gameObj.Init(charData, viewMap.LogicMap);
     gameGo = GameObject.CreatePrimitive(PrimitiveType.Cube);
     gameGo.name = charData.name;
     gameTrans = gameGo.transform;
 }
Example #2
0
 bool checkWalls(GameObj obj, out GameObj collis)
 {
     collis = null;
     foreach (var i in walls)
     {
         if (obj.HitBox.IntersectsWith(i.HitBox) && i != obj)
         {
             collis = i;
             return(true);
         }
     }
     return(false);
 }
Example #3
0
 bool CheckBounds(GameObj obj)
 {
     if (obj.pos.X < 0)
     {
         obj.pos.X = 0;
         return(true);
     }
     if (obj.pos.Y < 0)
     {
         obj.pos.Y = 0;
         return(true);
     }
     if (obj.pos.X > size.Width - obj.Size.Width)
     {
         obj.pos.X = size.Width - obj.Size.Width;
         return(true);
     }
     if (obj.pos.Y > size.Height - obj.Size.Height)
     {
         obj.pos.Y = size.Height - obj.Size.Height;
         return(true);
     }
     return(false);
 }
Example #4
0
        void CheckBulletsCollisions()
        {
            List <GameObj> outofrange = new List <GameObj>();

            foreach (GameObj i in bullets.Concat(user.bullets))
            {
                if (checkWalls(i, out GameObj col))
                {
                    if (col.name == "wall")
                    {
                        outofrange.Add(i);
                        var boom = new GameObj(i.pos, exploisonsSize, animation: GetListFromImage(boomSprite, new Size(39, boomSprite.Height), 7), once: true)
                        {
                            name = "animation"
                        };
                        animations.Add(boom);
                        if (col.CanDestroy == true)
                        {
                            walls.Remove(col);
                        }
                    }
                }

                if (i.HitBox.IntersectsWith(user.HitBox) && i.name == "enemybullet")
                {
                    OnGameOver?.Invoke();
                    break;
                }
                if (CheckBounds(i))
                {
                    outofrange.Add(i);
                }
            }
            outofrange.ForEach(x => bullets.Remove(x));
            outofrange.ForEach(x => user.bullets.Remove(x));
        }
Example #5
0
        public Game(int countOfTanks, int countOfStars, int speed, Size size)
        {
            this.bounds       = new RectangleF(0, 0, size.Width, size.Height);
            this.countOfTanks = countOfTanks;
            this.countOfStars = countOfStars;
            this.speed        = speed;
            this.size         = size;

            user = new User(new PointF(size.Width / 2, size.Height / 2), userSize, this.speed + 5, playerSprite)
            {
                name = "user", moveable = true
            };


            while (walls.Count < 8)
            {
                bool canDestroy = (rand.NextDouble() < 0.5) ? true : false;
                var  wallsprite = canDestroy ? Properties.Resources.RTS_Crate1 : wallSprite;
                var  wall       = new GameObj(new PointF(rand.Next(size.Width - enemySize.Width), rand.Next(size.Height - enemySize.Height)), enemySize, image: wallsprite)
                {
                    name = "wall", CanDestroy = canDestroy
                };
                walls.Add(wall);
                if (user.HitBox.IntersectsWith(wall.HitBox) || CheckEnenymiesCollisions().Count() != 0)
                {
                    walls.Remove(wall);
                }
            }

            while (walls.Count < 12)
            {
                bool canAdd        = true;
                var  randDirection = (rand.NextDouble() < 0.5) ? Direction.bot : Direction.right;
                var  water         = new GameObj(new PointF(rand.Next(size.Width - waterSize.Width), rand.Next(size.Height - waterSize.Height)), waterSize, image: waterSprite, direction: randDirection)
                {
                    name = "water"
                };
                foreach (var i in walls.Append(user))
                {
                    if (i.name == "water")
                    {
                        continue;
                    }
                    if (i.HitBox.IntersectsWith(water.HitBox))
                    {
                        canAdd = false;
                    }
                }
                if (canAdd)
                {
                    walls.Add(water);
                }
            }

            while (enemies.Count() < countOfTanks)
            {
                //Возможно лишнее и CheckEnenymiesCollisions() хватало. не уверен
                var enemy = new Enemy(new PointF(rand.Next(size.Width - enemySize.Width), rand.Next(size.Height - enemySize.Height)), speed, enemySize, enemySprite)
                {
                    name = "enemy", moveable = true
                };
                bool canAdd = true;
                foreach (var i in enemies.Concat(walls).Append(user))
                {
                    var r1 = new PointF(enemy.pos.X + enemy.HitBox.Width / 2, enemy.pos.Y + enemy.HitBox.Height / 2);
                    var r2 = new PointF(i.pos.X + i.HitBox.Width / 2, i.pos.Y + i.HitBox.Height / 2);
                    if (Math.Sqrt(Math.Pow(r2.X - r1.X, 2) + Math.Pow(r2.Y - r1.Y, 2)) < Math.Max(enemySize.Width * 2, enemySize.Height * 2))
                    {
                        canAdd = false;
                        break;
                    }
                }
                if (canAdd)
                {
                    enemies.Add(enemy);
                }
            }

            while (stars.Count() < countOfStars)
            {
                var star = new GameObj(new PointF(rand.Next(size.Width - enemySize.Width), rand.Next(size.Height - enemySize.Height)), enemySize, animation: GetListFromImage(starSprite, new Size(84, starSprite.Height), 6))
                {
                    name = "star"
                };
                if (!user.HitBox.IntersectsWith(star.HitBox) && !checkWalls(star, out _))
                {
                    stars.Add(star);
                }
            }
        }