
October 14th, 2006, 11:43 AM
|
|
Contributing User
|
|
Join Date: Aug 2006
Location: belgium
Posts: 101
Time spent in forums: 1 Day 27 m 7 sec
Reputation Power: 2
|
|
|
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);
}
}
|