Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

java game on eclipse HELP!

Started by timmyk Oct 28, 2005 at 7:36 AM 2 replies 550+ views
Original Post
timmyk
timmyk
im making a java game on eclipse and i want to know how to get the shooting bullet to stop as soon as it hits an object(eg rock). i have posted my code: /* * Created on 13/10/2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code style - Code Templates */ /** * @author kusatim * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code style - Code Templates */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Tag_eg { public JFrame front, instruction, character, weapon, location, option, gamescreen, Controls; public JPanel Ft, Fm, Fb, It, Im, Ib, Ct, Cm, Cb, Cr, Cl, Wt, Wm, Wb, Wr, Wl, Lt, Lml, Lmm, Lmr, Lb, Lr, Ll, Ot, Om, Ob, Or, Ol, Gtop, Ctop, Cmiddle, Cbottom; public JLabel Ftopl, Fpic, Fintro, FLab, Ipic, Itopl, Ctopl, Wtopl, Ltopl, Otopl, Cteam1, Cteam2, Cname1, Cname2, Ct1is, Ct2is, Omusic, Oround, Otcol1, Otcol2, Iobjective, OmL1, OmL2, OmL3, OmL4, p1pic, p2pic, p3pic, p4pic, space, space1, Wep1, Wep2, Wep3, Wep4, wep1, wep2, wep3, wep4, wep1pic, wep2pic, wep3pic, wep4pic, Loc1pic, Loc2pic, Loc3pic, Loc4pic, Loc5pic, Cp1, Cp2, Cp3, Cp4, Cp5, Cp6, Cp7, Cp8, player1, player2, player3, player4, Loc1, Loc1p, MusicL, RoundL, Color1L, Color2L, control, Ctopc, Ccomand; public JButton Fplay, Finstruct, Fexit, Iback, Cok, Cok2, Ccont, Wback, Wcont, Lback, Lcont, Oback, Obegin, resume, quit1, Mon, Moff, R1, R3, R5, red, black, blue, green, orange, red1, black1, blue1, green1, orange1, p1, p2, p3, p4, g1, g2, g3, g4, g5, stg1, stg2, stg3, stg4, stg5, Wep1ok, CBut, CBack; public JTextField Ctxtentr1, Ctxtentr2, Ctxtis1, Ctxtis2, Gvstxt, Cp1tf, Cp2tf, Cp3tf, Cp4tf, p1txt, p2txt; public JDialog pause, quit; public int x = 20, y = 400, x1 = 900, y1 = 150, x2 = 20, y2 = 150, x3 = 900, y3 = 400, j = 0, a = 0, b = 0, cc = 0, d = 0, r = 0, b1 = 0, b2 = 0, xr = 400, yr = 400, base1x = 0, base1y = 250, base2x = 940, base2y = 250, e=500, f=500, w=0, e2 = 500, f2 = 500, gunchoice=0, gunx=20, guny=400, gunx1=900, guny1=150; public boolean goWpn = false, goWpn2 = false, imagepic = false, imagepic2 = false, fire1 = false, hitman = false, gamepanel = true, fire2=false, die=false; public ImagePanel lev1, lev2, lev3, lev4, lev5; public Image[] alex, timmy, ben, pye, Player1, Player2, Player3, Player4, rock, base1, base2; public Image backgroundImage1, backgroundImage2, backgroundImage3, backgroundImage4, backgroundImage5, base1red, base1black, base1blue, base1green, base1orange, base2red, base2black, base2blue, base2green, base2orange; public GridBagConstraints c; Image[] PlaceHolders, player, texture, opposition; public int [] z = {0,0,0}; public String team, team1, team2; public Image shoot, shoot1, playerHIT, playerHIT1; public Shoot [] gun = new Shoot [1000]; public Shoot1 [] gun1 = new Shoot1 [1000]; public boolean [] manshoot = new boolean [1000]; public boolean [] manshoot1 = new boolean [1000]; class ImagePanel extends JPanel { public ImagePanel() { } public void paintComponent(Graphics g) { // paint background super.paintComponent(g); // paint image in foreground. MediaTracker mt; mt = new MediaTracker(this); g.drawImage(backgroundImage1, 0, 0, this); //Create the four players. g.drawImage(rock[r], xr, yr, this); g.drawImage(base1[b1], base1x, base1y, this); g.drawImage(base2[b2], base2x, base2y, this); g.drawImage(alex[a], x, y, this); g.drawImage(timmy, x1, y1, this); if (die==false){ g.drawImage(ben[cc], x2, y2, this); } if (die==true){ g.drawImage(playerHIT, x2, y2, this); } // to get player to start from starting point when shot;x2=20(original int) if (die==false){ g.drawImage(pye[d], x3, y3, this); } if (die==true){ g.drawImage(playerHIT1, x3, y3, this); } for (int i=0; i<1000; i++){ if (manshoot==true){ g.drawImage(shoot, gun.gun_x, gun.gun_y, this); } } for (int i=0; i<1000; i++){ if (manshoot1==true){ g.drawImage(shoot1, gun1.gun_x1, gun1.gun_y1, this); } } } } public Tag_eg() { player = new Image[3]; player [0] = Toolkit.getDefaultToolkit().getImage("alex1.png"); player [1] = Toolkit.getDefaultToolkit().getImage("alex1.png"); player [2] = Toolkit.getDefaultToolkit().getImage("alex1.png"); shoot = Toolkit.getDefaultToolkit().getImage("bullet11.png"); shoot1 = Toolkit.getDefaultToolkit().getImage("bullet51.png"); playerHIT = Toolkit.getDefaultToolkit().getImage("boom.gif"); playerHIT1 = Toolkit.getDefaultToolkit().getImage("boom1.gif"); c = new GridBagConstraints(); team = new String(""); team1 = new String(""); team2 = new String(""); PlaceHolders = new Image[4]; PlaceHolders[0] = Toolkit.getDefaultToolkit().getImage(""); PlaceHolders[1] = Toolkit.getDefaultToolkit().getImage(""); PlaceHolders[2] = Toolkit.getDefaultToolkit().getImage(""); PlaceHolders[3] = Toolkit.getDefaultToolkit().getImage(""); lev1 = new ImagePanel(); lev2 = new ImagePanel(); lev3 = new ImagePanel(); lev4 = new ImagePanel(); lev5 = new ImagePanel(); Player1 = new Image[1]; Player1[0] = Toolkit.getDefaultToolkit().getImage(""); Player2 = new Image[1]; Player2[0] = Toolkit.getDefaultToolkit().getImage(""); Player3 = new Image[1]; Player3[0] = Toolkit.getDefaultToolkit().getImage(""); Player4 = new Image[1]; Player4[0] = Toolkit.getDefaultToolkit().getImage(""); alex = new Image[5]; alex[1] = Toolkit.getDefaultToolkit().getImage("alex1.png"); alex[2] = Toolkit.getDefaultToolkit().getImage("alex2.png"); alex[3] = Toolkit.getDefaultToolkit().getImage("alex3.png"); alex[4] = Toolkit.getDefaultToolkit().getImage("alex4.png"); alex[0] = Toolkit.getDefaultToolkit().getImage(""); timmy = new Image[5]; timmy[1] = Toolkit.getDefaultToolkit().getImage("timmy1.png"); timmy[2] = Toolkit.getDefaultToolkit().getImage("timmy2.png"); timmy[3] = Toolkit.getDefaultToolkit().getImage("timmy3.png"); timmy[4] = Toolkit.getDefaultToolkit().getImage("timmy4.png"); timmy[0] = Toolkit.getDefaultToolkit().getImage(""); ben = new Image[5]; ben[1] = Toolkit.getDefaultToolkit().getImage("ben1.png"); ben[2] = Toolkit.getDefaultToolkit().getImage("ben2.png"); ben[3] = Toolkit.getDefaultToolkit().getImage("ben3.png"); ben[4] = Toolkit.getDefaultToolkit().getImage("ben4.png"); ben[0] = Toolkit.getDefaultToolkit().getImage(""); pye = new Image[5]; pye[1] = Toolkit.getDefaultToolkit().getImage("pye1.png"); pye[2] = Toolkit.getDefaultToolkit().getImage("pye2.png"); pye[3] = Toolkit.getDefaultToolkit().getImage("pye3.png"); pye[4] = Toolkit.getDefaultToolkit().getImage("pye4.png"); pye[0] = Toolkit.getDefaultToolkit().getImage(""); rock = new Image[1]; rock[0] = Toolkit.getDefaultToolkit().getImage("rock1.png"); base1 = new Image[5]; base1 [0]= Toolkit.getDefaultToolkit().getImage("base1red.png"); base1 [1]= Toolkit.getDefaultToolkit().getImage("base1black.png"); base1 [2]= Toolkit.getDefaultToolkit().getImage("base1blue.png"); base1 [3]= Toolkit.getDefaultToolkit().getImage("base1green.png"); base1 [4]= Toolkit.getDefaultToolkit().getImage("base1orange.png"); base2 = new Image[5]; base2 [0]= Toolkit.getDefaultToolkit().getImage("base2red.png"); base2 [1]= Toolkit.getDefaultToolkit().getImage("base2black.png"); base2 [2]= Toolkit.getDefaultToolkit().getImage("base2blue.png"); base2 [3]= Toolkit.getDefaultToolkit().getImage("base2green.png"); base2 [4]= Toolkit.getDefaultToolkit().getImage("base2orange.png"); backgroundImage1 = Toolkit.getDefaultToolkit().getImage("space1.jpg"); backgroundImage2 = Toolkit.getDefaultToolkit().getImage("desert1.jpg"); backgroundImage3 = Toolkit.getDefaultToolkit().getImage("ocean1.jpg"); backgroundImage4 = Toolkit.getDefaultToolkit().getImage("fire1.jpg"); backgroundImage5 = Toolkit.getDefaultToolkit().getImage("woods1.jpg"); //FRAMES front = new JFrame("CAPTURE THE FLAG"); this.front.setUndecorated(true); instruction = new JFrame("INSTRUCTIONS"); this.instruction.setUndecorated(true); Controls = new JFrame("CONTROLS"); this.Controls.setUndecorated(true); character = new JFrame("CHARACTER SELECT"); this.character.setUndecorated(true); weapon = new JFrame("WEAPON SELECT"); this.weapon.setUndecorated(true); location = new JFrame("LOCATION SELECT"); this.location.setUndecorated(true); option = new JFrame("OTHER OPTIONS"); this.option.setUndecorated(true); gamescreen = new JFrame("CAPTURE THE FLAG"); this.gamescreen.setUndecorated(true); pause = new JDialog(front, "PAUSE", true); quit = new JDialog(front, "QUIT", true); //PANELS Ft = new JPanel(); Fm = new JPanel(); Fb = new JPanel(); It = new JPanel(); Im = new JPanel(); Ib = new JPanel(); Ct = new JPanel(); Cm = new JPanel(); Cb = new JPanel(); Cr = new JPanel(); Cl = new JPanel(); Wt = new JPanel(); Wm = new JPanel(); Wb = new JPanel(); Wr = new JPanel(); Wl = new JPanel(); Lt = new JPanel(); Lb = new JPanel(); Lml = new JPanel(); Lmm = new JPanel(); Lmr = new JPanel(); Lr = new JPanel(); Ll = new JPanel(); Ot = new JPanel(); Om = new JPanel(); Ob = new JPanel(); Or = new JPanel(); Ol = new JPanel(); Gtop = new JPanel(); Ctop = new JPanel(); Cmiddle = new JPanel(); Cbottom = new JPanel(); //LABELS Ccomand = new JLabel(" ", SwingConstants.CENTER); Cname1 = new JLabel("", SwingConstants.CENTER); Cname2 = new JLabel("", SwingConstants.CENTER); wep1=new JLabel("", SwingConstants.CENTER); wep1pic=new JLabel("", SwingConstants.CENTER); wep2=new JLabel("", SwingConstants.CENTER); wep2.setVisible(false); wep2pic=new JLabel("", SwingConstants.CENTER); wep3=new JLabel("", SwingConstants.CENTER); wep3.setVisible(false); wep3pic=new JLabel("", SwingConstants.CENTER); wep4=new JLabel("", SwingConstants.CENTER); wep4.setVisible(false); wep4pic = new JLabel("", SwingConstants.CENTER); p1pic = new JLabel(""); p2pic = new JLabel(""); p3pic = new JLabel(""); p4pic = new JLabel(""); Ftopl = new JLabel(""); FLab = new JLabel("The Game of the Future", SwingConstants.CENTER); FLab.setFont(new Font("Times new roman", Font.PLAIN, 35)); Fintro = new JLabel(new ImageIcon("intro.jpg")); Cp1 = new JLabel(); Cp2 = new JLabel(); Cp3 = new JLabel(); Cp4 = new JLabel(); MusicL = new JLabel("", SwingConstants.CENTER); RoundL = new JLabel("", SwingConstants.CENTER); Color1L = new JLabel("", SwingConstants.CENTER); Color2L = new JLabel("", SwingConstants.CENTER); Wep1=new JLabel("", SwingConstants.RIGHT); Wep2=new JLabel("", SwingConstants.RIGHT); Wep3=new JLabel("", SwingConstants.RIGHT); Wep4=new JLabel("", SwingConstants.RIGHT); Loc1 = new JLabel("", SwingConstants.CENTER); Loc1.setFont(new Font("Times new roman", Font.PLAIN, 18)); Loc1p = new JLabel("", SwingConstants.CENTER); Itopl = new JLabel("INSTRUCTIONS"); Itopl.setFont(new Font("Tahoma", Font.PLAIN, 28)); Ctopc = new JLabel("CONTROLS"); Ctopc.setFont(new Font("Tahoma", Font.PLAIN, 28)); Ctopl = new JLabel("CHARACTER SELECT"); Ctopl.setFont(new Font("Stencil", Font.PLAIN, 20)); Wtopl = new JLabel("WEAPON SELECT"); Wtopl.setFont(new Font("Stencil", Font.PLAIN, 20)); Ltopl = new JLabel("LOCATION SELECT"); Ltopl.setFont(new Font("Stencil", Font.PLAIN, 20)); Otopl = new JLabel("OTHER OPTIONS"); Otopl.setFont(new Font("Stencil", Font.PLAIN, 20)); Cteam1 = new JLabel("ENTER TEAM 1 NAME BELOW", SwingConstants.CENTER); Cteam2 = new JLabel("ENTER TEAM 2 NAME BELOW", SwingConstants.CENTER); Ct1is = new JLabel("TEAM 1 IS CALLED:"); Ct2is = new JLabel("TEAM 2 IS CALLED:"); Omusic = new JLabel("MUSIC:"); Oround = new JLabel("ROUNDS:"); Otcol1 = new JLabel("Team 1 Color:"); Otcol2 = new JLabel("Team 2 Color:"); Fpic = new JLabel(new ImageIcon("ctfpost.jpg")); Ipic = new JLabel(new ImageIcon("flag.jpg")); control = new JLabel("

" + " Player 1:

UP = up arrow key

" + " DOWN = down arrow key

" + " LEFT = left arrow key

" + " RIGHT = right arrow key

" + " Player 2:

UP = W

" + " DOWN = S

" + " LEFT = A

" + " RIGHT = D

" + " Player 3:

UP = U

" + " DOWN = J

" + " LEFT = H

" + " RIGHT = K

" + " Player 4:

UP = 8 on numberpad (NUMLOCK ON)

" + " DOWN = 5 on numberpad (NUMLOCK ON)

" + " LEFT = 4 on numberpad (NUMLOCK ON)

" + " RIGHT = 6 on numberpad (NUMLOCK ON)

" + "

" + " Quit = Q

" + " Pause = P

" + "


"); Iobjective = new JLabel( "

The Objective of this game is to capture the flag of the opposing team.

" + "The teams are split into groups of 2 where on either side there is an attacker and a defender.

" + "The attacker on both side is allowed to roam around the screen and try to" + "

avoid being shot by the defender and at the same time try to grab the flag" + "

from the base of the other team

"); //buttons Fplay = new JButton("PLAY"); Finstruct = new JButton("INSTRUCTIONS & CONTROLS"); Fexit = new JButton("EXIT"); Iback = new JButton("<< BACK"); Cok = new JButton("OK"); Cok2 = new JButton("OK"); Ccont = new JButton("CONTINUE >>"); Wback = new JButton("<< BACK"); Wcont = new JButton("CONTINUE >>"); Lback = new JButton("<< BACK"); Lcont = new JButton("CONTINUE >>"); Oback = new JButton("<< BACK"); Obegin = new JButton("BEGIN!"); p1 = new JButton(new ImageIcon("alex1.jpg")); p1.addActionListener(new myActionListener()); p1.setToolTipText("The mean machine - Alex"); p2 = new JButton(new ImageIcon("timmy1.jpg")); p2.addActionListener(new myActionListener()); p2.setToolTipText("The dominator - Timmy"); p3 = new JButton(new ImageIcon("ben1.jpg")); p3.addActionListener(new myActionListener()); p3.setToolTipText("The Terminator - Ben"); p4 = new JButton(new ImageIcon("pye1.jpg")); p4.addActionListener(new myActionListener()); p4.setToolTipText("Mr Incredible - Pye"); g1 = new JButton(new ImageIcon("gun1.gif")); g1.addActionListener(new myActionListener()); g1.setToolTipText("Pistol"); g2 = new JButton(new ImageIcon("gun2.gif")); g2.addActionListener(new myActionListener()); g2.setToolTipText("Machine Gun"); g3 = new JButton(new ImageIcon("gun3.jpg")); g3.addActionListener(new myActionListener()); g3.setToolTipText("Rifle"); g4 = new JButton(new ImageIcon("gun4.jpg")); g4.addActionListener(new myActionListener()); g4.setToolTipText("Shotgun"); g5 = new JButton(new ImageIcon("gun5.jpg")); g5.addActionListener(new myActionListener()); g5.setToolTipText("Uzi"); stg1 = new JButton(new ImageIcon("space.jpg")); stg1.addActionListener(new myActionListener()); stg1.setToolTipText("Space"); stg2 = new JButton(new ImageIcon("desert.jpg")); stg2.addActionListener(new myActionListener()); stg2.setToolTipText("Desert"); stg3 = new JButton(new ImageIcon("ocean.jpg")); stg3.addActionListener(new myActionListener()); stg3.setToolTipText("Ocean"); stg4 = new JButton(new ImageIcon("fire.jpg")); stg4.addActionListener(new myActionListener()); stg4.setToolTipText("Fire"); stg5 = new JButton(new ImageIcon("woods.jpg")); stg5.addActionListener(new myActionListener()); stg5.setToolTipText("Woods"); resume = new JButton("RESUME"); quit1 = new JButton("QUIT"); CBut = new JButton("CONTROLS"); CBut.addActionListener(new myActionListener()); CBack = new JButton("<< BACK"); CBack.addActionListener(new myActionListener()); Mon = new JButton("ON"); Mon.addActionListener(new myActionListener()); Moff = new JButton("OFF"); Moff.addActionListener(new myActionListener()); R1 = new JButton("1"); R1.addActionListener(new myActionListener()); R3 = new JButton("3"); R3.addActionListener(new myActionListener()); R5 = new JButton("5"); R5.addActionListener(new myActionListener()); red = new JButton(""); red.addActionListener(new myActionListener()); red1 = new JButton(""); red1.addActionListener(new myActionListener()); black = new JButton(""); black.addActionListener(new myActionListener()); black1 = new JButton(""); black1.addActionListener(new myActionListener()); blue = new JButton(""); blue.addActionListener(new myActionListener()); blue1 = new JButton(""); blue1.addActionListener(new myActionListener()); green = new JButton(""); green.addActionListener(new myActionListener()); green1 = new JButton(""); green1.addActionListener(new myActionListener()); orange = new JButton(""); orange.addActionListener(new myActionListener()); orange1 = new JButton(""); orange1.addActionListener(new myActionListener()); Wep1ok = new JButton("Click to select Team 2 Weapon"); Wep1ok.addActionListener(new myActionListener()); //TEXTFIELDS Ctxtentr1 = new JTextField("", 15); Ctxtentr2 = new JTextField("", 15); Ctxtis1 = new JTextField("", 15); Ctxtis2 = new JTextField("", 15); Gvstxt = new JTextField("", 15); Gvstxt.setHorizontalAlignment(JTextField.CENTER); Gvstxt.setEditable(false); Cp1tf = new JTextField("", 15); Cp2tf = new JTextField("", 15); Cp3tf = new JTextField("", 15); Cp4tf = new JTextField("", 15); p1txt = new JTextField("", 15); p2txt = new JTextField("", 15); } public void launchFrame() { front.addWindowListener(new myWindowListener()); front.addKeyListener(new MyKeyListener()); instruction.addKeyListener(new MyKeyListener()); Controls.addKeyListener(new MyKeyListener()); character.addKeyListener(new MyKeyListener()); weapon.addKeyListener(new MyKeyListener()); location.addKeyListener(new MyKeyListener()); option.addKeyListener(new MyKeyListener()); gamescreen.addKeyListener(new MyKeyListener()); Fplay.addActionListener(new myActionListener()); Finstruct.addActionListener(new myActionListener()); Fexit.addActionListener(new myActionListener()); Iback.addActionListener(new myActionListener()); Cok.addActionListener(new myActionListener()); Cok2.addActionListener(new myActionListener()); Ccont.addActionListener(new myActionListener()); Wback.addActionListener(new myActionListener()); Wcont.addActionListener(new myActionListener()); Lback.addActionListener(new myActionListener()); Lcont.addActionListener(new myActionListener()); Oback.addActionListener(new myActionListener()); Obegin.addActionListener(new myActionListener()); resume.addActionListener(new myActionListener()); quit1.addActionListener(new myActionListener()); gamescreen.setResizable(false); gamescreen.setSize(1020, 730); gamescreen.setLocation(0, 0); instruction.setResizable(false); instruction.setSize(1030, 735); instruction.setLocation(0, 0); character.setResizable(false); character.setSize(1030, 735); character.setLocation(0, 0); weapon.setResizable(false); weapon.setSize(1030, 735); weapon.setLocation(0, 0); location.setResizable(false); location.setSize(1030, 735); location.setLocation(0, 0); Controls.setResizable(false); Controls.setSize(1030, 735); Controls.setLocation(0, 0); option.setResizable(false); option.setSize(1030, 735); option.setLocation(0, 0); front.setSize(1030, 735); front.setLocation(0, 0); pause.setResizable(false); pause.setSize(55, 55); pause.setLocation(0, 0); quit.setResizable(false); quit.setSize(55, 55); quit.setLocation(0, 0); gamescreen.getContentPane().add(lev1, BorderLayout.CENTER); gamescreen.getContentPane().add(Gtop, BorderLayout.NORTH); character.getContentPane().add(Ct, BorderLayout.NORTH); character.getContentPane().add(Cm, BorderLayout.CENTER); character.getContentPane().add(Cb, BorderLayout.SOUTH); character.getContentPane().add(Cl, BorderLayout.EAST); character.getContentPane().add(Cr, BorderLayout.WEST); weapon.getContentPane().add(Wt, BorderLayout.NORTH); weapon.getContentPane().add(Wl, BorderLayout.WEST); weapon.getContentPane().add(Wm, BorderLayout.CENTER); weapon.getContentPane().add(Wr, BorderLayout.EAST); weapon.getContentPane().add(Wb, BorderLayout.SOUTH); location.getContentPane().add(Lt, BorderLayout.NORTH); location.getContentPane().add(Lml, BorderLayout.WEST); location.getContentPane().add(Lmm, BorderLayout.CENTER); location.getContentPane().add(Lmr, BorderLayout.EAST); location.getContentPane().add(Lb, BorderLayout.SOUTH); Controls.getContentPane().add(Ctop, BorderLayout.NORTH); Controls.getContentPane().add(Cmiddle, BorderLayout.CENTER); Controls.getContentPane().add(Cbottom, BorderLayout.SOUTH); instruction.getContentPane().add(It, BorderLayout.NORTH); instruction.getContentPane().add(Im, BorderLayout.CENTER); instruction.getContentPane().add(Ib, BorderLayout.SOUTH); option.getContentPane().add(Ot, BorderLayout.NORTH); option.getContentPane().add(Ol, BorderLayout.WEST); option.getContentPane().add(Om, BorderLayout.CENTER); option.getContentPane().add(Or, BorderLayout.EAST); option.getContentPane().add(Ob, BorderLayout.SOUTH); front.getContentPane().add(Ft, BorderLayout.NORTH); front.getContentPane().add(Fm, BorderLayout.CENTER); front.getContentPane().add(Fb, BorderLayout.SOUTH); pause.getContentPane().add(resume, BorderLayout.CENTER); quit.getContentPane().add(quit1, BorderLayout.CENTER); Ft.add(Ftopl); Ft.setBackground(Color.YELLOW); Ft.add(Fpic); Fm.setLayout(new GridLayout(2, 1)); Fm.add(FLab); Fm.add(Fintro); Fm.setBackground(Color.YELLOW); Fb.setLayout(new GridLayout(1, 3)); Fb.add(Fplay); Fplay.setBorderPainted(false); Fplay.setBackground(Color.YELLOW); Fb.add(Finstruct); Finstruct.setBorderPainted(false); Finstruct.setBackground(Color.YELLOW); Fb.add(Fexit); Fexit.setBorderPainted(false); Fexit.setBackground(Color.YELLOW); It.add(Itopl); Im.add(Iobjective); Im.add(Ipic); Ib.setLayout(new GridLayout(1, 2)); Ib.add(Iback); Ib.add(CBut); CBut.setBorderPainted(false); CBut.setBackground(Color.YELLOW); Iback.setBorderPainted(false); Iback.setBackground(Color.YELLOW); It.setBackground(Color.YELLOW); Im.setBackground(Color.YELLOW); Ib.setBackground(Color.YELLOW); Ctop.add(Ctopc); Cmiddle.add(control); Cbottom.add(CBack); CBack.setBorderPainted(false); CBack.setBackground(Color.YELLOW); Ctop.setBackground(Color.YELLOW); Cmiddle.setBackground(Color.YELLOW); Cbottom.setBackground(Color.YELLOW); Ct.add(Ctopl); Ct.setBackground(new Color(15, 102, 208)); Ctopl.setForeground(Color.WHITE); Cr.setLayout(new GridLayout(6, 1)); Cr.add(Cteam1); Cr.add(p1pic); Cr.add(Cname1); Cr.add(p2pic); Cr.add(Ctxtentr1); Cr.add(Cok); Cr.setBackground(Color.BLACK); Cname1.setForeground(Color.WHITE); Cteam1.setForeground(Color.WHITE); Cl.setLayout(new GridLayout(6, 1)); Cl.add(Cteam2); Cl.add(p3pic); Cl.add(Cname2); Cl.add(p4pic); Cl.add(Ctxtentr2); Cl.add(Cok2); Cl.setBackground(Color.BLACK); Cname2.setForeground(Color.WHITE); Cteam2.setForeground(Color.WHITE); Cm.setLayout(new GridLayout(4, 1)); Cm.add(p1); p1.setBackground(Color.BLACK); p1.setBorderPainted(false); Cm.add(p2); p2.setBackground(Color.BLACK); p2.setBorderPainted(false); Cm.add(p3); p3.setBackground(Color.BLACK); p3.setBorderPainted(false); Cm.add(p4); p4.setBackground(Color.BLACK); p4.setBorderPainted(false); Cm.setBackground(Color.BLACK); Cb.add(Ccont); Ccont.setBackground(new Color(15, 102, 208)); Ccont.setBorderPainted(false); Cb.setBackground(new Color(15, 102, 208)); Cb.setForeground(Color.WHITE); Wt.add(Wtopl); Wt.setBackground(new Color(239, 96, 80)); Wl.setLayout(new GridLayout(5, 1)); Wl.add(g1); Wl.add(g2); Wl.add(g3); Wl.add(g4); Wl.add(g5); Wm.setLayout(new GridLayout(8, 1)); Wm.add(wep1); Wm.add(wep1pic); Wm.add(wep2); Wm.add(wep2pic); Wm.add(wep3); Wm.add(wep3pic); Wm.add(wep4); Wm.add(wep4pic); Wr.setLayout(new BoxLayout(Wr, BoxLayout.Y_AXIS)); Wr.add(Box.createRigidArea(new Dimension(0, 120))); Wr.add(Wep1); Wr.add(Box.createRigidArea(new Dimension(0, 90))); Wr.add(Wep2); Wr.add(Box.createRigidArea(new Dimension(0, 120))); Wr.add(Wep1ok); Wr.add(Box.createRigidArea(new Dimension(0, 80))); Wr.add(Wep3); Wr.add(Box.createRigidArea(new Dimension(0, 90))); Wr.add(Wep4); Wb.add(Wback); Wback.setBackground(new Color(239, 96, 80)); Wback.setBorderPainted(false); Wb.setBackground(new Color(239, 96, 80)); Wb.add(Wcont); Wcont.setBackground(new Color(239, 96, 80)); Wcont.setBorderPainted(false); Lml.setLayout(new GridLayout(5, 1)); Lt.add(Ltopl); Lt.setBackground(new Color(68, 94, 215)); Lml.add(stg1); Lml.add(stg2); Lml.add(stg3); Lml.add(stg4); Lml.add(stg5); Lmm.setLayout(new BoxLayout(Lmm, BoxLayout.Y_AXIS)); Lmm.add(Box.createRigidArea(new Dimension(120, 190))); Lmm.add(Loc1p); Lmm.add(Box.createRigidArea(new Dimension(160, 40))); Lmm.add(Loc1); Lb.add(Lback); Lback.setBackground(new Color(68, 94, 215)); Lback.setBorderPainted(false); Lb.setBackground(new Color(68, 94, 215)); Lb.add(Lcont); Lcont.setBackground(new Color(68, 94, 215)); Lcont.setBorderPainted(false); Ot.add(Otopl); Ot.setBackground(new Color(108, 174, 130)); Ol.setLayout(new GridLayout(5, 1)); Ol.add(Omusic); // Ol.add(Oround); Ol.add(Otcol1); Ol.add(Otcol2); Om.setLayout(new GridLayout(5, 1)); Om.add(MusicL); // Om.add(RoundL); Om.add(Color1L); Om.add(Color2L); Or.setLayout(new BoxLayout(Or, BoxLayout.Y_AXIS)); Or.add(Box.createRigidArea(new Dimension(1, 60))); Or.add(Mon, c); Or.add(Box.createRigidArea(new Dimension(1, 10))); Or.add(Moff, c); // Or.add(Box.createRigidArea(new Dimension(1, 60))); // Or.add(R1, c); // Or.add(Box.createRigidArea(new Dimension(1, 5))); // Or.add(R3, c); // Or.add(Box.createRigidArea(new Dimension(1, 5))); // Or.add(R5, c); Or.add(Box.createRigidArea(new Dimension(1, 50))); Or.add(red, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(black, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(blue, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(green, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(orange, c); Or.add(Box.createRigidArea(new Dimension(1, 50))); Or.add(red1, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(black1, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(blue1, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(green1, c); Or.add(Box.createRigidArea(new Dimension(1, 5))); Or.add(orange1, c); Ob.add(Oback); Oback.setBackground(new Color(108, 174, 130)); Oback.setBorderPainted(false); Ob.setBackground(new Color(108, 174, 130)); Ob.add(Obegin); Obegin.setBackground(new Color(108, 174, 130)); Obegin.setBorderPainted(false); Gtop.add(Gvstxt); red.setBackground(Color.RED); black.setBackground(Color.BLACK); blue.setBackground(Color.BLUE); green.setBackground(Color.GREEN); orange.setBackground(Color.ORANGE); red1.setBackground(Color.RED); black1.setBackground(Color.BLACK); blue1.setBackground(Color.BLUE); green1.setBackground(Color.GREEN); orange1.setBackground(Color.ORANGE); front.setVisible(true); } public class MyKeyListener implements KeyListener { public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { for (int i=0; i<1000; i++){ if (manshoot==false){ manshoot=true; gun = new Shoot(x, y, i); gun.start(); break; } } } if (e.getKeyCode() == KeyEvent.VK_NUMPAD0) { for (int i=0; i<1000; i++){ if (manshoot1==false){ manshoot1=true; gun1 = new Shoot1( x1, y1, i); gun1.start(); break; } } } //pause if (e.getKeyCode() == KeyEvent.VK_P) { pause.setVisible(true); } //quit if (e.getKeyCode() == KeyEvent.VK_Q) { quit.setVisible(true); } //player 1 controls if (e.getKeyCode() == KeyEvent.VK_RIGHT) { if (x != 970) { x = x + 10; a = 2; // if ((x >= 380) && (y >= 355) && (y <= 480)) { // x = x - 10; // } // if ((x <= 40)&&(y>=100)&&(y<=150)){ // x = x - 10; // } gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_LEFT) { if (x != 0) { x = x - 10; a = 2; // if ((x <= 520) && (y >= 355) && (y <= 480)) { // x = x + 10; // } gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_UP) { if (y != -10) { y = y - 10; a = 2; // if ((x <= 452) && (y >= 452) && (y <= 348)) { // x = x - 10; // } gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (y != 630) { y = y + 10; a = 2; // if ((x <= 452) && (y >= 348) && (y <= 452)) { // x = x - 10; // } gamescreen.repaint(); } } //player 2 controls if (e.getKeyCode() == KeyEvent.VK_D) { if (x1 != 970) { x1 = x1 + 10; b = 3; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_A) { if (x1 != 0) { x1 = x1 - 10; b = 3; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_W) { if (y1 != -10) { y1 = y1 - 10; b = 3; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_S) { if (y1 != 630) { y1 = y1 + 10; b = 3; gamescreen.repaint(); } } //player 3 controls if (e.getKeyCode() == KeyEvent.VK_K) { if (x2 != 970) { x2 = x2 + 10; cc = 4; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_H) { if (x2 != 0) { x2 = x2 - 10; cc = 2; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_U) { if (y2 != -10) { y2 = y2 - 10; cc = 3; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_J) { if (y2 != 630) { y2 = y2 + 10; cc = 1; gamescreen.repaint(); } } // PLAYER 4 CONTROLS if (e.getKeyCode() == KeyEvent.VK_NUMPAD6) { if (x3 != 930) { x3 = x3 + 10; d = 3; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_NUMPAD4) { if (x3 != 0) { x3 = x3 - 10; d = 2; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_NUMPAD8) { if (y3 != -10) { y3 = y3 - 10; d = 4; gamescreen.repaint(); } } if (e.getKeyCode() == KeyEvent.VK_NUMPAD5) { if (y3 != 600) { y3 = y3 + 10; d = 1; gamescreen.repaint(); } } } } class myActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { team1 = Ctxtentr1.getText(); if (team1 == null || team1.equals("")) { team1 = "TEAM 1"; } team2 = Ctxtentr2.getText(); if (team2 == null || team2.equals("")) { team2 = "TEAM 2"; } if (team.compareToIgnoreCase(team1) == 0) { if (e.getSource() == p1) { if (imagepic) { p2pic.setIcon(new ImageIcon("alex1.png")); PlaceHolders[2]=Toolkit.getDefaultToolkit().getImage("alex1.png"); Cteam1.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr1.setEditable(true); Ctxtentr1.requestFocus(); wep2.setText("TEAM 1 - 'The Mean Machine' Select weapon"); team = ""; } else { p1pic.setIcon(new ImageIcon("alex1.png")); PlaceHolders[1]=Toolkit.getDefaultToolkit().getImage("alex1.png"); gamescreen.repaint(); Cteam1.setText("SELECT SECOND PLAYER"); imagepic = true; wep1.setText("TEAM 1 - 'The Mean Machine' Select weapon"); } } if (e.getSource() == p2) { if (imagepic) { p2pic.setIcon(new ImageIcon("timmy1.png")); Cteam1.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr1.setEditable(true); Ctxtentr1.requestFocus(); wep2.setText("TEAM 1 - 'The Dominator' Select weapon"); team = ""; } else { p1pic.setIcon(new ImageIcon("timmy1.png")); Cteam1.setText("SELECT SECOND PLAYER"); imagepic = true; wep1.setText("TEAM 1 - 'The Dominator' Select weapon"); } } if (e.getSource() == p3) { if (imagepic) { p2pic.setIcon(new ImageIcon("ben1.png")); Cteam1.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr1.setEditable(true); Ctxtentr1.requestFocus(); wep2.setText("TEAM 1 - 'The Terminator' Select weapon"); team = ""; } else { p1pic.setIcon(new ImageIcon("ben1.png")); Cteam1.setText("SELECT SECOND PLAYER"); imagepic = true; wep1.setText("TEAM 1 - 'The Terminator' Select weapon"); } } if (e.getSource() == p4) { if (imagepic) { p2pic.setIcon(new ImageIcon("pye1.png")); Cteam1.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr1.setEditable(true); Ctxtentr1.requestFocus(); wep2.setText("TEAM 1 - 'Mr Incredible' Select weapon"); team = ""; } else { p1pic.setIcon(new ImageIcon("pye1.png")); Cteam1.setText("SELECT SECOND PLAYER"); imagepic = true; wep1.setText("TEAM 1 - 'Mr Incredible' Select weapon"); } } } if (e.getSource() == Cok) { Cname1.setText(team1); Cteam1.setText(""); Cteam2.setText("TEAM 2, SELECT FIRST PLAYER"); team = team2; } if (team.compareToIgnoreCase(team2) == 0) { if (e.getSource() == p1) { if (imagepic2) { p4pic.setIcon(new ImageIcon("alex1.png")); Cteam2.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr2.setEditable(true); Ctxtentr2.requestFocus(); wep4.setText("TEAM 2 - 'The Mean Machine' Select weapon"); team = ""; } else { p3pic.setIcon(new ImageIcon("alex1.png")); Cteam2.setText("SELECT SECOND PLAYER"); imagepic2 = true; wep3.setText("TEAM 2 - 'The Mean Machine' Select weapon"); } } if (e.getSource() == p2) { if (imagepic2) { p4pic.setIcon(new ImageIcon("timmy1.png")); Cteam2.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr2.setEditable(true); Ctxtentr2.requestFocus(); wep4.setText("TEAM 2 - 'The Dominator' Select weapon"); team = ""; } else { p3pic.setIcon(new ImageIcon("timmy1.png")); Cteam2.setText("SELECT SECOND PLAYER"); imagepic2 = true; wep3.setText("TEAM 2 - 'The Dominator' Select weapon"); } } if (e.getSource() == p3) { if (imagepic2) { p4pic.setIcon(new ImageIcon("ben1.png")); Cteam2.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr2.setEditable(true); Ctxtentr2.requestFocus(); wep4.setText("TEAM 2 - 'The Terminator' Select weapon"); team = ""; } else { p3pic.setIcon(new ImageIcon("ben1.png")); Cteam2.setText("SELECT SECOND PLAYER"); imagepic2 = true; wep3.setText("TEAM 2 - 'The Terminator' Select weapon"); } } if (e.getSource() == p4) { if (imagepic2) { p4pic.setIcon(new ImageIcon("pye1.png")); Cteam2.setText("ENTER TEAM NAME THEN CLICK OK"); Ctxtentr2.setEditable(true); Ctxtentr2.requestFocus(); wep4.setText("TEAM 2 - 'Mr Incredible' Select weapon"); team = ""; } else { p3pic.setIcon(new ImageIcon("pye1.png")); Cteam2.setText("SELECT SECOND PLAYER"); imagepic2 = true; wep3.setText("TEAM 2 - 'Mr Incredible' Select weapon"); } } } if (e.getSource() == Cok2) { Cname2.setText(team2); Cteam2.setText(""); team=team1; } if (team.compareToIgnoreCase(team1)==0){ if (e.getSource() == g1) { if (goWpn) { wep2pic.setIcon(new ImageIcon("bullet1.png")); Wep2.setText("Pistol"); team=""; } else { wep1pic.setIcon(new ImageIcon("bullet1.png")); Wep1.setText("Pistol"); wep2.setVisible(true); goWpn = true; } } if (e.getSource() == g2) { if (goWpn) { wep2pic.setIcon(new ImageIcon("bullet3.png")); Wep2.setText("Machine Gun"); team=""; } else { wep1pic.setIcon(new ImageIcon("bullet3.png")); Wep1.setText("Machine Gun"); wep2.setVisible(true); goWpn = true; } } if (e.getSource() == g3) { if (goWpn) { wep2pic.setIcon(new ImageIcon("bullet2.png")); Wep2.setText("Rifle"); team=""; } else { wep1pic.setIcon(new ImageIcon("bullet2.png")); Wep1.setText("Rifle"); wep2.setVisible(true); goWpn = true; } } if (e.getSource() == g4) { if (goWpn) { wep2pic.setIcon(new ImageIcon("bullet5.png")); Wep2.setText("Shotgun"); team=""; } else { wep1pic.setIcon(new ImageIcon("bullet5.png")); Wep1.setText("Shotgun"); wep2.setVisible(true); goWpn = true; } } if (e.getSource() == g5) { if (goWpn) { wep2pic.setIcon(new ImageIcon("bullet4.png")); Wep2.setText("Uzi"); team=""; } else { wep1pic.setIcon(new ImageIcon("bullet4.png")); Wep1.setText("Uzi"); wep2.setVisible(true); goWpn = true; } } } if (e.getSource() == Wep1ok) { wep3.setVisible(true); team=team2; } if (team.compareToIgnoreCase(team2)==0){ if (e.getSource() == g1) { if (goWpn2) { wep4pic.setIcon(new ImageIcon("bullet1.png")); Wep4.setText("Pistol"); team=""; } else { wep3pic.setIcon(new ImageIcon("bullet1.png")); Wep3.setText("Pistol"); wep4.setVisible(true); goWpn2 = true; } } if (e.getSource() == g2) { if (goWpn2) { wep4pic.setIcon(new ImageIcon("bullet3.png")); Wep4.setText("Machine Gun"); team=""; } else { wep3pic.setIcon(new ImageIcon("bullet3.png")); Wep3.setText("Machine Gun"); wep4.setVisible(true); goWpn2 = true; } } if (e.getSource() == g3) { if (goWpn2) { wep4pic.setIcon(new ImageIcon("bullet2.png")); Wep4.setText("Rifle"); team=""; } else { wep3pic.setIcon(new ImageIcon("bullet2.png")); Wep3.setText("Rifle"); wep4.setVisible(true); goWpn2 = true; } } if (e.getSource() == g4) { if (goWpn2) { wep4pic.setIcon(new ImageIcon("bullet5.png")); Wep4.setText("Shotgun"); team=""; } else { wep3pic.setIcon(new ImageIcon("bullet5.png")); Wep3.setText("Shotgun"); wep4.setVisible(true); goWpn2 = true; } } if (e.getSource() == g5) { if (goWpn2) { wep4pic.setIcon(new ImageIcon("bullet4.png")); Wep4.setText("Uzi"); team=""; } else { wep3pic.setIcon(new ImageIcon("bullet4.png")); Wep3.setText("Uzi"); wep4.setVisible(true); goWpn2 = true; } } } if (e.getSource() == Wep1ok) { Wep3.requestFocus(); } if (e.getSource() == Wep1ok) { Wep3.requestFocus(); } if (e.getSource() == p1) { PlaceHolders[1] = alex[1]; gamescreen.repaint(); } if (e.getSource() == p1) { PlaceHolders[1] = timmy[1]; gamescreen.repaint(); } if (e.getSource() == p1) { PlaceHolders[1] = ben[1]; gamescreen.repaint(); } if (e.getSource() == p1) { PlaceHolders[1] = pye[1]; gamescreen.repaint(); } if (e.getSource() == stg1) { Loc1p.setIcon(new ImageIcon("space.jpg")); Loc1p.requestFocus(); Loc1.setIcon(new ImageIcon("Spacewriting.jpg")); lev1.repaint(); } if (e.getSource() == stg2) { Loc1p.setIcon(new ImageIcon("desert.jpg")); Loc1p.requestFocus(); Loc1.setIcon(new ImageIcon("Desertwriting.jpg")); backgroundImage1 = backgroundImage2; gamescreen.getContentPane().add(lev2, BorderLayout.CENTER); lev2.repaint(); } if (e.getSource() == stg3) { Loc1p.setIcon(new ImageIcon("ocean.jpg")); Loc1p.requestFocus(); Loc1.setIcon(new ImageIcon("Oceanwriting.jpg")); backgroundImage1 = backgroundImage3; gamescreen.getContentPane().add(lev3, BorderLayout.CENTER); lev3.repaint(); } if (e.getSource() == stg4) { Loc1p.setIcon(new ImageIcon("fire.jpg")); Loc1p.requestFocus(); Loc1.setIcon(new ImageIcon("Firewriting.jpg")); backgroundImage1 = backgroundImage4; gamescreen.getContentPane().add(lev4, BorderLayout.CENTER); lev4.repaint(); } if (e.getSource() == stg5) { Loc1p.setIcon(new ImageIcon("woods.jpg")); Loc1p.requestFocus(); Loc1.setIcon(new ImageIcon("Woodswriting.jpg")); backgroundImage1 = backgroundImage5; gamescreen.getContentPane().add(lev5, BorderLayout.CENTER); lev5.repaint(); } if (e.getSource() == Obegin) { Gvstxt.setText(Ctxtentr1.getText() + " VS " + Ctxtentr2.getText()); } if (e.getSource() == resume) { pause.setVisible(false); } if (e.getSource() == quit1) { front.setVisible(true); instruction.setVisible(false); Controls.setVisible(false); character.setVisible(false); weapon.setVisible(false); location.setVisible(false); option.setVisible(false); gamescreen.setVisible(false); quit.hide(); } if (e.getSource() == Fplay) { character.setVisible(true); front.setVisible(false); character.requestFocus(); team=team1; } if (e.getSource() == Finstruct) { instruction.setVisible(true); front.setVisible(false); instruction.requestFocus(); } if (e.getSource() == Fexit) { System.exit(0); } if (e.getSource() == Iback) { front.setVisible(true); instruction.hide(); front.requestFocus(); } if (e.getSource() == CBut) { Controls.setVisible(true); instruction.hide(); Controls.requestFocus(); } if (e.getSource() == CBack) { instruction.setVisible(true); Controls.hide(); instruction.requestFocus(); } if (e.getSource() == Ccont) { weapon.setVisible(true); character.hide(); weapon.requestFocus(); } if (e.getSource() == Wback) { character.setVisible(true); weapon.hide(); character.requestFocus(); } if (e.getSource() == Wcont) { location.setVisible(true); weapon.hide(); location.requestFocus(); } if (e.getSource() == Lback) { weapon.setVisible(true); location.hide(); weapon.requestFocus(); } if (e.getSource() == Lcont) { option.setVisible(true); location.hide(); option.requestFocus(); } if (e.getSource() == Oback) { location.setVisible(true); option.hide(); location.requestFocus(); } if (e.getSource() == Mon) { MusicL.setText("ON"); } if (e.getSource() == Moff) { MusicL.setText("OFF"); } // if (e.getSource() == R1) { // RoundL.setText("1 round"); // } // if (e.getSource() == R3) { // RoundL.setText("3 rounds"); // } // if (e.getSource() == R5) { // RoundL.setText("5 rounds"); // } if (e.getSource() == red) { Color1L.setIcon(new ImageIcon("base1red.png")); base1[b1] = base1[0]; gamescreen.repaint(); } if (e.getSource() == red1) { Color2L.setIcon(new ImageIcon("base2red.png")); base2[b2] = base2[0]; gamescreen.repaint(); } if (e.getSource() == black) { Color1L.setIcon(new ImageIcon("base2black.png")); base1[b1] = base1[1]; gamescreen.repaint(); } if (e.getSource() == black1) { Color2L.setIcon(new ImageIcon("base2black.png")); base2[b2] = base2[1]; gamescreen.repaint(); } if (e.getSource() == blue) { Color1L.setIcon(new ImageIcon("base1blue.png")); base1[b1] = base1[2]; gamescreen.repaint(); } if (e.getSource() == blue1) { Color2L.setIcon(new ImageIcon("base2blue.png")); base2[b2] = base2[2]; gamescreen.repaint(); } if (e.getSource() == green) { Color1L.setIcon(new ImageIcon("base1green.png")); base1[b1] = base1[3]; gamescreen.repaint(); } if (e.getSource() == green1) { Color2L.setIcon(new ImageIcon("base2green.png")); base2[b2] = base2[3]; gamescreen.repaint(); } if (e.getSource() == orange) { Color1L.setIcon(new ImageIcon("base1orange.png")); base1[b1] = base1[4]; gamescreen.repaint(); } if (e.getSource() == orange1) { Color2L.setIcon(new ImageIcon("base2orange.png")); base2[b2] = base2[4]; gamescreen.repaint(); } if (e.getSource() == Obegin) { gamescreen.setVisible(true); gamescreen.repaint(); option.hide(); gamescreen.requestFocus(); } } } public class Shoot extends Thread{ int gun_x = 0; int gun_y = 0; int bullet_xy = 0; public Shoot(int start1, int start2, int start3){ gun_x = start1; gun_y = start2; bullet_xy = start3; } public void run(){ do{ gun_x=gun_x+50; // + = direction left, right; 50(number) means how fast its going gamescreen.repaint(); if (((gun_x>=x3)&&((gun_x+15)<=(x3+90)))&&((gun_y>=y3)&&((gun_y+5)<=(y3+110)))){ System.out.println("Working"); die=true; } try{this.sleep(50);}catch(InterruptedException e){} }while ((gun_y>100)&&(hitman!=true)); manshoot[bullet_xy] = false; } } public class Shoot1 extends Thread{ int gun_x1 = 0; int gun_y1 = 0; int bullet_xy = 0; public Shoot1(int start4, int start5, int start6){ gun_x1 = start4; gun_y1 = start5; bullet_xy = start6; } public void run(){ do{ gun_x1=gun_x1-15; gamescreen.repaint(); if (((gun_x1>=x2)&&((gun_x1+15)<=(x2+90)))&&((gun_y1>=y2)&&((gun_y1+5)<=(y2+110)))){ System.out.println("Working"); die=true; } try{this.sleep(50);}catch(InterruptedException e){} }while ((gun_y1>100)&&(hitman!=true)); manshoot1[bullet_xy] = false; } } public void main(){ } class myWindowListener implements WindowListener { public void windowClosing(WindowEvent w) { System.exit(0); } public void windowOpened(WindowEvent w) { } public void windowIconified(WindowEvent w) { } public void windowDeiconified(WindowEvent w) { } public void windowDeactivated(WindowEvent w) { } public void windowClosed(WindowEvent w) { } public void windowActivated(WindowEvent w) { } } public static void main(String[] args) { Tag_eg Taga1 = new Tag_eg(); Taga1.launchFrame(); } } thanks in advance; ALSO.... how would i go about doing this; i have a base(picture) on each side on the gamescreen and i want to put a pic of a flag in the middle.(that part i can do), but i want to be able to make it so when a player walks over that image of the flag, the flag will be attached to him and something will say "you win!!!" (i'm doing a capture the flag type game if you haven't already guessed) thanks again in advance- PLS HELP
timmyk
timmyk
i'm really sorry dude-i am a beginner though to this stuff and if i ahd a known i would of made it simple for you to read :(
this may sound stupid but what is on line 765 because when i go their i'm getting this line of code:
Om.add(Color2L);
(line 765 is in here)......................
Or.setLayout(new BoxLayout(Or, BoxLayout.Y_AXIS));
and what am i adding a ++ to, im really sorry
thankz in advance (sorry)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.