public bool CheckCollision(Player2 s, Item i)
        {
            float leftA, leftB;
            float rightA, rightB;
            float topA, topB;
            float bottomA, bottomB;

            leftA = i.Pos.X;
            rightA = i.Pos.X + i.SpriteTexture.Width;
            topA = i.Pos.Y;
            bottomA = i.Pos.Y + i.SpriteTexture.Height;

            leftB = s.Pos.X;
            rightB = s.Pos.X + s.SpriteTexture.Width;
            topB = s.Pos.Y;
            bottomB = s.Pos.Y + s.SpriteTexture.Height;

            if (bottomA <= topB)
            {
                return false;
            }

            if (topA >= bottomB)
            {
                return false;
            }

            if (rightA <= leftB)
            {
                return false;
            }

            if (leftA >= rightB)
            {
                return false;
            }

            //If none of the sides from A are outside B
            return true;
        }
Exemple #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Segoi           = Content.Load <SpriteFont>("SpriteFont1");
            SegoiSmall      = Content.Load <SpriteFont>("SpriteFont2");
            ForegroundBatch = new SpriteBatch(GraphicsDevice);

            windowWidth  = Window.ClientBounds.Width;
            windowHeight = Window.ClientBounds.Height - 37;
            MyCircle     = new Player(Content, spriteBatch);
            checkTime    = DateTime.Now.Second;

            BGTexture = Content.Load <Texture2D>("bhtex");

            currentLevel = new Level(@"Content/MAP.txt");
            Random random = new Random(DateTime.Now.Millisecond);

            Random random2 = new Random(DateTime.Now.Millisecond);



            for (int i = 0; i < currentLevel.Grid.Count; i++)
            {
                for (int j = 0; j < Level.Width; j++)
                {
                    if (currentLevel.Grid[i][j])
                    {
                        byte r = (byte)random2.Next(0, 255);
                        byte g = (byte)random2.Next(0, 255);
                        byte b = (byte)random2.Next(0, 255);

                        Color tempCol;
                        tempCol = new Color(r, g, b);
                        Random random3 = new Random(DateTime.Now.Millisecond);
                        int    temp    = random.Next(0, 100);
                        surfaces.Add(new Surface(Content, spriteBatch, 43, 42, j * 43, i * 42, j, i, tempCol, temp, false));
                        if (i == currentLevel.Grid.Count - 1)
                        {
                            for (int k = 1; k < 4; k++)
                            {
                                surfaces.Add(new Surface(Content, spriteBatch, 43, 42, j * 43, (i + k) * 42, j, i, tempCol, temp, true));
                            }
                        }
                    }
                    else
                    {
                        if (random.Next(0, 100) < 30 && i != currentLevel.Grid.Count - 1 && i > 0)
                        {
                            if (currentLevel.Grid[i][j] == false && currentLevel.Grid[i + 1][j] == true)
                            {
                                items.Add(new Item(Content, spriteBatch, j * 43 + (43 / 4), i * 42 + 12, "cherry"));
                            }
                        }
                    }
                }
            }
            int starX = (random.Next(2, Level.Width - 1));

            while (!spawnedStar)
            {
                int randHeight = random.Next(1, Level.Height - 1);
                if (currentLevel.Grid[randHeight][starX] == false && currentLevel.Grid[randHeight + 1][starX] == true)
                {
                    items.Add(new Item(Content, spriteBatch, starX * 43 + (43 / 4), (randHeight) * 42 + 12, "star"));
                    starPos.X   = starX * 43 + (43 / 4);
                    starPos.Y   = (randHeight) * 42 + 12;
                    spawnedStar = true;
                    //break;
                }
                else
                {
                    starX = random.Next(2, Level.Width - 1);
                }
            }

            MyCircle  = new Player(Content, spriteBatch);
            MyCircle2 = new Player2(Content, spriteBatch);
            MyCircle3 = new Player3(Content, spriteBatch);
            MyCircle4 = new Player4(Content, spriteBatch);



            //items.Add(new Item(Content, spriteBatch, starX * 43 + (43 / 4), 8 * 42 + 12, "star"));



            // TODO: use this.Content to load your game content here
        }
Exemple #3
0
        protected void nextLevel()
        {
            surfaces.Clear();
            items.Clear();
            spawnedStar = false;
            bgColor     = Color.SkyBlue;

            currentLevel = new Level(@"Content/MAP.txt");
            Random random = new Random(DateTime.Now.Millisecond);

            Random random2 = new Random(DateTime.Now.Millisecond);



            for (int i = 0; i < currentLevel.Grid.Count; i++)
            {
                for (int j = 0; j < Level.Width; j++)
                {
                    if (currentLevel.Grid[i][j])
                    {
                        byte r = (byte)random2.Next(0, 255);
                        byte g = (byte)random2.Next(0, 255);
                        byte b = (byte)random2.Next(0, 255);

                        Color tempCol;
                        tempCol = new Color(r, g, b);
                        Random random3 = new Random(DateTime.Now.Millisecond);
                        int    temp    = random.Next(0, 100);
                        surfaces.Add(new Surface(Content, spriteBatch, 43, 42, j * 43, i * 42, j, i, tempCol, temp, false));
                        if (i == currentLevel.Grid.Count - 1)
                        {
                            for (int k = 1; k < 4; k++)
                            {
                                surfaces.Add(new Surface(Content, spriteBatch, 43, 42, j * 43, (i + k) * 42, j, i, tempCol, temp, true));
                            }
                        }
                    }
                    else
                    {
                        if (random.Next(0, 100) < 30 && i != currentLevel.Grid.Count - 1 && i > 0)
                        {
                            if (currentLevel.Grid[i][j] == false && currentLevel.Grid[i + 1][j] == true)
                            {
                                items.Add(new Item(Content, spriteBatch, j * 43 + (43 / 4), i * 42 + 12, "cherry"));
                            }
                        }
                    }
                }
            }
            int starX = (random.Next(2, Level.Width - 1));

            while (!spawnedStar)
            {
                if (starAttempCount > 100)
                {
                    starAttempCount = 0;
                    break;
                }
                int randHeight = random.Next(1, Level.Height - 1);
                if (currentLevel.Grid[randHeight][starX] == false && currentLevel.Grid[randHeight + 1][starX] == true)
                {
                    items.Add(new Item(Content, spriteBatch, starX * 43 + (43 / 4), (randHeight) * 42 + 12, "star"));
                    starPos.X   = starX * 43 + (43 / 4);
                    starPos.Y   = (randHeight) * 42 + 12;
                    spawnedStar = true;
                    //break;
                }
                else
                {
                    starX = random.Next(2, Level.Width - 1);
                }
            }
            score1          = MyCircle.Score;
            score2          = MyCircle2.Score;
            score3          = MyCircle3.Score;
            score4          = MyCircle4.Score;
            MyCircle        = new Player(Content, spriteBatch);
            MyCircle2       = new Player2(Content, spriteBatch);
            MyCircle3       = new Player3(Content, spriteBatch);
            MyCircle4       = new Player4(Content, spriteBatch);
            MyCircle.Score  = score1;
            MyCircle2.Score = score2;
            MyCircle3.Score = score3;
            MyCircle4.Score = score4;

            if (!spawnedStar)
            {
                nextLevel();
            }
        }