Beispiel #1
0
        public void InitializeBrickz()
        {
            //
            for(int i = 0; i<Brickz.Length; i++)//SETS LOCATION, SIZE, AND TYPES OF BRICKS. initializing.
            {
                //ROW ONE
                if (i < 1)//the first brick
                    //              (xPos + int for not sticking,    yPos + int for bricks not sticking, height,width, bricktype, is active?)
                    Brickz[i] = new Brick(brickGroupPosX + i * brickDistanceX, brickGroupPosY, brickRadius, brickRadius, slowBalls, true);//slow balls / blue
                if (i >= 1 && i < 7)
                    Brickz[i] = new Brick(brickGroupPosX + i * brickDistanceX + i, brickGroupPosY, brickRadius, brickRadius, normal, true);//normal / gray
                if (i >= 7 && i < 14)
                    Brickz[i] = new Brick(brickGroupPosX+250 + i * brickDistanceX + i, brickGroupPosY, brickRadius, brickRadius, normal, true);//normal / gray
                if (i >= 14 && i < 15)
                    Brickz[i] = new Brick(brickGroupPosX+250 + i * brickDistanceX + i, brickGroupPosY, brickRadius, brickRadius, fastBalls, true);//fast balls / red

                // ROW TWO
                else if (i >= 15 && i < 16)
                    Brickz[i] = new Brick(brickGroupPosX + 20 + (i - 15) * brickDistanceX + (i - 15), brickGroupPosY + brickDistanceY, brickRadius, brickRadius, doubleBall, true);//double / gray
                else if (i >= 16 && i < 22)
                    Brickz[i] = new Brick(brickGroupPosX + 20 + (i - 15) * brickDistanceX + (i - 15), brickGroupPosY + brickDistanceY, brickRadius, brickRadius, normal, true);//normal / gray
                else if (i >= 22 && i < 29)
                    Brickz[i] = new Brick(brickGroupPosX + 230 + (i - 15) * brickDistanceX + (i - 15), brickGroupPosY + brickDistanceY, brickRadius, brickRadius, normal, true);//normal / gray
                else if (i >= 29 && i < 30)
                    Brickz[i] = new Brick(brickGroupPosX + 230 + (i - 15) * brickDistanceX + (i - 15), brickGroupPosY + brickDistanceY, brickRadius, brickRadius, doubleBall, true);//double / gray

                //ROW THREE
                else if (i >= 30 && i < 31)
                    Brickz[i] = new Brick(brickGroupPosX + 40 + (i - 30) * brickDistanceX + (i - 30), brickGroupPosY + 2 * brickDistanceY, brickRadius, brickRadius, slowBalls, true);//slow / blue
                else if (i >= 31 && i < 37)
                    Brickz[i] = new Brick(brickGroupPosX + 40 + (i - 30) * brickDistanceX + (i - 30), brickGroupPosY + 2 * brickDistanceY , brickRadius, brickRadius, normal, true);//normal / gray
                else if (i >= 37 && i < 44)
                    Brickz[i] = new Brick(brickGroupPosX + 210 + (i - 30) * brickDistanceX + (i - 30), brickGroupPosY + 2 * brickDistanceY, brickRadius, brickRadius, normal, true);//normal / gray
                else if (i >= 44 && i < 45)
                    Brickz[i] = new Brick(brickGroupPosX + 210 + (i - 30) * brickDistanceX + (i - 30), brickGroupPosY + 2 * brickDistanceY, brickRadius, brickRadius, fastBalls, true);//fast / red

                //ROW FOUR - not existing. possible to add new bricks.
                else if (i >= 45 && i < 60)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 45) * brickRadius + (i - 45), brickGroupPosY + 3 * brickRadius + 3, brickRadius, brickRadius, normal, true);//normal / gray
            }
        }
Beispiel #2
0
        //initialize BALLS AND BRICKS
        public void InitializeBrickz()
        {
            //
            for(int i = 0; i<Brickz.Length; i++)//SETS LOCATION AND TYPES OF BRICKS. initializing.
            {//if I want a special brick, make a small if statement in between.
                //ROW ONE
                if(i < 1)//the first brick
                    Brickz[i] = new Brick(brickGroupPosX + i * brickWidth + i, brickGroupPosY, brickHeight, brickWidth, slowBalls, true);//slow balls / blue

                if (i >= 1 && i < 14)
                    Brickz[i] = new Brick(brickGroupPosX + i * brickWidth + i, brickGroupPosY, brickHeight, brickWidth, normal, true);//normal / gray

                if (i >= 14 && i < 15)
                    Brickz[i] = new Brick(brickGroupPosX + i * brickWidth + i, brickGroupPosY, brickHeight, brickWidth, fastBalls, true);//fast balls / orange

                // ROW TWO
                else if(i >= 15 && i < 20)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 15) * brickWidth + (i - 15), brickGroupPosY + 1 * brickHeight + 1, brickHeight, brickWidth, normal, true);//normal / gray
                else if (i >= 20 && i < 25)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 15) * brickWidth + (i - 15), brickGroupPosY + 1 * brickHeight + 1, brickHeight, brickWidth, doubleBall, true);//double ball / green
                else if (i >= 25 && i < 30)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 15) * brickWidth + (i - 15), brickGroupPosY + 1 * brickHeight + 1, brickHeight, brickWidth, normal, true);//normal / gray

                //ROW THREE
                else if(i >= 30 && i < 35)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 30) * brickWidth + (i - 30), brickGroupPosY + 2 * brickHeight + 2, brickHeight, brickWidth, normal, true);//normal / gray
                else if (i >= 35 && i < 40)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 30) * brickWidth + (i - 30), brickGroupPosY + 2 * brickHeight + 2, brickHeight, brickWidth, normal, true);//normal / gray
                else if (i >= 40 && i < 45)
                    Brickz[i] = new Brick(brickGroupPosX + (i - 30) * brickWidth + (i - 30), brickGroupPosY + 2 * brickHeight + 2, brickHeight, brickWidth, doubleBall, true);//normal / gray

                //ROW FOUR - not existing yet
                else if (i >= 45 && i < 60)//last bricks
                    Brickz[i] = new Brick(brickGroupPosX + (i - 45) * brickWidth + (i - 45), brickGroupPosY + 3 * brickHeight + 3, brickHeight, brickWidth, normal, true);//normal / gray
                //                                        (xPos + int for not sticking,  yPos + int for bricks not sticking  ,   height,    width, bricktype, is active?)
            }
        }
Beispiel #3
0
        //this should not run on next frame, or balls will return.
        public void calculateBrickCollision(Brick brick)
        {
            double collisionTangent = Math.Atan2((double)yDist, (double)xDist); //returns the angle of the tangent of the vector which is the collision x and y distance.
            double sin = Math.Sin(collisionTangent);
            double cos = Math.Cos(collisionTangent);
            //rotate ball 0 pos
            double B0x = 0;//relative x & y pos set
            double B0y = 0;
            //set ball 1 pos relative to ball 0, aka distance.
            double B1x = xDist * cos + yDist * sin;//RELATIVE TO BALL 0!!!
            double B1y = yDist * cos - xDist * sin;
            //rotate ball 0 velocity
            double V0x = xSpeed * cos + ySpeed * sin;
            double V0y = ySpeed * cos - xSpeed * sin;
            //rotate brick 1 velocity
            double V1x = 0;
            double V1y = 0;

            //collision reaction ELASTISK LIGNING I BOKA?, tror denne gjør at de ikke setter seg fast, må plusse på noe ekstra? eller ikke siden det er vel.
            double vxtotal = V0x - V1x;
            V0x = ((mass - brick.getMass()) * V0x + 2 * brick.getMass() * V1x) / (mass + brick.getMass());//new velocity x ball 1
            V1x = vxtotal + V0x; //new velocity x ball 2
            //update position, THIS ONE IS RELATIVE TO MID BALL 0 and BALL 1
            B0x += V0x;
            B1x += V1x;
            //rot pos back? SET NEW POSITION. BALLS SHOULD OVERLAP AFTER THIS.
            double B0newPosx = B0x * cos - B0y * sin;
            double B0newPosy = B0y * cos + B0x * sin;

            double B1newPosx = B1x * cos - B1y * sin;
            double B1newPosy = B1y * cos + B1x * sin;

            //rot vel back?
            double B0newVelx = V0x * cos - V0y * sin;
            double B0newVely = V0y * cos + V0x * sin;

            double B1newVelx = V1x * cos - V1y * sin;
            double B1newVely = V1y * cos + V1x * sin;

            //update pos
            xPos = xPos + (float)B0newPosx;//these 2 new positions will be a little "bigger" than when they entered. this is so that they wont stick. also, they point slightly away from each other.
            yPos = yPos + (float)B0newPosy;

            //update speed
            xSpeed = (float)B0newVelx;
            ySpeed = (float)B0newVely;
        }
Beispiel #4
0
 //brick collision
 public bool checkBrickCollision(Brick b, float iSpeed, bool isAlive)
 {
     //2.1F is for accuracy, so the balls wont skip collision detection and venture into the brick.
     if (isAlive == true)
     {//brick top
         if (yPos + radius >= b.top && yPos + radius <= b.top + 2.1F && xPos >= b.left && xPos <= b.right)
         {
             ySpeed = -iSpeed;//so that we have constant speeds.
             yPos -= 2;
             return true;
         }//brick bot
         if (yPos - radius <= b.bot  && yPos - radius >= b.bot -2.1F && xPos >= b.left && xPos <= b.right)
         {
             ySpeed = iSpeed;
             yPos += 2;
             return true;
         }//brick left
         if (yPos + radius >= b.top && yPos - radius <= b.bot && xPos + radius >= b.left && xPos + radius <= b.left + 2.1F)
         {
             xSpeed = -iSpeed;
             xPos -= 2;
             return true;
         }//brick right
         if (yPos + radius >= b.top && yPos - radius <= b.bot && xPos - radius >= b.right -2.1F  && xPos - radius <= b.right )
         {
             xSpeed = iSpeed;
             xPos += 2;
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Beispiel #5
0
        //brick collision
        public bool checkBrickCollision(Brick brick)
        {
            xDist = brick.getX() - xPos;//dx
            yDist = brick.getY() - yPos;//dy

            float radDist = radius + brick.getWidth();

            if (radDist * radDist >= (xDist * xDist + yDist * yDist) && inPlay == true && brick.isAlive == true) //check if distance is bigger than the balls touching range and is alive
            {
                return true;
            }
            else
            {
                return false;
            }
        }