public void stop()
{
if(duck1!=null)
duck1.stop();
if(t2!=null)
t2.stop();
}
class DUCK1 extends Thread
{
duckShoot app;
int x;
//pass reference to Applet
DUCK1(duckShoot parent)
{
app=parent;
}
public void run()
{
//method loops forever if thread exsists, other processes can run aswell
while(true) {
if(x++>600)
x=0;
app.repaint();
try{Thread.sleep(10);}catch(InterruptedException e){}
}
}
}
class T2 extends Thread
{
duckShoot app;
int x;
//pass reference to Applet
T2(duckShoot parent)
{
app=parent;
}
public void run()
{
//method loops forever if thread exsists, other processes can run aswell
while(true) {
if(x++>600)
x=0;
app.repaint();
try{Thread.sleep(1);}catch(InterruptedException e){}
}
}
}
Class Names Like Duck and Duck1 Should Always Start With A Capital Letter
variable names like Buffer (yours) should always start with a lowercase letter (e.g. buffer) and should be more descriptive of what they actually do (e.g. duckImageBuffer)
ALL CAPITAL LETTERS IS A RESERVED CONVENTION FOR FINAL VARIABLES. DO NOT NAME CLASSES WITH ALL CAPS UNLESS IT IS AN ACRONYM E.G. "public class URL{"
only every make a variable name all caps if if is declared as: " ... final int MY_INT"
-
this will make your code more readable and understandable to other programmers.. it is also what Sun say you should do
--
I dont think your buffering technique is correct.. you should merely setDoubleBuffered(true) on whatever component you are using to display the ducks
05-11-2004, 05:56 AM
cjard
by the way.. sleeping for 1 millisecond isnt going to do much, as your applet will be generating arounf a thousand repaints a second, but java wont bother updating the display as often as that,,
youve sort-of got the right idea about creating a video game, but at the same time, the method youre using is unsuited to java because of the way graphics are handled.. you'd be better off using a java.util.Timer to stimulate an array of Duck sprites at a regular interval. at every interval, the sprites should move a little, and when you fire, the arrow should be made aware of the Duck array so it can query each one to see if it hit one of them (when it gets there)..
writing a game is a big thing to do; be careful not to bite off more than you can chew :)