Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2008, 05:26 AM
Member
 
Join Date: May 2008
Posts: 1
aprenz is on a distinguished road
Double Buffering problem
My double buffering works through my IDE, but not in html. I would really appreciate any input.

Here's my code

Code:
import javax.swing.*; import java.applet.*; import java.awt.event.*; import java.awt.*; import java.awt.image.*; import java.util.*; class Brick { public int x,y; public Brick(int x,int y) {this.x = x;this.y = y;} } class Ball { public int x,y,a,b; public Ball(int x, int y) {this.x = x;this.y = y;} } public class Pong2 extends JApplet implements MouseListener, MouseMotionListener, Runnable, KeyListener { long tm = System.currentTimeMillis(); int delay; int a1=0,b1=0,c1=0,d1=0; int dead; int ranB1,ranB2; boolean pauseB = false; boolean starttext = true; int ani = 0; String stringWin; Graphics offscreen;Image image; private final int INIT_ACTIVE = 0; private final int INTRO_ACTIVE = 1; private final int GAME1_ACTIVE = 2; private final int GAME2_ACTIVE = 3; private final int GAME3_ACTIVE = 4; private int r1,r2,r3,r4,r5,starter=0,win=0,own=0; private int gameflag; private boolean player = true,moveB = true,thisB = true,timerB = true; private boolean drawB = true; private int counte=0; private int time = -2; private int movecheck1; int movecheck2;int movecheck3;int movecheck4; private int c; private int god = 0; private int tempx1, tempy1,tempx2,tempy2; private int pause = 2, resume = 0; private int ran, ran2,ran3,ran4; private int yCheck1,yCheck2,yCheck3,yCheck4,xCheck1,xCheck2,xCheck3,xCheck4; private int begin = 0; private int counter = 0, colorChange =0; private Brick brick[] = new Brick[4]; private Ball ball[] = new Ball[2]; private Ball ball2[] = new Ball[8]; private int cons1 = 0,cons2 = 0,cons3=0,cons4=0; private int score1=10, score2=10,score3=10,score4=10; private Thread t; private Font font; private AudioClip match,teleport,headshot, ballbounce, dkill,humiliation,one,two,three,fight,prepare; public Image paddle3,paddle4,rarrow,dbuffer,paddle,paddle2,bricks,blood,title,edge,m_imgOffScr; private Graphics dbuffer_gfx,m_gOffScr,dbg; private Color Color1 = new Color(255,255,255); private Color sColor3 = new Color(139,80,14); private Color sColor2 = new Color(0,255,0); private Color sColor4 = new Color(255,255,0); private Polygon poly1 = new Polygon();Polygon poly2 = new Polygon(); private Polygon poly3 = new Polygon();Polygon poly4 = new Polygon(); private boolean p1Dead=false, p2Dead=false, p3Dead=false, p4Dead=false; private int ranLoc, winner; public void initgame() { poly1.addPoint(0,0);poly1.addPoint(0,125);poly1.addPoint(125,0); poly2.addPoint(0,650);poly2.addPoint(125,650);poly2.addPoint(0,525); poly3.addPoint(650,0);poly3.addPoint(650,125);poly3.addPoint(525,0); poly4.addPoint(650,650);poly4.addPoint(650,525);poly4.addPoint(525,650); for (int j = 0; j < ball.length; j++){ball[j] = new Ball(325,325);} brick[0] = new Brick(25,285); brick[1] = new Brick(615,285); brick[2] = new Brick(285,25); brick[3] = new Brick(285,615); yCheck1 = brick[0].y; yCheck2 = brick[1].y; yCheck3 = brick[2].y; yCheck4 = brick[3].y; xCheck1 = brick[0].x; xCheck2 = brick[1].x; xCheck3 = brick[2].x; xCheck4 = brick[3].x; if(player) for (int n = 0; n<8; n++) { r1 = (int)(Math.random() * 600)+10;r2 = (int)(Math.random() * 600)+10; ball2[n] = new Ball(r1,r2); if (n == 0||n==4) {ball2[n].a = 3; ball2[n].b = 3;}if (n == 1||n==5) {ball2[n].a = -3; ball2[n].b = 3;} if (n == 2||n==6) {ball2[n].a = 3; ball2[n].b = -3;}if (n == 3||n==7) {ball2[n].a = -3; ball2[n].b = -3;} } player = false; } public void init() { gameflag = INIT_ACTIVE; setSize(650,725); requestFocus(); Font font = new Font ("Arial", Font.BOLD,50); paddle = getImage(getCodeBase(), "paddle.jpg"); paddle2 = getImage(getCodeBase(), "paddle2.jpg"); paddle3 = getImage(getCodeBase(), "paddle3.jpg"); paddle4 = getImage(getCodeBase(), "paddle4.jpg"); bricks = getImage(getCodeBase(), "bricks.jpg"); blood = getImage(getCodeBase(), "blood.jpg"); title = getImage(getCodeBase(), "title.jpg"); headshot = getAudioClip(getCodeBase(), "headshot2.wav"); ballbounce = getAudioClip(getCodeBase(), "ir_begin.wav"); humiliation = getAudioClip(getCodeBase(), "humiliation.wav"); prepare = getAudioClip(getCodeBase(), "prepare.wav"); teleport = getAudioClip(getCodeBase(), "teleport.wav"); match = getAudioClip(getCodeBase(), "matchwin.wav"); dbuffer=createImage(getSize().width,getSize().height); dbuffer_gfx=dbuffer.getGraphics(); initgame(); addMouseListener(this); addMouseMotionListener(this); addKeyListener(this); } public void start() { Thread t = new Thread(this); t.start(); new Thread(pMovement).start(); } public void stop() { t.yield(); t = null; } public void update (Graphics g) { paint(dbuffer_gfx); g.drawImage(dbuffer,0,0,this); } public void PaintIntro(Graphics g) { g.setColor(Color.white); g.fillRect(0,0,650,725); g.setColor(Color.black); for(int wa = 0;wa<8;wa++) g.fillOval(ball2[wa].x,ball2[wa].y,10,10); g.drawImage(title,100,100,this); g.setFont(new Font("Arial", Font.BOLD,20)); g.drawString("Written By Alec Parenzan",200,200); g.setFont(new Font("Arial", Font.BOLD,14)); if (colorChange==0)g.setColor(Color.blue); g.drawString("4 Player Game",275,430); g.setColor(Color.black); if (colorChange==1)g.setColor(Color.blue); g.drawString("2 Player Game",275,450); g.setColor(Color.black); if (colorChange==2)g.setColor(Color.blue); g.drawString("1 Player Game",275,470); } public void PaintGame1 (Graphics g) { g.setColor(Color.black); g.drawImage(blood,0,0,650,650,this); if(p1Dead==false && own>0 )g.drawImage(paddle3,brick[0].x,brick[0].y,10,80,this); if(p2Dead==false&& own>0)g.drawImage(paddle,brick[1].x,brick[1].y,10,80,this); if(p3Dead==false&& own>0)g.drawImage(paddle2,brick[2].x,brick[2].y,80,10,this); if(p4Dead==false&& own>0)g.drawImage(paddle4,brick[3].x,brick[3].y,80,10,this); g.fillPolygon(poly1);g.fillPolygon(poly2);g.fillPolygon(poly3);g.fillPolygon(poly4); g.setColor(Color.white); g.drawPolygon(poly1);g.drawPolygon(poly2);g.drawPolygon(poly3);g.drawPolygon(poly4); g.setColor(Color.black); if(begin==1 && drawB) {g.fillOval(ball[0].x,ball[0].y,10,10);g.fillOval(ball[1].x,ball[1].y,10,10);} g.drawImage(bricks,1,650,650,75,this); //score g.setFont(new Font("Comic Sans MS", Font.ITALIC,50)); if(own>0){ g.setColor(sColor2);g.drawString(Integer.toString(score1),50,705); g.setColor(Color.orange);g.drawString(Integer.toString(score2),150,705); g.setColor(Color.blue);g.drawString(Integer.toString(score3),440,705); g.setColor(sColor3);g.drawString(Integer.toString(score4),540,705);} //painting gui if (starttext) {g.setColor(Color.black); g.setFont(new Font("Arial", Font.ITALIC,30));g.drawString("Click START to Begin",175,325);} g.setColor(Color1); g.setFont(new Font("Arial", Font.BOLD,30)); if(pause ==1 && begin>0)g.drawString("RESUME",270,700); else if(begin==0)g.drawString("START",270,700); else if(begin>=1 && begin<=2 && pause==0){g.drawString("PAUSE",270,700);} //start g.setFont(font);g.setColor(Color.black); if(win ==1){if(winner==1)g.setColor(Color.green);else if(winner==2)g.setColor(Color.orange); else if(winner==3)g.setColor(Color.blue);else if(winner==4)g.setColor(sColor3); g.drawString(stringWin,245,325);} g.setColor(Color.black); if (time == 1)g.drawString("3",300,325); else if (time==2)g.drawString("2",300,325); else if (time==3)g.drawString("1",300,325); } public void PaintGame2(Graphics g) { g.setColor(Color.black); g.drawImage(blood,0,0,650,650,this); if(p1Dead==false && own>0 )g.drawImage(paddle3,brick[0].x,brick[0].y,10,80,this); if(p2Dead==false&& own>0)g.drawImage(paddle,brick[1].x,brick[1].y,10,80,this); g.fillPolygon(poly1);g.fillPolygon(poly2);g.fillPolygon(poly3);g.fillPolygon(poly4); g.setColor(Color.white); g.drawPolygon(poly1);g.drawPolygon(poly2);g.drawPolygon(poly3);g.drawPolygon(poly4); g.setColor(Color.black); if(begin==1 && drawB) {g.fillOval(ball[0].x,ball[0].y,10,10);g.fillOval(ball[1].x,ball[1].y,10,10);} g.drawImage(bricks,1,650,650,75,this); //score g.setFont(new Font("Comic Sans MS", Font.ITALIC,50)); if(own>0){ g.setColor(sColor2);g.drawString(Integer.toString(score1),50,705); g.setColor(Color.orange);g.drawString(Integer.toString(score2),540,705);} //painting gui if (starttext) {g.setColor(Color.black); g.setFont(new Font("Arial", Font.ITALIC,30));g.drawString("Click START to Begin",175,325);} g.setColor(Color1); g.setFont(new Font("Arial", Font.BOLD,30)); if(pause ==1 && begin>0)g.drawString("RESUME",270,700); else if(begin==0)g.drawString("START",270,700); else if(begin>=1 && begin<=2 && pause==0){g.drawString("PAUSE",270,700);} //start g.setFont(font);g.setColor(Color.black); if(win ==1){if(winner==1)g.setColor(Color.green);else if(winner==2)g.setColor(Color.orange);} g.setColor(Color.black); if (time == 1)g.drawString("3",300,325); else if (time==2)g.drawString("2",300,325); else if (time==3)g.drawString("1",300,325); } //paint graphics public void paint(Graphics g) { g.setColor(Color.WHITE); g.fillRect(0,0,500,500); g.setColor(Color.BLACK); if (gameflag == INIT_ACTIVE) { g.setColor(Color.black); g.fillRect(0,0,getSize().width,getSize().height); g.setColor(Color.white); g.drawString("Loading...",getSize().width/2, getSize().height/2); } if (gameflag == INTRO_ACTIVE){PaintIntro(g);} if (gameflag == GAME1_ACTIVE){PaintGame1(g);} if (gameflag == GAME2_ACTIVE || gameflag == GAME3_ACTIVE){PaintGame2(g);} } public void paddlephys() { for(int j =0; j < 2;j++) { //P1 if(p1Dead==false&&ball[j].x-4<=xCheck1 && ball[j].x<=xCheck2 && begin==1) { if (ball[j].y>=yCheck1&&ball[j].y<=yCheck1+12) {ball[j].a=2;ball[j].b=-4;ballbounce.play();} else if (ball[j].y>=yCheck1+13&&ball[j].y<=yCheck1+25) {ball[j].a=3;ball[j].b=-3;ballbounce.play();} else if (ball[j].y>=yCheck1+26&&ball[j].y<=yCheck1+39) {ball[j].a=4;ball[j].b=-2;ballbounce.play();} else if (ball[j].y>=yCheck1+40&&ball[j].y<=yCheck1+53) {ball[j].a=4;ball[j].b=2;ballbounce.play();} else if (ball[j].y>=yCheck1+54&&ball[j].y<=yCheck1+66) {ball[j].a=3;ball[j].b=3;ballbounce.play();} else if (ball[j].y>=yCheck1+67&&ball[j].y<=yCheck1+79) {ball[j].a=2;ball[j].b=4;ballbounce.play();} } //P2 if(p2Dead==false&&ball[j].x>=xCheck2 && ball[j].x<=xCheck2+5 && begin==1) { if (ball[j].y>=yCheck2&&ball[j].y<=yCheck2+12) {ball[j].a=-2;ball[j].b=-4;ballbounce.play();} else if (ball[j].y>=yCheck2+13&&ball[j].y<=yCheck2+25) {ball[j].a=-3;ball[j].b=-3;ballbounce.play();} else if (ball[j].y>=yCheck2+26&&ball[j].y<=yCheck2+39) {ball[j].a=-4;ball[j].b=-2;ballbounce.play();} else if (ball[j].y>=yCheck2+40&&ball[j].y<=yCheck2+53) {ball[j].a=-4;ball[j].b=2;ballbounce.play();} else if (ball[j].y>=yCheck2+54&&ball[j].y<=yCheck2+66) {ball[j].a=-3;ball[j].b=3;ballbounce.play();} else if (ball[j].y>=yCheck2+67&&ball[j].y<=yCheck2+79) {ball[j].a=-2;ball[j].b=4;ballbounce.play();} } //P3 if(p3Dead==false&&ball[j].y>=yCheck3-5 && ball[j].y<=yCheck3 && begin==1) { if (ball[j].x>=xCheck3&&ball[j].x<=xCheck3+12) {ball[j].a=-4;ball[j].b=2;ballbounce.play();} else if (ball[j].x>=xCheck3+13&&ball[j].x<=xCheck3+25) {ball[j].a=-3;ball[j].b=3;ballbounce.play();} else if (ball[j].x>=xCheck3+26&&ball[j].x<=xCheck3+39) {ball[j].a=-2;ball[j].b=4;ballbounce.play();} else if (ball[j].x>=xCheck3+40&&ball[j].x<=xCheck3+53) {ball[j].a=2;ball[j].b=4;ballbounce.play();} else if (ball[j].x>=xCheck3+54&&ball[j].x<=xCheck3+66) {ball[j].a=3;ball[j].b=3;ballbounce.play();} else if (ball[j].x>=xCheck3+67&&ball[j].x<=xCheck3+79) {ball[j].a=4;ball[j].b=2;ballbounce.play();} } //P4 if(p4Dead==false&&ball[j].y>=yCheck4 && ball[j].y<=yCheck4+5 && begin==1) { if (ball[j].x>=xCheck4&&ball[j].x<=xCheck4+12) {ball[j].a=-4;ball[j].b=-2;ballbounce.play();} else if (ball[j].x>=xCheck4+13&&ball[j].x<=xCheck4+25) {ball[j].a=-3;ball[j].b=-3;ballbounce.play();} else if (ball[j].x>=xCheck4+26&&ball[j].x<=xCheck4+39) {ball[j].a=-2;ball[j].b=-4;ballbounce.play();} else if (ball[j].x>=xCheck4+40&&ball[j].x<=xCheck4+53) {ball[j].a=2;ball[j].b=-4;ballbounce.play();} else if (ball[j].x>=xCheck4+54&&ball[j].x<=xCheck4+66) {ball[j].a=3;ball[j].b=-3;ballbounce.play();} else if (ball[j].x>=xCheck4+67&&ball[j].x<=xCheck4+79) {ball[j].a=4;ball[j].b=-2;ballbounce.play();} } } } Runnable pMovement = new Runnable() { public void run() { while(moveB) { if(pauseB==false){ if (brick[0].y == 445) brick[0].y-=2; if (brick[0].y == 125) brick[0].y+=2; if (brick[0].y<445&&brick[0].y>125){if (movecheck1==1){brick[0].y-=1;yCheck1 = brick[0].y;} else if (movecheck1==-1){brick[0].y+=1;yCheck1 = brick[0].y;} } if (brick[1].y == 445) brick[1].y-=2; if (brick[1].y == 125) brick[1].y+=2; if (brick[1].y<445&&brick[1].y>125){if (movecheck2==1){brick[1].y-=1;yCheck2 = brick[1].y;} else if (movecheck2==-1){brick[1].y+=1;yCheck2 = brick[1].y;} } if (brick[2].x == 445) brick[2].x-=2; if (brick[2].x == 125) brick[2].x+=2; if (brick[2].x<570&&brick[2].x>125){if (movecheck3==1){brick[2].x-=1;xCheck3 = brick[2].x;} else if (movecheck3==-1){brick[2].x+=1;xCheck3 = brick[2].x;} } if (brick[3].x == 445) brick[3].x-=2; if (brick[3].x == 125) brick[3].x+=2; if (brick[3].x<570&&brick[3].x>0){if (movecheck4==1){brick[3].x-=1;xCheck4 = brick[3].x;} else if (movecheck4==-1){brick[3].x+=1;xCheck4 = brick[3].x;} } starter(); try{Thread.sleep(2,500);}catch(InterruptedException e){} } } if(pauseB){try{Thread.sleep(2,500);}catch(InterruptedException e){}} } }; public void starter() { if(starter==1) { if(gameflag==2){p1Dead=false; p2Dead=false; p3Dead=false; p4Dead=false;} if(gameflag==3 || gameflag==4){p3Dead=true;p4Dead=true;} a1=0;b1=0;c1=0;d1=0;drawB=true; starttext = false; win=0; score1=10;score2=10;score3=10;score4=10; if(gameflag==3 || gameflag==4){score3=0;score4=0;} own=1; prepare.play(); try{Thread.sleep(5000);}catch(InterruptedException e){} time=1; try{Thread.sleep(1000);}catch(InterruptedException e){} time=2; try{Thread.sleep(1000);}catch(InterruptedException e){} time=3; try{Thread.sleep(1000);}catch(InterruptedException e){} if(gameflag==2) { ball[0].a=2;ball[0].b=0; ball[1].a=0;ball[1].b=-2; } if(gameflag==3 || gameflag==4) { ball[0].a=2;ball[0].b=0; ball[1].a=-2;ball[1].b=0; } ball[0].x = 325; ball[0].y = 325;ball[1].x = 325; ball[1].y = 325; pause=0;time=-5;starter=0;begin=1; } } public void run() { while(thisB) { if(pauseB==false) switch(gameflag) { case INIT_ACTIVE: { repaint(); gameflag = INTRO_ACTIVE; try{Thread.sleep(10);} catch(InterruptedException ex){break;} break; } case INTRO_ACTIVE: { physicsintro(); try{Thread.sleep(10);} catch(InterruptedException ex){break;} for(int w = 0;w<8;w++){ball2[w].x+=ball2[w].a;ball2[w].y+=ball2[w].b;} repaint(); break; } case GAME1_ACTIVE: { if(countDead())resetter(); boundaries(); paddlephys(); for(int w = 0;w<2;w++){ball[w].x+=ball[w].a;ball[w].y+=ball[w].b;} try{Thread.sleep(7,500);}catch(InterruptedException e){break;} repaint(); } case GAME2_ACTIVE: { if(countDead())resetter(); boundaries(); paddlephys(); for(int w = 0;w<2;w++){ball[w].x+=ball[w].a;ball[w].y+=ball[w].b;} try{Thread.sleep(7,500);}catch(InterruptedException e){break;} repaint(); } case GAME3_ACTIVE: { if(countDead())resetter(); boundaries(); paddlephys(); for(int w = 0;w<2;w++){ball[w].x+=ball[w].a;ball[w].y+=ball[w].b;} try{Thread.sleep(7,500);}catch(InterruptedException e){break;} repaint(); } } if(pauseB==true){repaint();try{Thread.sleep(7,500);}catch(InterruptedException e){}} } } public void boundaries() { for(int z = 0; z<2;z++) { ranB1 = (int)(Math.random() * 4); //P1 scores if(p1Dead==false && ball[z].y<525 && ball[z].y>125 && ball[z].x<2) { if(score1==1)humiliation.play(); else headshot.play(); score1--;cons1++; ball[z].y=325;ball[z].x=325; if(ranB1==0){ball[z].a=1;ball[z].b=1;}else if(ranB1==1){ball[z].a=-1;ball[z].b=1;} else if(ranB1==2){ball[z].a=1;ball[z].b=-1;}else if(ranB1==3){ball[z].a=-1;ball[z].b=-1;} if(score1 == 0)p1Dead=true; } //P2 scores else if(p2Dead==false&& ball[z].y<525 && ball[z].y>125 && ball[z].x>648) { if(score2==1)humiliation.play(); else headshot.play(); score2--;cons2++; ball[z].y = 325;ball[z].x=325; if(ranB1==0){ball[z].a=1;ball[z].b=1;}else if(ranB1==1){ball[z].a=-1;ball[z].b=1;} else if(ranB1==2){ball[z].a=1;ball[z].b=-1;}else if(ranB1==3){ball[z].a=-1;ball[z].b=-1;} if(score2 == 0)p2Dead=true; } //P3 scores else if(p3Dead==false&&ball[z].x<525 && ball[z].x>125 && ball[z].y<2) { if(score3==1)humiliation.play(); else headshot.play(); score3--;cons3++; ball[z].y = 325; ball[z].x = 325; if(ranB1==0){ball[z].a=1;ball[z].b=1;}else if(ranB1==1){ball[z].a=-1;ball[z].b=1;} else if(ranB1==2){ball[z].a=1;ball[z].b=-1;}else if(ranB1==3){ball[z].a=-1;ball[z].b=-1;} if(score3 == 0)p3Dead=true; } //P4 Scores else if(p4Dead==false&&ball[z].x<525 && ball[z].x>125 && ball[z].y>648) { if(score4==1)humiliation.play(); else headshot.play(); score4--;cons4++; ball[z].y = 325; ball[z].x = 325; if(ranB1==0){ball[z].a=1;ball[z].b=1;}else if(ranB1==1){ball[z].a=-1;ball[z].b=1;} else if(ranB1==2){ball[z].a=1;ball[z].b=-1;}else if(ranB1==3){ball[z].a=-1;ball[z].b=-1;} if(score4 == 0)p4Dead=true; } if((p1Dead==true && ball[z].y<525 && ball[z].y>125 && ball[z].x<2) || (gameflag==3 || gameflag == 4)) { ballbounce.play();ball[z].a*=-1; } else if((p2Dead==true && ball[z].y<525 && ball[z].y>125 && ball[z].x>648) || (gameflag==3 || gameflag == 4)) { ballbounce.play();ball[z].a*=-1; } else if((p3Dead==true &&ball[z].x<525 && ball[z].x>125 && ball[z].y<2) || (gameflag==3 || gameflag == 4)) { ballbounce.play();ball[z].b*=-1; } else if((p4Dead==true &&ball[z].x<525 && ball[z].x>125 && ball[z].y>648) || (gameflag==3 || gameflag == 4)) { ballbounce.play();ball[z].b*=-1; } if(poly1.contains(ball[z].x,ball[z].y)) { ballbounce.play(); if(ranB1 == 0){ball[z].a=1;ball[z].b=5;}else if(ranB1 == 1){ball[z].a=2;ball[z].b=4;} else if(ranB1 == 2){ball[z].a=5;ball[z].b=1;}else if(ranB1 == 3){ball[z].a=4;ball[z].b=2;} } else if(poly2.contains(ball[z].x,ball[z].y)) { ballbounce.play(); if(ranB1 == 0){ball[z].a=1;ball[z].b=-5;}else if(ranB1 == 1){ball[z].a=2;ball[z].b=-4;} else if(ranB1 == 2){ball[z].a=5;ball[z].b=-1;}else if(ranB1 == 3){ball[z].a=4;ball[z].b=-2;} } else if(poly3.contains(ball[z].x,ball[z].y)) { ballbounce.play(); if(ranB1 == 0){ball[z].a=-1;ball[z].b=5;}else if(ranB1 == 1){ball[z].a=-2;ball[z].b=4;} else if(ranB1 == 2){ball[z].a=-5;ball[z].b=1;}else if(ranB1 == 3){ball[z].a=-4;ball[z].b=2;} } else if(poly4.contains(ball[z].x,ball[z].y)) { ballbounce.play(); if(ranB1 == 0){ball[z].a=-1;ball[z].b=-5;}else if(ranB1 == 1){ball[z].a=-2;ball[z].b=-4;} else if(ranB1 == 2){ball[z].a=-5;ball[z].b=-1;}else if(ranB1 == 3){ball[z].a=-4;ball[z].b=-2;} } } } public void resetter() { brick[0].x=25;brick[0].y=285;brick[1].x=615;brick[1].y=285;brick[2].x=285;brick[2].y=25;brick[3].x=285;brick[3].y=615; if(p4Dead==true && p3Dead==true && p2Dead==true && p1Dead==false){ball[0].x = 325;ball[0].y = 325;ball[1].x = 325;ball[1].y = 325; ball[0].a=0;ball[0].b=0;ball[1].a=0;ball[1].b=0;drawB=false;match.play();pause=5;p1Dead=true;begin=0;win=1;winner=1;stringWin="Player 1 Wins";} else if(p4Dead==true && p3Dead==true && p2Dead==false && p1Dead==true){ball[0].x = 325;ball[0].y = 325;ball[1].x = 325;ball[1].y = 325; ball[0].a=0;ball[0].b=0;ball[1].a=0;ball[1].b=0;drawB=false;match.play();pause=5;p2Dead=true;begin=0;win=1;winner=2;stringWin="Player 2 Wins";} else if(p4Dead==true && p3Dead==false && p2Dead==true && p1Dead==true){ball[0].x = 325;ball[0].y = 325;ball[1].x = 325;ball[1].y = 325; ball[0].a=0;ball[0].b=0;ball[1].a=0;ball[1].b=0;drawB=false;match.play();pause=5;p3Dead=true;begin=0;win=1;winner=3;stringWin="Player 3 Wins";} else if(p4Dead==false && p3Dead==true && p2Dead==true && p1Dead==true){ball[0].x = 325;ball[0].y = 325;ball[1].x = 325;ball[1].y = 325; ball[0].a=0;ball[0].b=0;ball[1].a=0;ball[1].b=0;drawB=false;match.play();pause=5;p4Dead=true;begin=0;win=1;winner=4;stringWin="Player 4 Wins";} } public boolean countDead() { if(gameflag==2) { if(p4Dead==true)a1=1;if(p3Dead==true)b1=1;if(p2Dead==true)c1=1;if(p1Dead==true)d1=1; dead = a1 + b1 + c1 + d1; if(dead>2)return true; else return false; } if(gameflag==3 || gameflag==4) { if(p2Dead==true)c1=1;if(p1Dead==true)d1=1; dead = c1 + d1; if(dead==1) return true; else return false; } return false; } public void physicsintro() { for(int aw = 0;aw<8;aw++) { if(ball2[aw].x >645 || ball2[aw].x < 5)ball2[aw].a *= -1; if(ball2[aw].y > 720 || ball2[aw].y <5)ball2[aw].b *= -1; } } public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mousePressed(MouseEvent e){} public void mouseClicked(MouseEvent e) { // resume if(pause==1 && e.getX()>=270 && e.getX()<= 360 && e.getY()>=650) { pauseB=false;pause=0; } // pause else if(pause==0 && e.getX()>=270 && e.getX()<= 360 && e.getY()>=650) { pauseB=true;pause=1; } //start else if(begin == 0 && e.getX()>=270 && e.getX()<= 360 && e.getY()>=650) { starter = 1; } } public void mouseMoved(MouseEvent e) { //gui light up if(e.getX()>=270 && e.getX()<= 360 && e.getY()>=650){Color1 = new Color(255,255,255);} else{Color1 = new Color(0,0,0);} repaint(); } public void mouseDragged(MouseEvent e){} public void keyTyped(KeyEvent e){} public void keyPressed(KeyEvent e) { c = e.getKeyCode(); if(gameflag==2 || gameflag==3) switch(c) { case KeyEvent.VK_1: movecheck1 = 1;break; case KeyEvent.VK_2: movecheck1 = -1;break; case KeyEvent.VK_V: movecheck2 = 1;break; case KeyEvent.VK_B: movecheck2 = -1;break; case KeyEvent.VK_K: movecheck3 = 1;break; case KeyEvent.VK_L: movecheck3 = -1;break; case KeyEvent.VK_LEFT: movecheck4 = 1;break; case KeyEvent.VK_DOWN: movecheck4 = -1;break; } if(gameflag==1) switch(c) { case KeyEvent.VK_UP: if(colorChange==0)colorChange=2; else if(colorChange==1)colorChange=0; else if(colorChange==2)colorChange=1;break; case KeyEvent.VK_DOWN: if(colorChange==0)colorChange=1; else if(colorChange==1)colorChange=2; else if(colorChange==2)colorChange=0;break; case KeyEvent.VK_ENTER: if(colorChange==0)gameflag=2; if(colorChange==1)gameflag=3; if(colorChange==2)gameflag=4; break; } } public void keyReleased(KeyEvent e) { c = e.getKeyCode(); if (gameflag==2 || gameflag==3) switch(c) { case KeyEvent.VK_1: movecheck1 = 0;break; case KeyEvent.VK_2: movecheck1 = 0;break; case KeyEvent.VK_V: movecheck2 = 0;break; case KeyEvent.VK_B: movecheck2 = 0;break; case KeyEvent.VK_K: movecheck3 = 0;break; case KeyEvent.VK_L: movecheck3 = 0;break; case KeyEvent.VK_LEFT: movecheck4 = 0;break; case KeyEvent.VK_DOWN: movecheck4 = 0;break; } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating sin of a double value Java Tip Java Tips 0 01-13-2008 09:13 PM
transforming double to int AlejandroPenton New To Java 2 12-11-2007 02:34 AM
Getting smallest possible Double value Java Tip Java Tips 0 12-06-2007 03:15 PM
Arc2D.Double coordinates alley Java 2D 2 11-07-2007 11:27 PM
How to round a double? Valeriano New To Java 1 05-31-2007 04:50 PM


All times are GMT +3. The time now is 10:48 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org