Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Collision detection using threads
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Junaid2pac




PostPosted: Sun Jan 20, 2008 6:06 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Junaid2pac




PostPosted: Sun Jan 20, 2008 6:46 pm   Post subject: Re: Collision detection using threads

in this code where would i put my collision detection:

code:

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 <= sumR)
            {
                //hit = true;
                //dxE = 0;
                return;
            }
       
            ///////////////////////////
                        /*Speed of ball*/
            x += dx;
            y += dy;
            Dimension d = box.getSize();
   
            ///////////////////////////
            /*Change velocity of ball*/
            ///////////////////////////
            if (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 <= 50)
            {
                dxE *= -1;
            }
       
                        e.drawOval(xE, yE, xELength, yELength);
                        runBall = false;
              }
        }
Junaid2pac




PostPosted: Sun Jan 20, 2008 6:47 pm   Post subject: Re: Collision detection using threads

the only reason i can't figure it out is because it's in a thread
Junaid2pac




PostPosted: Sun Jan 20, 2008 7:29 pm   Post subject: Re: Collision detection using threads

the problem is that i only know how to do collision with the latest created enemy....how would i look at the older enemies
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: