
-----------------------------------
Junaid2pac
Sun Jan 20, 2008 6:06 pm

Collision detection using threads
-----------------------------------
Just wondering where u would have the code for actually doing the collision detection in a game if u have 2 objects in the same class that extend thread.

-----------------------------------
Junaid2pac
Sun Jan 20, 2008 6:46 pm

Re: Collision detection using threads
-----------------------------------
in this code where would i put my collision detection:


public void draw()								//Draw ball
  	{
  		if (runBall == true)
  		{
    		Graphics g = box.getGraphics();
    		//g.setXORMode(box.getBackground());
    		g.drawImage(new ImageIcon("C:\\Junaid Java\\Junaid Java ISU\\Pics\\cannon 1.gif").getImage(), 0, 350, null);
    		g.dispose();
  		}
    	else if(runEnemy == true)
    	{
    		Graphics e = box.getGraphics();
    		e.drawOval(xE,yE,xELength,yELength);
    		e.dispose();
    	}
  	}
  	
  	//////////////////////////////////////////////////
  	/*This is how the ball will move - Speed of ball*/
 	//////////////////////////////////////////////////
  	public void moveBall()
  	{
  		if (runBall == true)
  		{
  			elapsed = System.currentTimeMillis() - start;			//Current time
    		if (!box.isVisible())
      			return;
			/*Set Ball*/
    		Graphics g = box.getGraphics();
			g.setXORMode(box.getBackground());				//Removes trail of the ball
    		g.fillOval(x, y, xLength, yLength);
    		
    		if (xE - x = 615 || y>= 390)
    		{
    			dx = 0;
    			dy = 0;
    		}
    		else
    		{
    			if (x>=0)
    			{
    				dx = (Math.cos((Math.toRadians(angle)))) * velocity + windX;					//X Speed
    			}
    			dy = (Math.sin((Math.toRadians(angle)))) * velocity + ((windY + (accelY * (elapsed))) * 0.0005); 	//Y Speed
    		}
    	
    		g.fillOval(x, y, xLength, yLength);
    		g.dispose();
    		runEnemy = false;
  		}
  	}
  	
  	public void moveEnemy()
  	{
  		int i = 0;
  		if (runEnemy == true)
  		{
  			if (!box.isVisible())
      			return;
      		
      		/*Set enemy*/
    		/////////////
    		Graphics e = box.getGraphics();
			e.setXORMode(box.getBackground());
    		e.drawOval(xE,yE,xELength,yELength);

			xE += dxE;
    		//yE += dyE;
    		Dimension d = box.getSize();
      	
      		////////////////////////////
    		/*Change velocity of enemy*/
    		////////////////////////////
    		if(xE >= 600)
    		{
    			dxE *= -1;
    		}
    		else if(xE 