Thread: Making a radar

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8

    Making a radar


    hi guys (and, or girls)
    I'm building on a weird radar program but there is no collision detection, btw I'm building in java.
    It says standing on no hit and doesn't change in hit when it enters the big green field.

    here is my code

    Code:
    import java.awt.*;
    import java.applet.*;
    
    public class radar extends Applet implements Runnable
    {
        Thread runner;
        Image Buffer;
        Graphics gBuffer;
        int angle;
        Rectangle hit;
        Rectangle target;
        boolean bhit;
        boolean stap1;     
    
        public void init()
        {   hit=new Rectangle(110,115,10,10);
            target= new Rectangle(200,0,200,200);
            Buffer=createImage(size().width,size().height);
            gBuffer=Buffer.getGraphics();
            
        }
    
        public void start()
        {
            if (runner == null)
            {
                runner = new Thread (this);
                runner.start();
            }
        }
    
        public void stop()
        {
            if (runner != null)
            {
                runner.stop();
                runner = null;
            }
        }
    
        public void run()
        {
            while(true)
            {   bhit  = hit.intersects(target);
                if(bhit){stap1=true;}
                else if (!bhit){stap1=false;}
                try {runner.sleep(10);}
                catch (Exception e) { }
               
                repaint();
            }
        }
    
        void drawStuff()
        {   
            gBuffer.setColor(Color.black);
            gBuffer.fillRect(0,0,size().width,size().height);
            Point p=new Point(size().width/2, size().height/2);   
            int LENGTH=140;
            double vector = angle * Math.PI*2 / 360.0;
            int vx=(int)(p.x+LENGTH*Math.sin(vector));
            int vy=(int)(p.y-LENGTH*Math.cos(vector));
    
    
            hit= new Rectangle(p.x,p.y,vx,vy);
            //r2.move ( r2.x,r2.y-4);
            gBuffer.setColor(Color.green);
            gBuffer.drawLine(hit.x,hit.y, hit.width ,hit.height);
            gBuffer.fillRect(target.x, target.y, target.width, target.height);
            gBuffer.setFont(new Font("Helvetica",Font.PLAIN,13));
            gBuffer.drawString("Angle="+angle+"",10,20);
            
            if(angle<360) angle++;
             else angle=0;
             if(stap1){gBuffer.drawString("hit!!!!!!!!!",20,30);}
             else    {gBuffer.drawString("no hit",20,30);}
    
             }
    
        public void update(Graphics g)
        {
            paint(g);
        }
    
        public void paint(Graphics g)
        {
            drawStuff();
            g.drawImage (Buffer,0,0, this);
        }
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,270
    Rep Power
    1737
    Originally Posted by william_nagels
    here is my code
    Very nice. Anything else you would like to add to that? One of the guidelines in asking questions, is uh, ask a question...

    And be specific. Something like is my code correct doesn't help. What is that compiling, trying to fix the code on your own, and googling, couldn't solve?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8
    my question is (off course :s) why isn't there a collision detection.
    Believe me i googled enough

IMN logo majestic logo threadwatch logo seochat tools logo