@Override
    public void paintComponent(Graphics g) {

        //if the game has started draw all the game elements
        if (gameStarted == true) {
            g.drawImage(backgroundImage, 0, 0, this);//draw background always

            //draw ennemy tanks
            //cycle through tank array draw an "X" if that tank is dead draw the tank if it is not
            tankitr = activeTanks.iterator();

            while (tankitr.hasNext()) {
                enemyTank theTank = (enemyTank) tankitr.next();

                if (theTank.dead == true) {
                    g.drawImage(redX, (int) (theTank.enemyX - (redX.getWidth(this) / 2)), (int) (theTank.enemyY - (redX.getHeight(this) / 2)), this);
                } else {
                    g.drawImage(enemyTankBase, (int) (theTank.enemyX - (enemyTankBase.getWidth(this) / 2)), (int) (theTank.enemyY - (enemyTankBase.getHeight(this) / 2)), this);
                }
            }

            //draw my tank
            if (!gameOver) {

                //if level faild or game over draw an "X" else draw the thank
                if (!levelFail) {
                    g.drawImage(tankBase, tankX - (tankBase.getWidth(this) / 2), tankY - (tankBase.getHeight(this) / 2), this);

                    //draw the number of bullets in mag
                    for (int b = 1; b < bulletMag - bulletsFired + 1; b++) {
                        g.drawImage(bulletBillA, 50 + (25 * b) - (bulletBillA.getWidth(this) / 2), 800 - (bulletBillA.getHeight(this) / 2), this);
                    }
                } else {
                    g.drawImage(blackX, tankX - (blackX.getWidth(this) / 2), tankY - (blackX.getHeight(this) / 2), this);
                }

                //if level faild or game over draw an "X" else draw the thank
            } else {
                g.drawImage(blackX, tankX - (blackX.getWidth(this) / 2), tankY - (blackX.getHeight(this) / 2), this);
            }

            //draw the bullet
            //cycle through bullet array and draw the bullets
            bulletitr = activeBullets.iterator();

            while (bulletitr.hasNext()) {
                bullet theBullet = (bullet) bulletitr.next();

                //rotate the bullet
                AffineTransform bulletaffineTransform = new AffineTransform();
                bulletaffineTransform.rotate(theBullet.bulletAngle, bullet.getWidth() / 2, bullet.getHeight() / 2);
                AffineTransformOp opRotated = new AffineTransformOp(bulletaffineTransform, AffineTransformOp.TYPE_BILINEAR);

                //bulletRotated is a reotated version of the bullet
                BufferedImage bulletRotated = opRotated.filter(bullet, null);

                //draw the rotated bullet
                g.drawImage(bulletRotated, (int) theBullet.bulletX - (bulletRotated.getWidth(this) / 2), (int) theBullet.bulletY - (bulletRotated.getHeight(this) / 2), this);
            }

            brickitr = activeBricks.iterator();

            while (brickitr.hasNext()) {
                brick theBrick = (brick) brickitr.next();
                    //g.drawImage(brick, (int) (theBrick.brickX - (brick.getWidth(this)/2)),(int) (theBrick.brickY - (brick.getWidth(this)/2)), this);

//rotate the bullet
                AffineTransform affineTransform = new AffineTransform();
                affineTransform.rotate(theBrick.angle, brick.getWidth()+1 / 2, brick.getHeight() / 2);
                AffineTransformOp opRotated = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR);

                //bulletRotated is a reotated version of the bullet
                BufferedImage brickRotated = opRotated.filter(brick, null);

                //draw the rotated bullets
                g.drawImage(brickRotated, (int) theBrick.brickX - (brickRotated.getWidth(this) / 2), (int) theBrick.brickY - (brickRotated.getHeight(this) / 2), this);
            }
            //draw paused sign
            //if the game is paused
            if (pause) {
                g.drawImage(paused, 0, 0, this);
            }

            //draw game over sign
            //if the game is over display game over sign
            if (gameOver) {
                g.drawImage(gameover, 0, 0, this);
            }

            //draw level won sign
            //if you beat the level, draw the level won sign and also display how many lives and what level you have just beaten
            if (levelWon) {

                g.drawImage(levelComplete, 0, 0, this);
                g.setFont(new Font("Impact", Font.BOLD, fontSizeA));
                g.setColor(Color.RED);
                g.drawString(slevel, 1000, 450);
                g.drawString(slives, 600, 650);
                //if you are in god mode display the words "god mode"
                if (godMODE == true) {
                    g.setFont(new Font("Impact", Font.BOLD, fontSizeA));
                    g.setColor(Color.RED);
                    g.drawString("GOD MODE", 300, 300);
                }
            }

            //draw level failed sign
            //if you failed the level, draw the level failed sign and also display how many lives
            if (levelFail == true) {

                g.drawImage(levelFailed, 0, 0, this);
                g.setFont(new Font("Impact", Font.BOLD, fontSizeA));
                g.setColor(Color.RED);
                slives = "Lives:" + Integer.toString(lives);
                g.drawString(slives, 600, 650);

            }
            //if the game has not started
        } else //disply instructions on the instructions page
        if (instructions == true) {
            g.drawImage(instructionsScreen, 0, 0, this);
        } else {
            g.drawImage(startScreen, 0, 0, this);
        }

        //display the stats page
        //show how many level you go to and shows the looing screen
        if (statsPage == true) {

            g.drawImage(loosingScreen, 0, 0, this);
            g.setFont(new Font("Impact", Font.BOLD, fontSizeA));
            g.setColor(Color.RED);
            g.drawString(slevel, 1400, 150);
            y = 325;

            //writes out the highscores
            for (int j = 0; j < scores.length; j++) {
                highScoreLevel = Integer.toString(scores[j].level);
                y += 100;
                g.setFont(new Font("Impact", Font.BOLD, fontSizeA));
                g.setColor(Color.RED);
                g.drawString(scores[j].name, 500, y);
                g.drawString(highScoreLevel, 900, y);
            }

        }

        //display the high scores page
        if (displayHighScore == true) {
            //if in large mode

            g.drawImage(highScoreScreen, 0, 0, this);
            y = 325;

            //writes out the high scores
            for (int i = 0; i < scores.length; i++) {
                highScoreLevel = Integer.toString(scores[i].level);
                y += 100;//lower next line of text
                g.setFont(new Font("Impact", Font.BOLD, fontSizeA));
                g.setColor(Color.RED);
                g.drawString(scores[i].name, 500, y);
                g.drawString(highScoreLevel, 900, y);
            }
        }
    }