Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.*;
- import java.awt.event.*;
- import java.awt.*;
- import java.awt.event.MouseAdapter;
- import java.awt.image.BufferedImage;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import javax.swing.ImageIcon;
- import javax.swing.Timer;
- public class braekuot extends Applet implements MouseMotionListener, ActionListener{
- ball ball;
- paddle paddle;
- squirtle squirtle;
- zombie zombie;
- brick[][] bricks = new brick[5][20];
- Color[][] brickColorsArray = new Color[bricks.length][bricks[1].length];
- int score = 0;
- Color[] brickColors = {new Color(255, 128, 128), new Color(255, 192, 192), Color.white, Color.gray, Color.black, new Color(128, 0, 0), Color.pink, new Color(255, 0, 128), Color.magenta, new Color (128, 0, 255), Color.blue, new Color (0, 128, 255), Color.cyan, new Color(0, 255, 128), new Color(128, 255, 0), Color.yellow, Color.orange, new Color(255, 128, 0), Color.red};
- int currentColor = 0;
- int lives = 3;
- String name;
- Font scoreFont = new Font("myriadpro", Font.BOLD, 15);
- Graphics bufferGraphics;
- Image offscreen;
- Image squirt;
- Image zomb;
- long currentTime;
- boolean mouseWasClicked = false;
- boolean isThereAZombie = false;
- boolean isThereASquirtle = false;
- boolean acidTrip = false;
- static final int windowWidth = 480, windowHeight = 720;
- int numberOfBricks = 100;
- int displayCase;
- AudioClip sideHitSound;
- AudioClip paddleHitSound;
- AudioClip brickHitSound;
- AudioClip lifeLossSound;
- AudioClip deathSound;
- AudioClip startSound;
- AudioClip music;
- AudioClip zombieSpawnedSound;
- AudioClip zombieKilledSound;
- AudioClip squirtleSpawnedSound;
- AudioClip squirtleFaintSound;
- /* sideHitSound = getAudioClip(getDocumentBase(),"side.wav");
- paddleHitSound = getAudioClip(getDocumentBase(),"paddle.wav");
- brickHitSound = getAudioClip(getDocumentBase(),"brick.wav");
- lifeLossSound = getAudioClip(getDocumentBase(),"");//nope.avi
- deathSound = getAudioClip(getDocumentBase(),"loss.wav");
- startSound = getAudioClip(getDocumentBase(),"shootS.au");//"lets begin"
- music = getAudioClip(getDocumentBase(),"dataS.au"); //impedus
- */
- public void init() {
- sideHitSound = getAudioClip(getDocumentBase(),"side.wav");
- paddleHitSound = getAudioClip(getDocumentBase(),"file:paddle.wav");
- brickHitSound = getAudioClip(getDocumentBase(),"brick.wav");
- lifeLossSound = getAudioClip(getDocumentBase(),"nah.wav");//nope.avi
- deathSound = getAudioClip(getDocumentBase(),"loss.wav");
- startSound = getAudioClip(getDocumentBase(),"shootS.au");//"lets begin"
- zombieSpawnedSound = getAudioClip(getDocumentBase(), "bleg.wav");//minecraft
- zombieKilledSound = getAudioClip(getDocumentBase(), "blug.wav");//minecraft
- squirtleSpawnedSound = getAudioClip(getDocumentBase(), "skeet.wav");//pokemon
- squirtleFaintSound = getAudioClip(getDocumentBase(), "skat.wav");//pokemon
- music = getAudioClip(getDocumentBase(),"impetus.wav");
- squirt = getImage(getDocumentBase(), "squirtle.png");
- zomb = getImage(getDocumentBase(), "zombie.png");
- name = highScoreTable.checkString();
- setSize(windowHeight, windowWidth);
- displayCase=0;
- ball = new ball();
- paddle = new paddle();
- for (int i = bricks.length-1; i >= 0; i--){
- for (int j = bricks[i].length-1; j >= 0; j--){
- bricks[i][j] = new brick();
- bricks[i][j].setPos(windowHeight/20*j, 15*i);
- }
- }
- for (int i = bricks.length-1; i >= 0; i--){
- for (int j = bricks[i].length-1; j >= 0; j--){
- brickColorsArray[i][j] = brickColors[currentColor%19];
- currentColor++;
- }
- }
- System.out.println("check 2");
- addMouseMotionListener(this);
- addMouseListener(new MouseAdapter(){
- public void mouseClicked(MouseEvent evt){
- displayCase=1;
- }
- });
- setBackground(Color.blue);
- offscreen = createImage(windowHeight, windowWidth);
- bufferGraphics = offscreen.getGraphics();
- startSound.play();
- music.play();
- }
- public void start(){
- currentTime = System.currentTimeMillis();
- Timer time = new Timer(15, this);
- time.start();
- currentTime = System.currentTimeMillis() - currentTime;
- }
- public void stop(){}
- public void actionPerformed(ActionEvent e){
- ball.move();
- checkCollision();
- walkingDead();
- iChooseYou();
- repaint();
- }
- public void mouseMoved(MouseEvent evt){
- paddle.setPos(evt.getX()- 35);
- }
- public void mouseDragged(MouseEvent evt){}
- public void walkingDead(){
- if ((isThereAZombie==false)&&(0+(int)(Math.random()*(600)+1)==99)){
- zombie = new zombie();
- isThereAZombie = true;
- }
- if (isThereAZombie==true){
- zombie.setPos(zombie.getX()+10, zombie.getY());
- }
- }
- public void iChooseYou(){
- if ((isThereASquirtle==false)&&(0+(int)(Math.random()*(1200)+1)==100)){
- squirtle = new squirtle();
- isThereASquirtle = true;
- }
- if (isThereASquirtle==true){
- squirtle.setPos(squirtle.getX()-15, squirtle.getY());
- }
- }
- public void checkCollision(){
- if(ball.getY() == 0){
- ball.dy = (ball.dy * -1);
- music.play();
- }
- if(ball.getY() == 480){
- ball.dy = (ball.dy * -1);
- lives--;
- ball.reset();
- lifeLossSound.play();
- if ((lives<=0)||(numberOfBricks==0))
- displayCase=2;
- }
- if(ball.getX() == 0 || ball.getX() == 720){
- ball.dx = (ball.dx * -1);
- music.play();
- }
- if(hitPaddle()){
- ball.dy = (ball.dy * -1);
- paddleHitSound.play();
- }
- if(hitBrickVerical()){
- ball.dx = (ball.dx*-1);
- brickHitSound.play();
- }
- if(hitBrickHorizontal()){
- ball.dy = (ball.dy*-1);
- brickHitSound.play();
- }
- if(hitSquirtleHorizontal()){
- ball.dy=(ball.dy*-1);
- squirtleFaintSound.play();
- }
- if(hitSquirtleVertical()){
- ball.dx=(ball.dx*-1);
- squirtleFaintSound.play();
- }
- if(hitZombieHorizontal()){
- ball.dy=(ball.dy*-1);
- zombieKilledSound.play();
- }
- if(hitZombieVertical()){
- ball.dx=(ball.dx*-1);
- zombieKilledSound.play();
- }
- }
- public boolean hitPaddle(){
- boolean hit = false;
- if(((ball.getX()+10>= paddle.getX())&&(ball.getX()<=paddle.getX()+70))&&(ball.getY()+10==paddle.getY())){
- hit = true;
- }
- return hit;
- }
- public boolean hitBrickHorizontal(){
- boolean hit = false;
- for (int i = bricks.length-1; i >= 0; i--){
- for (int j = bricks[i].length-1; j >= 0; j--){
- if((((ball.getX()+10>=bricks[i][j].getX()&&ball.getX()<=bricks[i][j].getX()+(windowWidth/20))&&(ball.getY()==bricks[i][j].getY()+15)||(ball.getY()+10==bricks[i][j].getY())))&&bricks[i][j].getBroken()==false){
- hit = true;
- bricks[i][j].setBroken(true);
- score = score+100;
- numberOfBricks--;
- return hit;
- }
- }
- }
- return hit;
- }
- public boolean hitBrickVerical(){
- boolean hit = false;
- for (int i = bricks.length-1; i >= 0; i--){
- for (int j = bricks[i].length-1; j >= 0; j--){
- if(((ball.getY()<=bricks[i][j].getY()+15)&&(ball.getY()+10>=bricks[i][j].getY()))&&((ball.getX()==bricks[i][j].getX()+20/windowWidth)||(ball.getX()+10==bricks[i][j].getX()))&&bricks[i][j].getBroken()==false){
- hit = true;
- bricks[i][j].setBroken(true);
- score = score+100;
- numberOfBricks--;
- return hit;
- }
- }
- }
- return hit;
- }
- public boolean hitSquirtleHorizontal(){
- boolean hit = false;
- if (isThereASquirtle == true){
- if((((ball.getX()+10>=squirtle.getX()&&ball.getX()<=squirtle.getX()+20)&&(ball.getY()==squirtle.getY()+15)||(ball.getY()+10==squirtle.getY())))&&squirtle.getFainted()==false){
- hit = true;
- squirtle.setStatus(true);
- score = score+300;
- isThereASquirtle = false;
- return hit;
- }
- }
- return hit;
- }
- public boolean hitSquirtleVertical(){
- boolean hit = false;
- if (isThereASquirtle == true){
- if(((ball.getY()<=squirtle.getY()+15)&&(ball.getY()+10>=squirtle.getY()))&&((ball.getX()==squirtle.getX()+20)||(ball.getX()+10==squirtle.getX()))&&squirtle.getFainted()==false){
- hit = true;
- squirtle.setStatus(true);
- score = score+300;
- isThereASquirtle = false;
- return hit;
- }
- }
- return hit;
- }
- public boolean hitZombieVertical(){
- boolean hit = false;
- if(isThereAZombie == true){
- if(((ball.getY()<=zombie.getY()+15)&&(ball.getY()+10>=zombie.getY()))&&((ball.getX()==zombie.getX()+20)||(ball.getX()+10==zombie.getX()))&&zombie.getLiving()==false){
- hit = true;
- zombie.setLiving(true);
- score = score+200;
- isThereAZombie = false;
- return hit;
- }
- }
- return hit;
- }
- public boolean hitZombieHorizontal(){
- boolean hit = false;
- if(isThereAZombie == true){
- if((((ball.getX()+10>=zombie.getX()&&ball.getX()<=zombie.getX()+20)&&(ball.getY()==zombie.getY()+15)||(ball.getY()+10==zombie.getY())))&&zombie.getLiving()==false){
- hit = true;
- zombie.setLiving(true);
- score = score+200;
- isThereAZombie = false;
- return hit;
- }
- }
- return hit;
- }
- public void paint(Graphics g){
- if (displayCase==0){
- bufferGraphics.clearRect(0, 0, windowHeight, windowWidth);
- bufferGraphics.setFont(scoreFont);
- bufferGraphics.setColor(Color.gray);
- bufferGraphics.drawString("Braekuot", 320, 200);
- bufferGraphics.drawString("A game by Brandon Slaght", 260, 220);
- ball.reset();
- g.drawImage(offscreen,0,0,this);
- Toolkit.getDefaultToolkit().sync();
- }
- if (displayCase==1){
- bufferGraphics.clearRect(0, 0, windowHeight, windowWidth);
- bufferGraphics.setColor(Color.green);
- bufferGraphics.fillRect(paddle.getX(),paddle.paddleY,70,10);
- bufferGraphics.setColor(Color.white);
- bufferGraphics.setFont(scoreFont);
- bufferGraphics.drawString("Score: "+Integer.toString(score)+" Lives: "+Integer.toString(lives), 15, windowWidth-15);
- for (int i = bricks.length-1; i >= 0; i--){
- for (int j = bricks[i].length-1; j >= 0; j--){
- if (bricks[i][j].getBroken()==false){
- bufferGraphics.setColor(brickColorsArray[i][j]);
- bufferGraphics.fillRect(bricks[i][j].getX(),bricks[i][j].getY(), 36, 15);
- }
- }
- }
- bufferGraphics.setColor(Color.red);
- bufferGraphics.fillOval(ball.getX(),ball.getY(),10,10);
- if(isThereASquirtle == true )
- bufferGraphics.drawImage(squirt, squirtle.getX(), squirtle.getY(), null);
- if(isThereAZombie == true)
- bufferGraphics.drawImage(zomb, zombie.getX(), zombie.getY(), null);
- g.drawImage(offscreen,0,0,this);
- Toolkit.getDefaultToolkit().sync();
- }
- if (displayCase==2){
- bufferGraphics.clearRect(0, 0, windowHeight, windowWidth);
- music.stop();
- bufferGraphics.clearRect(0, 0, windowHeight, windowWidth);
- g.drawImage(offscreen,0,0,this);
- try {
- highScoreTable.checkHighScore(score, name);
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- try{
- BufferedReader br = new BufferedReader(new FileReader("highscores"));
- String line;
- int reps = 0;
- while ((line = br.readLine()) != null) {
- bufferGraphics.drawString(br.readLine(), 15, 20*reps);
- reps++;
- }
- br.close();
- }
- catch (Exception e){
- System.err.println("Error: " + e.getMessage());
- }
- finally{}
- }
- if (displayCase==3){
- bufferGraphics.clearRect(0, 0, windowHeight, windowWidth);
- bufferGraphics.setColor(Color.green);
- bufferGraphics.fillRect(paddle.getX(),paddle.paddleY,70,10);
- bufferGraphics.setColor(Color.white);
- bufferGraphics.setFont(scoreFont);
- bufferGraphics.drawString("Score: "+Integer.toString(score)+" Lives: "+Integer.toString(lives), 15, windowWidth-15);
- for (int i = bricks.length-1; i >= 0; i--){
- for (int j = bricks[i].length-1; j >= 0; j--){
- if (bricks[i][j].getBroken()==false){
- bufferGraphics.setColor(brickColorsArray[i][j]);
- bufferGraphics.fillRect(bricks[i][j].getX(),bricks[i][j].getY(), 36, 15);
- }
- }
- }
- bufferGraphics.setColor(Color.red);
- bufferGraphics.fillOval(ball.getX(),ball.getY(),10,10);
- g.drawImage(offscreen,0,0,this);
- Toolkit.getDefaultToolkit().sync();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement