The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Game Development
|
Making a radar
Discuss Making a radar in the Game Development forum on Dev Shed. Making a radar Game Development forum covering non language specific programming - game creation, design, modding, theories and math. A place for developers and gamers of all levels to discuss and debate all things involved in game creation and modding.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 14th, 2006, 11:43 AM
|
|
Contributing User
|
|
Join Date: Aug 2006
Location: belgium
Posts: 116

Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
|
|
|
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);
}
}
|

October 14th, 2006, 11:53 AM
|
|
|
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?
|

October 14th, 2006, 11:57 AM
|
|
Contributing User
|
|
Join Date: Aug 2006
Location: belgium
Posts: 116

Time spent in forums: 1 Day 7 h 2 m 45 sec
Reputation Power: 7
|
|
|
my question is (off course :s) why isn't there a collision detection.
Believe me i googled enough
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|