Results 1 to 7 of 7
  1. #1
    sahildave1991 Guest

    Default Help in bow and arrow game

    i have made this program for bow and arrow games.
    But my problem is, that i am able to shoot only 1 arrow.
    I want to shoot as much as arrows as i want.
    wat should i do....

    and also, there is lot of flickering, how should i reduce it ???


    Java Code:
    package BowAndArrow;
    
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class BAA3 extends Applet implements MouseListener,MouseMotionListener,Runnable
    
    {
    	Image pics[]=new Image[12];
    	Image current,arrow,burst,back;
    	Thread t;
    	int num,posX,posY,i=0,j=0,cursor=0;
    	int posAX,posAY;
    	int boom=0;
    	int pos=-100;
    	int posBurstY,posBurstX;
    	
    	public void init()
    	{
    		String imageString[]={"S20.png","S20 (1).png","S20 (2).png","S20 (3).png","S20 (4).png",
    				"S20 (5).png","S30.png","S30 (1).png","S40.png","S40 (1).png","H50.png","B-10.png"};
    		String imageString2[]={"ex.jpg","ex1.jpg"};
    		for(int i=0;i<imageString.length;i++)
    		{
    			pics[i] = getImage(getDocumentBase(),imageString[i]);	
    		}
    		back=getImage(getDocumentBase(),"STAGE I - Morning Glory 2.JPG");
    		burst=getImage(getDocumentBase(),"ex.jpg");
    		addMouseListener(this);
    		addMouseMotionListener(this);
    		arrow=getImage(getDocumentBase(),"1.PNG");
    	}
    	
    	//start
    	public void start()
    	{
    		t= new Thread(this);
    		t.start();
    	}
    	
    	//run
    	public void run()
    	{
    		while(boom!=1)
    		{
    			num=(int)((Math.random())*12);					// for random balloon
    			loadpic(num);	
    		}
    	}
    	
    	//loadpic
    	public void loadpic(int i)
    	{
    		current=pics[i];
    		posX=(int)(Math.random()*950);						//	for random position of balloon
    		j=0;
    		while(j<751&&boom==2)
    		{
    			pause(100);
    			j=j+30;
    		}
    		
    	}
    	
    	//pause
    	public void pause(int t)
    	{
    		try 
    		{
    			Thread.sleep(t);
    		}
    		catch (InterruptedException e) {}
    	}
    	
    	//mouseEvents
    	public void mouseMoved(MouseEvent e)
    	{
    		posY=e.getY();
    		showStatus("mouse moved");
    	}
    	public void mouseClicked(MouseEvent e) 
    	{
    		pos=e.getY();
    		cursor=1;
    		showStatus("mouse clicked");
    		repaint();	
    	}
    	public void mouseEntered(MouseEvent e) {}
    	public void mouseExited(MouseEvent e) {}
    	public void mousePressed(MouseEvent e) {}
    	public void mouseReleased(MouseEvent e) {}
    	public void mouseDragged(MouseEvent e) {}
    	
    	//graphics
    	public void paint(Graphics g)
    	{	
    		g.drawImage(back,0,0,this);
    		if (current != null)
    		{
    			setSize(1024,668);
    			
    			g.drawString("arrow at "+i+","+posY,0, 620);
    			g.drawString(posX+","+(548-j), 0, 600);
    			g.drawString("BALLOON NO. "+num, 0, 610);
    			
    			for(int x=0;x<150;x++)
    			{
    				if((posAX+100)==posX&&(548-j+x)==pos)	//	For bursting of balloon,
    				{										//	if the coordinate matches
    					boom=1;								//	in specific region the 
    					posBurstY  = 548-j+x;				//	image of explosion would 
    					posBurstX=posX;						//	be drawn.
    				}
    			}
    			if(boom==1)
    			{
    				g.drawImage(burst,posBurstX, posBurstY,this);	//drawing image of explosion			
    			}
    			else
    			{
    				//balloon
    				g.drawImage(current, posX, 548-j, this);
    				//arrow
    				g.drawImage(arrow,0, posY, null);		//	arrow always at the left of screen
    				g.drawImage(arrow,i+0, pos, null);		//	moving arrow
    				posAX=i;posAY=posY;	
    				boom=2;
    				if(cursor==1&&i<1000)
    				{
    					i++;
    				}
    				repaint();
    			}
    		}
    	}
    	
    	
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default

    Try debugging your program to see why only 1 arrow. Add some println() statements to show control flow and the values of variables.

    I don't see any comments in the code that indicates where you "shoot an arrow".
    Can you explain how you are "able to shoot an arrow"?

  3. #3
    sahildave1991 Guest

    Default

    in the else (in paint() method)

    g.drawImage(arrow,0, posY, null);
    g.drawImage(arrow,i+0, pos, null);

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default

    How do YOU(the user) shoot an arrow? I don't see where the user has any control over arrows.

    There is no way I can look at how the code executes without the images.
    Last edited by Norm; 07-03-2010 at 01:20 PM.

  5. #5
    saran1 is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    i try to open this file with all the posible images but browser showing the arrow point and white screen only.. why?

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Quote Originally Posted by saran1 View Post
    i try to open this file with all the posible images but browser showing the arrow point and white screen only.. why?
    Because that's what the code you wrote is telling the program to do. Step through it with a debugger like you were already told, and try to narrow it down. We can't really answer general questions like this, other than to point you towards a debugger and the basic tutorials. Throw together an SSCCE and ask a specific question, and we'll go from there.

  7. #7
    saran1 is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. hove i create arrow?
    By sunolinu in forum Java 2D
    Replies: 8
    Last Post: 02-20-2010, 01:20 AM
  2. BlueJ arrow missing betwen two classes
    By jboy in forum New To Java
    Replies: 2
    Last Post: 10-29-2009, 12:42 PM
  3. Arrow Button Example
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-11-2008, 04:44 PM
  4. Replies: 0
    Last Post: 07-11-2008, 03:07 PM
  5. Draw an arrow
    By Albert in forum SWT / JFace
    Replies: 3
    Last Post: 02-01-2008, 08:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •