Game Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesGame Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 14th, 2006, 11:43 AM
william_nagels william_nagels is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Location: belgium
Posts: 116 william_nagels User rank is Private First Class (20 - 50 Reputation Level)william_nagels User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
Send a message via MSN to william_nagels
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);
    }
}

Reply With Quote
  #2  
Old October 14th, 2006, 11:53 AM
Oler1s Oler1s is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2006
Posts: 2,270 Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 15 h 34 m 57 sec
Reputation Power: 1735
Quote:
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?

Reply With Quote
  #3  
Old October 14th, 2006, 11:57 AM
william_nagels william_nagels is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Location: belgium
Posts: 116 william_nagels User rank is Private First Class (20 - 50 Reputation Level)william_nagels User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
Send a message via MSN to william_nagels
my question is (off course :s) why isn't there a collision detection.
Believe me i googled enough

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesGame Development > Making a radar

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap