コード例 #1
0
        public bool MoveBullet(int width, int height)
        {
            if (ball.Bullet.IsEnable)
            {
                MoveBullet(ball.Bullet);

                if (Collision.CollisionWithBorders(ball.Bullet, width, height))
                {
                    ball.Bullet.IsEnable    = false;
                    ball.Bullet.wasDisabled = DateTime.Now;
                }

                foreach (Block block in BlockModel.GetBlocks())
                {
                    if (Collision.CollisionBox(ball.Bullet, block) && block.IsEnabled)
                    {
                        ball.Bullet.IsEnable    = false;
                        ball.Bullet.wasDisabled = DateTime.Now;

                        if (block.Name == "b")
                        {
                            block.IsEnabled = false;
                        }
                    }
                }

                foreach (Tank tank in TankModel.GetTanks())
                {
                    if (Collision.CollisionBox(ball.Bullet, tank) && tank.IsEnable)
                    {
                        ball.Bullet.IsEnable    = false;
                        ball.Bullet.wasDisabled = DateTime.Now;
                        tank.IsEnable           = false;
                        tank.PosX = -tank.Size;

                        return(true);
                    }

                    if (Collision.CollisionBox(ball.Bullet, tank.Bullet))
                    {
                        ball.Bullet.IsEnable    = false;
                        tank.Bullet.IsEnable    = false;
                        ball.Bullet.wasDisabled = DateTime.Now;
                        tank.Bullet.wasDisabled = DateTime.Now;

                        tank.Bullet.PosX = -tank.Size;
                        ball.Bullet.PosX = -ball.Size;
                    }
                }
            }

            return(false);
        }
コード例 #2
0
        public void CheckCollision(int x, int y, int width, int height)
        {
            if (Collision.CollisionWithBorders(ball, width, height))
            {
                ball.PosX -= x;
                ball.PosY -= y;
            }

            foreach (Block block in BlockModel.GetBlocks())
            {
                if (Collision.CollisionBox(ball, block) && block.IsEnabled)
                {
                    ball.PosX -= x;
                    ball.PosY -= y;
                }
            }
        }
コード例 #3
0
        public void CreateApple(int num, int size, int width, int height)
        {
            while (apples.Count < num)
            {
                bool canBePlaced = true;

                do
                {
                    canBePlaced = true;

                    apples.Add(new Apple(rnd.Next(width - size), rnd.Next(height - size), size));

                    foreach (Block block in BlockModel.GetBlocks())
                    {
                        if (apples.Count > 0 && Collision.CollisionBox(apples.Last(), block))
                        {
                            canBePlaced = false;
                            apples.Remove(apples.Last());
                        }
                    }
                } while (!canBePlaced);
            }
        }
コード例 #4
0
        public bool MoveBullet(int width, int height)
        {
            foreach (Tank tank in tanks)
            {
                if (tank.Bullet.IsEnable)
                {
                    MoveBullet(tank, tank.Bullet);

                    if (Collision.CollisionWithBorders(tank.Bullet, width, height))
                    {
                        tank.Bullet.IsEnable    = false;
                        tank.Bullet.PosX        = -tank.Size;
                        tank.Bullet.wasDisabled = DateTime.Now;
                    }

                    if (Collision.CollisionBox(tank.Bullet, BallModel.GetBall()))
                    {
                        return(true);
                    }

                    foreach (Block block in BlockModel.GetBlocks())
                    {
                        if (Collision.CollisionBox(tank.Bullet, block) && block.IsEnabled)
                        {
                            tank.Bullet.IsEnable    = false;
                            tank.Bullet.PosX        = -tank.Size;
                            tank.Bullet.wasDisabled = DateTime.Now;

                            if (block.Name == "b")
                            {
                                block.IsEnabled = false;
                            }
                        }
                    }

                    foreach (Tank el in tanks)
                    {
                        if (el != tank)
                        {
                            if (Collision.CollisionBox(tank.Bullet, el))
                            {
                                tank.Bullet.IsEnable    = false;
                                tank.Bullet.PosX        = -tank.Size;
                                tank.Bullet.wasDisabled = DateTime.Now;
                            }

                            if (Collision.CollisionBox(tank.Bullet, el.Bullet))
                            {
                                tank.Bullet.IsEnable    = false;
                                tank.Bullet.PosX        = -tank.Size;
                                el.Bullet.IsEnable      = false;
                                el.Bullet.PosX          = -el.Size;
                                tank.Bullet.wasDisabled = DateTime.Now;
                                el.Bullet.wasDisabled   = DateTime.Now;
                            }
                        }
                    }
                }
            }

            return(false);
        }