In my code below....i wish to add a yellow bar at the bottom if upon firing a bullet, the bullet reaches the moving bar at the top(which is a trail of alternative yellow and cyan boxes) and touches it at a yellow box.For that what I am planning is to first detect the color of the pixel where the bullet touches the moving bar and then add yellow bar below if the pixel color was yellow............Here is my code: //
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class abyss extends Applet implements Runnable,KeyListener{
int lim=446,l,src,i=-40,n,c,ct=450,cl=225,y,f,bl,bw,fr,mud=0;
Thread v=null;
public void init() {
setBackground(Color.black);
addKeyListener(this);
}
public void start() {
v=new Thread(this);
v.start();
}
public void run() {
try {
int trainDelay = 0;
while (true) {
if(ct<=200)
{repaint();
}
if (y == 1) {
if (f<=41) {
bl = cl + 25;
bw = 10;
f = lim;
}
if (f > 41) {
repaint(bl, f, bw, bw + 1);
if (--f<=41) {
if(l%80==0)
{mud=1;
ct=ct-20;
System.out.println("decreased");
lim=lim-20;
repaint();}
else if(l%80!=0 && (ct+20<=420))
{ct=ct+20;
lim=lim+20;
}
y = 0;
bw = 0;
}
}
}
if (trainDelay <= 0) {
repaint();
i = i + 40;
c = 1;
n = i / 40;
trainDelay = 200;
}
Thread.sleep(5);
trainDelay--;
}
} catch (Exception e) {
}
}
public void paint(Graphics g) {
if(ct>=200){
if(mud==1)
{g.setColor(Color.orange);
g.fill3DRect(0,ct+20,500,450-ct,true);}
g.setColor(Color.darkGray);
g.fill3DRect(0,200,30,300,true);
g.fill3DRect(470,200,30,300,true);
g.fill3DRect(0,470,500,30,true);
g.setColor(Color.blue);
g.fill3DRect(cl,ct,50,20,true);
setBackground(Color.black);
for(int j=n-1;j>=0;j--)
{ l=j*40;
if((c%2)==0)
{g.setColor(Color.cyan);
g.fill3DRect(l,0,50,40,true);}
else
{g.setColor(Color.orange);
g.fill3DRect(l,0,50,40,true);}
c++;
}
}
{g.setColor(Color.yellow);
g.fillOval(bl,f,bw,bw);
if(ct<=200)
{setBackground(Color.red);
g.setColor(Color.yellow);
g.drawString("You win!!",215,210);
}
} }
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_LEFT && cl>=38){
cl=cl-10;}
if(e.getKeyCode()==KeyEvent.VK_RIGHT && cl<=412){
cl=cl+10;}
if(e.getKeyCode()==KeyEvent.VK_UP){
y=1;}
}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public void stop() {
try{wait();}
catch(Exception e) {}
}
public void destroy() {}
}
Please tell me how to detect the color.........can getColor() be used??